Forum Discussion

dhundley's avatar
dhundley
Regular Contributor
10 months ago
Solved

Wait timeout and waitproperty not working as expected

I need some help figuring out what I’m doing wrong with setting the timeout values in testcomplete. First, the only reason I’m creating the type of function below is that the WaitProperty does not do what it’s supposed to.

 

 

 

Anytime I have ever used WaitProperty, it waits the ENTIRE time value that is specified in the WaitTime parameter. So if I tell it to wait 30 seconds for an onscreen object’s visible property to be true

SomeObj.WaitProperty(“Visible”, true, 30)

And it is visible on the screen in just 5 seconds, it’s still going to wait the full thirty seconds before allowing the execution to continue. If smartbear would just fix this then that would really simplify my life. I don’t see why this should be such a problem to resolve. I can put a two minute wait time in the WaitWinFormObject method and if the form that has been specified in the method exists in 5 seconds in doesn’t wait the full two minutes.

 

So, back to the issue I’m having with my home grown property wait function. Here is the essential part of what it does. I pass in two arguments the object and an integer value of how long I want it to wait for the exists property to be true before it gives up.

 

function CheckForExists(objElement, intSecondsToDelay)

{

  let intTimeOut = Options.Run.Timeout;

  Log.Message("Check for exists " + Options.Run.Timeout);

  Options.Run.Timeout = 1000;

  Project.Variables.blnWindowFound = false;

  let intSecondsWaited = 0;

  Log.Message("starting do loop");

  do

  {

    intSecondsWaited ++;

    Log.Message(Options.Run.Timeout);

    if (objElement.Exists)

    {

      Log.Message("object exists");     

      Project.Variables.blnWindowFound = true;

      break;

    }

    else

    {

Log.Message("object does not exist");

    }

    Log.Message(intSecondsToDelay);

    Log.Message(intSecondsWaited);

  }

  while (intSecondsWaited <= intSecondsToDelay);

 

 

Here’s the line in my keyword script that calls this function. I am passing in the object name and an integer 15 for the number of seconds to wait.

 

As you can see, in addition to setting the Options.Run.Timeout value inside the function to 1000ms, I’m even putting 1000ms in the Autowait timeout value of the function call in the keyword test because I want each iteration of the Do Loop inside the function to only take one second as it compares it to the value of 15. Despite all that, for some reason, when it’s checking the Exists property of the object, it is taking more than 30 seconds for each iteration.

 

 

 

Does anyone see anything that I’ve messed up here or can someone tell me why the testcomplete WaitProperty method doesn’t work like it’s supposed to?

 

Thanks!

  • Hi,

     

    Anytime I have ever used WaitProperty, it waits the ENTIRE time value that is specified in the WaitTime parameter.

     

    Can you provide a real code snippet that does not work as expected?

     

    There are questions for your CheckForExists() function but I would like to see the non-working code first.

     

9 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    The WaitTime is in milliseconds. If you want 30 seconds, then the last parameter should be 30000,

     

    SomeObj.WaitProperty(“Visible”, true, 30000);

     

     

    Play around with the following code, against the website.

     

    function Test1()
    {
        var page = NameMapping.Sys.Browser("chrome").Page("https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_style_visibility").Panel("container").Panel("iframecontainer").Panel("iframe").Panel("iframewrapper").Frame("iframeResult");
        var item = page.TextNode("myP");
        item.WaitProperty("Visible", false, 30000);
    }

     

     

    The function you have written, is based on the number of iterations, there's no delay of waiting. Which is similar to this,

    function TestIt()
    {
        var intSecondsWaited = 0;
        var intSecondsToDelay = 30;
        
        do
        {
            intSecondsWaited++;
            Log.Message(intSecondsWaited);
        }
        while (intSecondsWaited <= intSecondsToDelay);
    }
    • dhundley's avatar
      dhundley
      Regular Contributor

      my mistake about putting 30 instead of 30000. I was throwing that into the post just as an additional question to my main question. even if i put in the 30000 value, if the object becomes visible in 5 seconds it is still going to wait the full 30 seconds before execution continues. that's what i'm getting at. why does it wait the full amount even though the property value has been satisfied. 

       

      as for the other matter, i believe you are wrong to say it is simply based on the number of iterations because of the if statement in the example i provided. when it processes the If (objElement.Exists), it is supposed to wait the amount of time specified by the auto wait time out value (which I've clearly set to be 1 second (1000 milliseconds). yet it is waiting 30 seconds for each iteration. if what you were saying is true it would finish up my do loop in a flash (less than 1 second probably for all 15 iterations). I want to know why its taking so long.

       

      if i'm wrong please point out where I've gotten off. Thanks!

  • eykxas's avatar
    eykxas
    Frequent Contributor

    I am facing the same issue. All Wait method are completely useless for me. 

     

    As a workaround I use codes like this : 

     

    here, I want to see an object to disappear. 

    function waitSpinner(){
      page = getPage("webPage");
      var elementHTML = page.FindElement("//mat-progress-spinner[@role='progressbar']");
      let stopTime = GetTickCount() + 4000;
      while(elementHTML.VisibleOnScreen == true && GetTickCount() < stopTime){
        Delay(100);
        optimisation.refresh_object(page);
      }
    }
  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I'm going to try my best to explain the following scenario - I'm using your code to search for SubmitX button on website https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select which does not exist.

     

    I'm going to pass in the following values into the method, CheckForExists(page, 3),

    function main()
    {
        // URL https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select
        var page = Sys.Browser().Page("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select").FindElement("#iframeResult");
        CheckForExists(page, 3);
    }
    
    function CheckForExists(objElement, intSecondsToDelay)
    {
        let intTimeOut = Options.Run.Timeout;
        Log.Message("Check for exists " + Options.Run.Timeout);
        Options.Run.Timeout = 1000;
        let intSecondsWaited = 0;
        Log.Message("starting do loop");
        do
        {
            intSecondsWaited ++;
            Log.Message(Options.Run.Timeout);
            // Find SubmitX button, which does not exist
            if (objElement.FindElement("//input[@value='SubmitX']").Exists)
            {
                Log.Message("object exists");     
                break;
            }
            else
            {
                Log.Message("object does not exist");
            }
            Log.Message(intSecondsToDelay);
            Log.Message(intSecondsWaited);
        }
        while (intSecondsWaited < intSecondsToDelay);
    }

    and Options.Run.Timeout = 1000, which sets the following project value,

    When I run the code, it's waited 1000ms for the object to become available, as shown in Error. Since we set parameter intSecondsToDelay = 3, we can say it waited for 3 seconds (I'll get back to this point)

     

    Now, if I pass CheckForExists(page, 2) and Options.Run.Timeout = 30000. When I run the code, it's waited 30000ms for the object to become available, as shown in Error lines. Since we set parameter intSecondsToDelay = 2, we can say it waited for 2 seconds. However, we can clearly see that it hasn't waited for 2 seconds, it's done 2 iterations of the loop, waiting 30 seconds each. Therefore, the total time it took was about 1 minute to complete.

     

    In your example, it seems like Options.Run.Timeout is not settings the value correctly; performing 15 iterations and waiting 30 seconds each time.

  • eykxas's avatar
    eykxas
    Frequent Contributor

    I think this behavior is normal. FindElement (and other Find method) already use the timeout option of the project when performing the search. 

    When I want to override this timeout and doing the wait in my own way, I always surrounding my code with :

    Options.Run.Timeout = 50;  //set to 50ms
    //my_code_that_contains_any_Find_Method
    Option.Run.Timeout = 4000; //revert to initial value, 4s.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Anytime I have ever used WaitProperty, it waits the ENTIRE time value that is specified in the WaitTime parameter.

     

    Can you provide a real code snippet that does not work as expected?

     

    There are questions for your CheckForExists() function but I would like to see the non-working code first.

     

    • dhundley's avatar
      dhundley
      Regular Contributor

      okay, i must have been coding the method incorrectly. as i was attempting to run it in order to provide you with the code snippet you requested i took care to really examine the documentation for the method. pretty sure that instead using a string value for the first parameter (e.g. "WPFControlText") i was putting in the actual mapped name of that property for the object (e.g. Alias. . . . . . .WPFControlText). Once i put in the string value it stopped waiting as soon as the text value on the screen was the same as the value I was waiting for it to be. 

       

      Thanks!

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    The example I have provided for WaitProperty, works fine. If it waits until the WaitTime period, it usually indicates that the TestObj is null, can not be found or it does not have that specified property.

     

    My guess is, it that it's a code related issue.

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      indicates that the TestObj is null

      Yes, this is what I expected to see in the code sample that I asked dhundley for.

      In a nutshell:

      -- WaitXXX methods so far worked as documented and I did not hear about any problems with them in the latest releases of TestComplete;

      -- All WaitXXX methods are added by TestComplete to the UI objects identified by TestComplete. Thus, in order these methods can be called, the parent object must exist. When this cannot be guaranteed, code must first check if object exist (if (<someObject>.Exists) then <someObject>.WaitXXX(...) ). Otherwise, TestComplete will wait, but not for the result of WaitXXX method, but for the object itself. Finally, an error will be posted to test log if the object does not appear within wait timeout.