- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 12:52 AM
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...?
Solved! Go to Solution.
- 2,513 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 01:02 AM
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.
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 01:08 AM - edited ‎09-30-2024 02:28 AM
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:
JavaScriptnew 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:
JavaScriptvar 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 03:54 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 01:02 AM
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.
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 01:08 AM - edited ‎09-30-2024 02:28 AM
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:
JavaScriptnew 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:
JavaScriptvar 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 03:54 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 10:16 PM - edited ‎09-30-2024 10:18 PM
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:
- Create a Test Case:
- Navigate to Test Management > Test Cases.
- Click on New to create a new test case.
- Add Test Steps:
- Add the necessary steps to your test case. You will add a step for waiting.
- 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)
- 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.
- 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.