- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 03-18-2019 04:09 AM
ServiceNow Automated Test Framework for Testing REST based Integration
About ATF
ATF helps automating the test cases at system upgrade for testing the checklist, implementation testing for an application or for testing a real-time integration using REST or server-side scripts.
REST API Explorer
ServiceNow provides an easy way to communicate via HTTP methods with built-in tables – base, core or custom tables. We provide base URL, system parameters, limiting the returned record count, deciding on the format either for JSON or XML etc. We will cover this as a first step in our ATF Test case.
You can explore on this Starting with REST APIs - ServiceNow Integration Level 1
Business Case
Integrating with 3rd party tool (say Workday): Passing values form Workday to ServiceNow to verify using GET operation in CMDB tables and return ‘200 Success - Record Found’ for a matching value or ‘404 Failed - Record Not found’ for incorrect/empty input.
Proposed Solution
Use ServiceNow ATF solution to test if data is found in ServiceNow or not using Assertion of Status Code and Response data. The following steps provide clear understanding!
Steps
1. Create a ServiceNow Record (which says record is already present in Configuration Database table) - populate with below details: We use Apple as manufacturer with sys_id = sys_idOfApple (for convenience)
2. The Workday team has provides/sends a JSON file consisting Manufacturer and Asset tag as an input to ServiceNow REST APIs
Let’s say the file consists of this data: {"manufacturer":"sys_idOfApple","asset_tag":" WXYZ9876"}
3. Success Case
Creating a Test and it's steps in Automated Test Framework Application and add assert steps to validate. Remember to activate the plugin if it's not active by default, verify in Plugins Module.
i. Open Automated Test Framework > Test > Create New > Fill in details > Submit
ii. Create Test Steps within Test > Create New Step > Choose from Categories and follow the same order as given (full list found in Madrid version):
ii.a. Select Send REST Request - Inbound - REST API Explorer > Next
ii.b. Select the table as Application (cmdb_ci_appl) and fill out the details for input (sysparm_query – manufacturer=sys_idOfApple^asset_tag=WXYZ9876) and output (sysparm_fields – choose from select box, here it is just ‘name’). The default HTTP Method will be GET, which is of our interest here and the rest all fields can be the same or modify at the best of the knowledge. Click Send and verify the results in JSON format.
ii.c. Next click on top right corner – Create Automated Test Step > Save > Go to Basic Authentication > Search Box > Create a new profile for authentication (here I have used my admin credentials and provided a name REST ATF Authentication) > Update
ii.d. Create 2nd Step – Choose Assert Status Code from REST category as we did in (1) and give the Status Code as 200. We are just verifying the output Status code here so as the logs show up expected value vs. actual value after the execution.
ii.e. Create 3rd Step - Assert Response JSON Payload Is Valid > Just Submit
ii.f. The 4th Step would be - Assert Response Payload and add the below text in the Response body – {"result":[{"manufacturer":"sysidOfApple","asset_tag":" WXYZ9876"}]}
The final Test Steps looks like this:
4. Failure Case
Creating next Test and its Steps in ATF Application: Follow the same steps as we did in section ‘c’ but with a little variation as shown below:
Choose the input to be wrong, say - sysparm_query: manufacturer=wrong-sys_idOfApple^asset_tag=WXYZ9876
Asset status code must be set to ‘404’, Next step is as same as first case, Assert Response Payload: {“result”:[]} //meaning empty results as the record not found
Results
ATF suite is used at the end if required which is given with same input to the Tests present within it (say Success Test & Failure Test). This way we can check either a success or failure case within a suite. Though the suite result may say 'failed' (as it will be success if and only if all the tests inside it are in success case) but in our above project, as configured one of the test case will be true, not both, which decides the success of failure. This is just a crude way of testing REST APIs in ATF, if someone gets an idea to standardize this please feel free to comment. Let's learn together!
Regards, Akash
- 7,244 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Akash.
First of all thank you for excellent post!
I have a Scripted REST API that creates a custom record and returns the Number and SysID of it in the JSON response payload.
Is there a good way to create a test step after all the Assert steps to pick up individual items from the JSON response and do record lookups to ensure that the ticket was created correctly?
A simplified JSON response from the Scripted REST API looks like this:
{
"result": {
"status": "ok",
"record_created": {
"sys_id": "455f7999db25f7001d289475db961992",
"number": "CUST0001445"
}
}
}
I have already steps that assert like in your example that the status code is 200, JSON payload is valid and that /result/status is "ok".
Next I would like to have a step that picks up the /result/record_created/number item (or sys_id or both) and does a lookup of that record to validate some fields in the newly created record.
Do you think this is possible somehow, perhaps via a scripted step?
Best regards,
Ingimar
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Absolutely Ingimar,
You can user server side scripts for this, first you may do with any background script or business rule for testing purpose, after which try to save the responses that you have asserted in a variable/list. If in a test step, speaking with above test steps is possible, then a solution for your requirement is possible as well. I will try to help you, please post your sample code here.
Regards, Akash
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Akash,
Thanks for the wonderful explanation. Just wanted to know if it is possible to test outbound transactions via ATF? for eg, if I have to create an Incident ticket to 3rd party tool from Servicenow, how can I test that?
Thanks for your answer!
Regards,
Mansi
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Mansi14 do you have some informations regarding this? i am also interested in this topic. Thanks