ATF test step

Anantha27
Mega Guru

In one catalog item, workflow contains timer if one task is closed it takes 20 sec to create another task so I need to create the test that test should wait for 20 seconds and continue to access another task to write in the test step. Any solutions...?

3 ACCEPTED SOLUTIONS

Hemanth M1
Giga Sage
Giga Sage

Hi @Anantha27 ,

 

Create a custom test script and add do nothing loop to wait

 

Refer this : https://www.servicenow.com/community/developer-forum/atf-server-script-to-wait-some-time/m-p/1879854... 

 

Navigate to custom script step.

HemanthM1_0-1727683295651.png

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

Sai Krishna6147
Mega Guru

Here's a comprehensive approach that combines the best aspects of previous responses and addresses potential issues:

1. Identify the Relevant Task:

  • Determine the exact task within the catalog item workflow that you want to wait for. This information can be found in the workflow definition.

2. Create a Test Step:

  • Create a new test step in your ATF test case.

3. Set the Test Step Action:

  • In the "Action" field of the test step, select "Wait for Condition."

4. Define the Condition:

  • In the "Condition" field, use the following expression:

    JavaScript
    new GlideRecord('task').query().addQuery('state', 'closed').addQuery('sys_id', <task_sys_id>).addQuery('sys_updated_on', '<time_before_20_seconds>').query();
     
     
    • Replace <task_sys_id> with the actual sys_id of the task you want to wait for.

    • Replace <time_before_20_seconds> with a calculated time that is 20 seconds before the current time. You can use JavaScript's Date object and appropriate methods to achieve this. For example:

      JavaScript
      var now = new GlideDateTime();
      now.subtractSeconds(20);
      var timeBefore20Seconds = now.getDisplayValue();

5. Configure the Wait Time:

  • In the "Timeout (in seconds)" field, set the value to a suitable timeout value. This is optional but can be helpful to prevent the test from waiting indefinitely if the condition is not met.

6. Add Subsequent Test Steps:

  • After the "Wait for Condition" step, add subsequent test steps that will access the other task and perform the necessary actions.

7. Save and Run the Test Case:

  • Save the test case and run it. The test will wait for 20 seconds before proceeding to the subsequent steps if the specified task is closed.

By following these steps and considering the additional factors, you should be able to create an effective ATF test that accurately simulates the waiting behavior in your catalog item workflow.

View solution in original post

Ramesh_143
Giga Guru

Hi @Anantha27 , 
Here's a server-side script step in ATF that you can use to wait for 20 seconds before proceeding with the next task:
 gs.sleep(20000); // 20000 milliseconds = 20 seconds & it will wait for 20 seconds
This script step leverages the gs.sleep() function to introduce a pause of 20 seconds in the ATF test execution.

Thanks,

Ramesh

View solution in original post

6 REPLIES 6

Hemanth M1
Giga Sage
Giga Sage

Hi @Anantha27 ,

 

Create a custom test script and add do nothing loop to wait

 

Refer this : https://www.servicenow.com/community/developer-forum/atf-server-script-to-wait-some-time/m-p/1879854... 

 

Navigate to custom script step.

HemanthM1_0-1727683295651.png

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Sai Krishna6147
Mega Guru

Here's a comprehensive approach that combines the best aspects of previous responses and addresses potential issues:

1. Identify the Relevant Task:

  • Determine the exact task within the catalog item workflow that you want to wait for. This information can be found in the workflow definition.

2. Create a Test Step:

  • Create a new test step in your ATF test case.

3. Set the Test Step Action:

  • In the "Action" field of the test step, select "Wait for Condition."

4. Define the Condition:

  • In the "Condition" field, use the following expression:

    JavaScript
    new GlideRecord('task').query().addQuery('state', 'closed').addQuery('sys_id', <task_sys_id>).addQuery('sys_updated_on', '<time_before_20_seconds>').query();
     
     
    • Replace <task_sys_id> with the actual sys_id of the task you want to wait for.

    • Replace <time_before_20_seconds> with a calculated time that is 20 seconds before the current time. You can use JavaScript's Date object and appropriate methods to achieve this. For example:

      JavaScript
      var now = new GlideDateTime();
      now.subtractSeconds(20);
      var timeBefore20Seconds = now.getDisplayValue();

5. Configure the Wait Time:

  • In the "Timeout (in seconds)" field, set the value to a suitable timeout value. This is optional but can be helpful to prevent the test from waiting indefinitely if the condition is not met.

6. Add Subsequent Test Steps:

  • After the "Wait for Condition" step, add subsequent test steps that will access the other task and perform the necessary actions.

7. Save and Run the Test Case:

  • Save the test case and run it. The test will wait for 20 seconds before proceeding to the subsequent steps if the specified task is closed.

By following these steps and considering the additional factors, you should be able to create an effective ATF test that accurately simulates the waiting behavior in your catalog item workflow.

Ramesh_143
Giga Guru

Hi @Anantha27 , 
Here's a server-side script step in ATF that you can use to wait for 20 seconds before proceeding with the next task:
 gs.sleep(20000); // 20000 milliseconds = 20 seconds & it will wait for 20 seconds
This script step leverages the gs.sleep() function to introduce a pause of 20 seconds in the ATF test execution.

Thanks,

Ramesh

VishaalRanS
Tera Guru

Hi @Anantha27 

 

you can use the built-in functionality of ServiceNow's automated testing framework.

Steps to Create a Test with a Timer in ServiceNow:

  1. Create a Test Case:
    • Navigate to Test Management > Test Cases.
    • Click on New to create a new test case.
  2. Add Test Steps:
    • Add the necessary steps to your test case. You will add a step for waiting.
  3. Use the wait Command:
    • In the test step where you want to introduce a delay, you can use the wait command. Implement this:
      • Select Add Step and Choose the Script type
      • Add Script: new GlideDuration(20000).pause();    // Wait for 20 seconds (20000 milliseconds)
  1. Access the Task:
    • After the wait command, add another step to access the next task.
    • This can be a step to retrieve the task record or perform actions on it.
  2. Save and Run the Test:
    • Save the test case and run it. The test should wait for 20 seconds after the first task is closed before proceeding to interact with the next task.

Notes:

  • Make sure your environment allows for pauses and that you're not affecting other users or processes with long waits.
  • Test scripts may need appropriate permissions to access and manipulate tasks.

 

Thanks, and Regards

Vishaal

Please mark this response as correct or helpful if it assisted you with your question.