Forum Discussion

r_ahmakov's avatar
r_ahmakov
Occasional Contributor
8 years ago
Solved

Variable delay time

Hi,

 

can I set a varible delay operation, so that I can performance slower and sometimes faster tests?

  • bo_roop's avatar
    bo_roop
    8 years ago

    We use the WaitAliasChild in the same way that you mentioned WaitChild.

     

    var gmailPanel = Aliases["browser"]["pagegmail"]["gmailpanel"]

    gmailPanel["WaitAliasChild"]( "linkPreviewAttachment", 30000)

    In the example above, gmailPanel is the parent object (a panel inside of gmail in your web browser) and we are waiting for the Preview Attachment link (both are present in the NameMapping file).

     

    I like using WaitAliasChild because it's easier to debug (in my opinion). When the logic fails to find the control in the 30 seconds, I can go into the NameMapping editor and find the alias ["browser"]["pagegmail"]["gmailpanel"]["linkPreviewAttachment"] and right click to highlight the object.

     

    If it can't be found, I can then point at the object in my application and when the result is returned I can see what properties are different from the NameMapping alias and make the appropriate changes/updates to the Alias. If they are all the same, that means there is more than one control that matches the saved properties and TestComplete can't differentiate between them.

     

    Either way, this gives me a better starting point for debugging.

     

    Ultimately, when you say that WaitChild doesn't work, it means that your child control isn't found by TestComplete... you need to go figure out why.

     

    Good luck!

13 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    Hi,

     

    What exactly do you want to delay?

    If you are about delay between user actions, you can change this value in your project's settings:

     

     

    If you need to wait for some specific elements of your application, better to create a kind of event-wrapper with Wait method rather than hard-coded delays.

     

    Anyway you can create a variable and use it within aqUtils.Delay() method.

  • r_ahmakov's avatar
    r_ahmakov
    Occasional Contributor

    Hi ,

     

    I have various delays between events, for example database updates or file-exporting... For some faster and smaller tests I'd like to reduce these delays in the entire test...or when the test is running on faster laptop.

     

    Something like that will be perfect :)

     

    TestDelay = Delay()*VariableParameter

     

    What is a "event-wrapper with Wait method"...sorry I am very new at TestComplete :).

     

    Thanks

     

    • baxatob's avatar
      baxatob
      Community Hero

      Your application would have some properties indicated that some event was successfully fired (e.g. data base was updated or file was uploaded). The common approach looks like:

       

      application.UpdateDatabase()
      
      flag = application.WaitProperty(PropertyName, PropertyValue, WaitTime) 
      
      if flag:
          doSomething
      else:
          doSomethingElse

       

      Wait Property() method returns True or False. 

      Also you can use WaitChild() method, which returns the object of your application or the Null value.

       

      Or you can hard-code your delay using aqUtils.Delay(timeout), where timeout is your variable (in milliseconds).

    • bo_roop's avatar
      bo_roop
      Contributor

      r_ahmakov wrote:

      Hi ,

       

      For some faster and smaller tests I'd like to reduce these delays in the entire test...or when the test is running on faster laptop.

       

      Something like that will be perfect :)

       

      TestDelay = Delay()*VariableParameter

       

       


      You can easily create a variable at the Project or ProjectSuite level and then reference that variable within your delay statements... which will get you through this first hurdle, but there will be times that this fails unless you set the timeout delays high enough to pass on the slowest machines.

       

      Eventually you'll want to perform (or rather your bosses will want you to perform) some real synchronization.

       

      Here's an example of logic I use when waiting for a file to download.

       

      1. Click the download button (or link or whatever)
      2. Start a loop (that does the next two steps over and over again)
      3. Delay 5000ms (5 seconds)
      4. Check to see if the file is present in the specific dwonload directory
      5. If not present, increment a counter and wait another 5 seconds
        • If the file is present, drop out of the loop and continue on with the test
      6. After looping/waiting for about 60 seconds (or however long you think is appropriate), drop out of the loop and log an error stating that the file was not found. (then you can go back and manually verify why the file hasn't completely downloaded after the 60 seconds)

      This logic stuff is a little more difficult, but A LOT more reliable. My tests can run at any hour of the day or night and the looping logic addresses any network latency or internet slow-downs... and doesn't cause me to wait for 60 seconds with each download. The longest you're waiting is an extra 5 seconds if the file is is present immediately after checking for its existence (decreasing the 5000ms delay also resolves that issue if you're concerned).

       

       

      Good luck!

      • mgroen2's avatar
        mgroen2
        Super Contributor

        r_ahmakov if you want, you could create a feature request, to update the projects; playback screen to include a min/max delay time