ATF: How to account for elapsed time in testing workflows

jmiskey
Kilo Sage

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

1 ACCEPTED SOLUTION

TrenaFritsche
Tera Expert

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));

 

 

View solution in original post

23 REPLIES 23

Hi,

Yes even i wanted to suggest you that. Please let us know if there is some other way to it.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

I opened a HI Ticket, and they confirmed that there currently is no way to bypass/skip/ignore Timers in ATF Testing, but that would be a good enhancement request, and suggested that I submit it to the Idea Portal.  I have, and it is named "Ability to Bypass/Skip Timers in ATF Testing of Workflows".   Please vote for it!

Great then, 

Could you please mark this thread answered so that it will go away from unanswered queue and if my answer helped you in any way then please hit the right button.

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

TrenaFritsche
Tera Expert

Hello all,

I wanted to let you know that I have been able to successfully move a timer workflow activity date to 2 minutes from the current date time to allow the schedule to run just as though the date time arrived within my ATF test. 

This allows the workflow that is waiting for a timer to arrive before moving on to continue without waiting for the actual date. 

The secret here is to get to the schedule for that activity and update the Next Action Date to the current datetime plus 2 minutes, then in your step before you move on to verify the next thing that would happen in your workflow, you would need to wait for 2 minutes for the datetime that you updated the schedule to arrive, then you can go on to the next step in your test.

I put all of the logic in a server step configuration.

Trena,

I am intrigued, but not sure I completely follow/understand what you are suggesting.  You keep referencing a "schedule".  What do you mean by that?

I tend to deal with two kinds of timers:

1. Ones that say to wait for a specified amount of time (i.e. Wait 15 minutes, wait 30 days, etc.)

2. Ones that say to wait a certain amount of time relative to an entered date (i.e. Wait until 10 days before Expiration Date)

So, is it possible to use your suggestion in these kind of scenarios?  What exactly would that look like?

Thanks