Ask a Question

How to put wait time or introduce sleep during execution in Testcomplete Script mode

SOLVED
prabhjot88singh
Contributor

How to put wait time or introduce sleep during execution in Testcomplete Script mode

Hi All,

 

Could someone please let me know the command to introduce a delay of 15 seconds between 2 test steps in Testcomplete using Script mode.

 

Like in selenium, we have Thread.sleep(1000), which pauses execution for 10 milliseconds and then runs next step.

 

Similarly , I am looking for a wait command in Testcomplete using JScript Mode in Page with specified delay of 10-20 seconds before jumping onto next command.

 

Please revert.

 

Best,

Prabhjot

1 ACCEPTED SOLUTION

Accepted Solutions
TanyaYatskovska
Community Manager

Re: How to put wait time or introduce sleep during execution in Testcomplete Script mode

Hi,

 

There are many ways to wait for an object during the test execution. WaitNNN methods are the best here. All recommended approaches are listed in the following article - please review it: https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-a...

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

6 REPLIES 6
tristaanogre
Community Hero

Re: How to put wait time or introduce sleep during execution in Testcomplete Script mode

aqUtils.Delay (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqutils/delay.html)

 

is what you're looking for, I believe.

However...  it depends upon why you're waiting as to whether or not I'd suggest using it.  As a rule of thumb, I don't like hardcoded "sleep" commands because, depending upon environment, server load, etc, execution times and wait times may vary.  

If you can tell us WHY you need to introduce these sleeps, perhaps we can suggest a better way that will help with execution and robustness of your automation.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
prabhjot88singh
Contributor

Re: How to put wait time or introduce sleep during execution in Testcomplete Script mode

My application has 2 buttons:

 

1. Validate

2. Post

 

Step 1 : .Initially user clicks on Validate button, and it takes around 2-5 seconds for this operation to complete.

This is why I need to put some Implicit wait after clicking on Validate button , similar to selenium.

 

2. Later once this validation is completed,  my Post button is enabled immediately.

 

Note : Page is not refreshed anywhere in this entire process, It is just like after first button is validated, second button gets enabled.

 

Please share the implicit wait commands, something like Thread.sleep(time) in Testcomplete script.

LinoTadros
Community Hero

Re: How to put wait time or introduce sleep during execution in Testcomplete Script mode

When you validate by clicking the first button, does the UI show at least a label somewhere that says "...validating" or anything at all on the UI so that it doe snot leave you hanging for 2 to 5 seconds?

If the answer is "No" then you have a bug report to file against R&D, as it is not acceptable nowadays to hang the system for 2 to 5 seconds without telling the user UI wise that you in the process of validating.

 

If there is a label somewhere on the UI stating that the validating is in progress then your the WaitProperty() command in JScript on the second button object to wait for the label text to no be available anymore to continue with the clicking of the second button

This way you don't have to sleep or delay for a number of seconds but wait for an indication from the label to disapear to move on with life.

 

Hope that helps

-Lino

tristaanogre
Community Hero

Re: How to put wait time or introduce sleep during execution in Testcomplete Script mode

In addition to what @LinoTadros suggests, if the Post button isn't in existance or such, you can also use WaitChild or WaitAliasChild as methods to actually wait for the child object to Exist before proceeding.   These "Wait" methods (documented https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-a... and https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-property-value.html and https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-state-changes.html) are the preferred ways to a hard sleep.  Only if none of these works, would I put in a hard sleep.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Krishna_Kumar
Contributor

Re: How to put wait time or introduce sleep during execution in Testcomplete Script mode

Hi @prabhjot88singh ,

 

you will be able to achieve that by using dynamic wait for the object.

the below is the code snippet which you can refer.

 

function waitForObject(propName, propValue, maxTime)
{
  var object;
  var counter=0;
  if(maxTime== undefined)
  maxTime= 20000;
  do
  {
    aqUtils.Delay(100);
    counter+= 100;
    if(counter>maxTime)
    {
      Log.Warning("Time Exceeded");
      return;
    }
    object= sys.browser("Chrome").page("*").Find(propName, propValue, 30, true);
  }while (! object.Exists)
  object.Click();
}

the above function takes two mandateory parameter ("property", "value") of the object for which you are waiting for. And the third parameter is  "maxTime" which is not mandatory if you dont give the third parameter, it will wait untill the some time (20000 milisec).

it enters into a loop which will try finding the object untill object is identified or untill the maxTime is reached

please try this and let me know

 

Kind Regards,

Sathish Kumar K

TanyaYatskovska
Community Manager

Re: How to put wait time or introduce sleep during execution in Testcomplete Script mode

Hi,

 

There are many ways to wait for an object during the test execution. WaitNNN methods are the best here. All recommended approaches are listed in the following article - please review it: https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-a...

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

cancel
Showing results for 
Search instead for 
Did you mean: