- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2020 11:44 AM
I am building some ATF Tests to test out various workflows that we have. Some of them have Timers in them (i.e. wait 5 minutes, wait 10 days before expiration). How can I write ATF tests for those workflows which have timers in them that cause "a pause" in time, waiting for time to pass before proceeding to the next step? Is there some command we can add to the ATF testing to tell it that a certain amount of time has passed? Or will it just ignore timers and go to the next step in the workflow?
Thanks
Solved! Go to Solution.
- Labels:
-
Automated Test Framework

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 02:24 PM
Basically, I haven't built out the Description script, I was more interested in having the execution do what I was looking to do.
Here is a screen capture of the part of the test that will move the change request forward...update the timer...
The script that I wrote inside of the Test "Update Change Request Scheduled Job..." to execute the timer activity on the workflow is the following, and it only needs the sys_id of the change request form as the input to query its way thru tables to get to the correct sys_trigger table. There are no outputs. The step just updates the timer for 2 minutes past the time it gets when the step runs and then the step sleeps for 2 minutes to allow the trigger job to actually run.
(function executeStep(inputs, outputs, stepResult, timeout) {
var cntxID = '';
var wfVerID = '';
var actvID = '';
var execID = '';
var nextAction = 'No';
//----Get Current Date Time
var gdt = new GlideDateTime();
var schdt = new GlideDateTime();
gdt.addSeconds(-10680); //Convert Time to Central + 2 minutes
//---------------------------------
var wfcontext = new GlideRecord('wf_context');
wfcontext.addQuery('id', inputs.u_request);
wfcontext.query();
if (wfcontext.next()) {
cntxID = wfcontext.sys_id;
wfVerID = wfcontext.workflow_version;
}
var wfactivity = new GlideRecord('wf_activity');
wfactivity.addQuery('name', 'Wait for CR Planned Start Date');
wfactivity.addQuery('workflow_version.sys_id', wfVerID);
wfactivity.query();
if (wfactivity.next()) {
actvID = wfactivity.sys_id;
}
if (cntxID != '') {
var wfexec = new GlideRecord('wf_executing');
wfexec.addQuery('context.sys_id', cntxID);
wfexec.addQuery('activity', actvID);
wfexec.query();
if (wfexec.next()) {
execID = wfexec.sys_id;
}
}
if (execID != '') {
var sched = new GlideRecord('sys_trigger');
sched.addQuery('document_key', execID);
sched.query();
if (sched.next()) {
schdt = sched.next_action;
sched.next_action = gdt;
nextAction = 'Yes';
sched.update();
}
}
gs.sleep('120000'); //2 Minutes
if (nextAction == 'Yes') {
stepResult.setSuccess();
stepResult.setOutputMessage = "Original Planned Start of " + schdt + " changed to " + gdt;
} else {
stepResult.setFailed();
}
}(inputs, outputs, stepResult, timeout));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 12:43 PM
I believe that tables that extend from Task (Incident, Problem, Change, Request etc...) can use Task as the referenced Table. Maybe sc_req_item is able to be used also, not sure as I haven't tried, but that does limit the usage of that step only to Requested Items if it does work.
This might be your issue, as I am not sure what your WF's Activities Name would be... This could also be an input variable too I would think. "Wait for CR Planned Start Date" is the Timer Activity Name for my test and I'm sure isn't the same for the Activity your are looking for.
In regards to the datetime addition of seconds...This is a tricky part and I always need to log values via gs.info to see what the values are. If I remember right 10800 is 3 hours (3600 seconds is 1 hour) and based on the date that it gave without any manipulation, the date I needed was 3 hours earlier but I needed to subtact 2 minutes which is 120 seconds...So basically I logged the datetime that "var gdt = new GlideDateTime();" was so I could determine what the raw date was getting set as.
10800-120 =10680. This calc may be off, but it worked for me, so I think I am close.
Let me know if this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 01:20 PM
It worked!!!
The issue wasn't the WF Actvity name, I had already updated that. It was the line I asked about in my previous post:
wfcontext.addQuery('id', inputs.u_request);
I needed to change "u_request" to the name of my input variable. And I did change the time to this:
gdt.addSeconds(-7080);
I figured that in Eastern time, I am one hour ahead of you, so I added 3600 to the value you were using.
I cannot thank you enough! I am so excited to get this working! We have a lot of workflows with Timers what we have not been able to test thoroughly and completely. Now we can!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 10:17 AM
Trena,
I hope I can bug you one more time for a follow-up question on the code.
The following line:
stepResult.setOutputMessage = "Original Planned Start of " + schdt + " changed to " + gdt;
Where do I see this output message? I looked in the Test Results, but cannot seem to find it.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 07:44 AM
Yet another version of the Sleep function:
The DevTools app contains a truckload of reusable scripts and
features to support your app development.
Fork at will!