- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 05:09 AM
I’m trying to test my Workflow scripts using ATF so I have added the Run Server Side Script Test Step using the following code:
(function(outputs, steps, stepResult, assertEqual) {
var staffId = "";
var staffEmail = "";
var staffDetails = new GlideRecord('sys_user');
if(staffId != ''){
staffDetails.addQuery('employee_number',staffId);
}else{
staffDetails.addQuery('first_name', "Roberto");
staffDetails.addQuery('last_name', "Firmino");
staffDetails.addQuery('manager.name', "Jurgen Klopp");
}
staffDetails.query();
if(staffDetails.next()) {
if(staffDetails.email != ''){
//workflow.scratchpad.email_sml_vs = staffDetails.email;
var assertEmailExists = {
name: "assert Email has been created",
shouldbe: "Roberto.Firmino@hse.gov.uk",
value: staffDetails.email
};
assertEqual(assertEmailExists);
}
}
stepResult.setOutputMessage("sys_user query failed");
return false;
})(outputs, steps, stepResult, assertEqual);
// uncomment the next line to execute this script as a jasmine test
jasmine.getEnv().execute();
But the test errors instead of fails with the following output:
sys_user query failed
Testing incomplete (check that all asynchronous functions made their callbacks)
Full logging from step execution:
10:47:49.464: Loading script: jasmine_lib/jasmine31.js
10:47:49.520: x_scoped_app:
----- Tests Complete -----
Test results :: (0/0) :: incomplete
I’ve not used the Jasmine Framework before, so I’m not sure if my code is wrong or if my Test Step config is wrong, any advice is appreciated. Any recommendations for good documentation on using Jasmine Tests in Service Now would also be good.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 06:26 AM
Hi Anderw
You have uncommented the last line to indicate that the code will be Jasmine but you are not writing any test in Jasmine format. Please comment the last line jasmine.getEnv().execute() and the test should start working.
--
Best Regards
Ankush
P.S. Please mark helpful/correct as appropriate to help the fellow community member in identifying the relevant answers.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 06:26 AM
Hi Anderw
You have uncommented the last line to indicate that the code will be Jasmine but you are not writing any test in Jasmine format. Please comment the last line jasmine.getEnv().execute() and the test should start working.
--
Best Regards
Ankush
P.S. Please mark helpful/correct as appropriate to help the fellow community member in identifying the relevant answers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 07:06 AM
Hello Ankush,
Thank you for replying, removing the execute line did allow the test to finish. Now the output is:
sys_user query failed
Full logging from step execution:
13:59:51.698: Loading script: jasmine_lib/jasmine31.js
Which indicates that the test has ran. Do you have any advice on how to use assertEqual? Or could you point me at some documentation? I'm not sure if the script is supposed to terminate after the evaluation of "is equal" or if the assertEqual has a return value that I should then be using as an output message?
I will mark your answer as Correct because it did answer my original question, but if you can give further guidance that would be appreciated.
Thanks for your help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 08:11 AM
Hi Andrew
You can find some examples here. In your quick example, you can use "return" after assertEqual. Otherwise as per the current code:
- assertEqual will compare the values mapped to 'shouldBe' and 'value' and report the message as 'name'.
- Overwrite the final message with the one passed in 'setOutputMessage'
- The final 'return false' will always return false and make the script result as fail.
--
Best regards
Ankush