Automated Test Framework- Service Catalog Attempt

rolandorng
Kilo Contributor

I began an attempt to create a catalog item from start to finish using the automated test framework. I wanted to provide my pain points and fixes in case any other user decides to delve into this and improves upon my findings.

I used a catalog item that uses a REST POST message to an external source (Sailpoint) to test, I wanted to see if this integration catalog item would work to test.

I started by creating an ATF for a catalog item submittal this was straightforward I created the following steps:

1. Impersonate

2. Open A Catalog Item

3. Set Variable Values

4. Variable State Validation

5. Order Catalog Item

I found it useful to go through the service catalog as the user sees it and provide the necessary pieces as my catalog was set up. I didn't really run into major issues.

I then thought, ok let's get the requested item and simulate the steps for this. I found this was not possible from the same test since there was no way for me to tie the submitted request. I did some digging and found documentation on how to test a Service Catalog Request.

Using the following documentation:

https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/administer/auto-test-framework/t...

So it turns out you can test your catalog past submittal but you have to create an actual RITM through normal means and use the values you submitted as a starting point. As explained in the documentation the flow of the test is what you are creating/testing. The flow of the original request item takes is not what you are testing but rather our test steps.

I will not reiterate the documentation but I will point out a few things I ran into on my custom catalog item.

1. When you have multiple approvals (we have 2) I found that once I update a record with a status of approved the next approval was not being triggered. After multiple trial and error steps I found that the issue was with the Enforce Security checkbox on the "Record Update"   test step. By unchecking this it properly updated the record and moved the workflow forward.

2. As a result of item 1 above I added record validation for that approval to ensure the state changed properly before and both with impersonation users or admin role it encountered the same issue when checked.

3. I only found this an issue with updates so to be on the safe side I uncheck that for any update. This worked in catalog task updates and task related tables.

The next hurdle was figuring out the REST piece of the workflow. Because no logging data is really preserved when generating these tests I wasn't able to confirm that the rest was being initiated but I did notice the ECC queue was receiving a response.

I confirmed from the receiving side (sailpoint) that an actual rest request does get instantiated and sent. Since our workflow currently does not track the item details until after the REST functionality is complete and creates a task I needed a way to wait for completion of the rest message so I did the following:

I created a "Run Server Side Script" that waits 90 seconds adding the following code:

(function(outputs, steps, stepResult, assertEqual) {

                  gs.sleep(90000);

var assertion = {

    name: "Waited",

                    shouldbe: "true",

                    value: "true"

};

assertEqual(assertion);

stepResult.setOutputMessage = "Waited 90 seconds";

return true;

})(outputs, steps, stepResult, assertEqual);

Assuming no issues with the rest payload and successful it allowed me to step through that workflow step and follow with task creation/completion.

Some improvements I plan to make is creating a stage specifically for the REST piece so I can properly wait for that completion. Since we have fulfillment blanketing the entire process it wasn't readily available to identify. This can be done in the "Run Server Side Script". Another possible advancement is providing a way to identify the ecc queue data with the workflow/request data to properly identify it's result.

1 REPLY 1

Sachin Pratap 2
Kilo Expert

Thanks a lot for this post, was looking for a way to test workflows from ATF.