Forum Discussion

gentlesea's avatar
gentlesea
Frequent Contributor
14 years ago

WaitProperty without timeout wanted

Currently I am waiting for a control to be enabled this way:





  Aliases.MainWnd.TabBar.TabbtnPlanContent.WaitProperty("Enabled", true, -1);

  Aliases.MainWnd.TabBar.TabbtnPlanContent.Click();





Works if the timeout is not passed. I do not want a timeout however. If the button does not appear, the test fails anyway. Any chance to wait infinitely?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The WaitProperty method returns a boolean true or false if, after the timeout, the property successfully was assigned the value.  So, what you can do is use a while loop dependant upon that result.  something like



    while (!Aliases.MainWnd.TabBar.TabbtnPlanContent.WaitProperty("Enabled", true, -1)) 

    {

    Delay(500)

    }




    My only problem with infinite loops is that they are infinite.  At some point in time, if the property does not equal the desired value, you'll want to break out of the loop and say "We didn't get there" and record an error.  After all, isn't that essentially a bug in the code that you're expecting the property to turn to true and it never does?



    So... instead of an infinite loop, you can just set the timeout to a sufficiently high value... say, two minutes (120 seconds).  The code, then, would look like



    if (!Aliases.MainWnd.TabBar.TabbtnPlanContent.WaitProperty("Enabled", true, 120000)) then

    {

        Log.Error("The object never got enabled")

    }

    else {Aliases.MainWnd.TabBar.TabbtnPlanContent.Click()}





    If it takes longer than two minutes for an object to be enabled, usually, to me, that presents a problem towards usability of the application under test.



    But, YMMV.
  • gentlesea's avatar
    gentlesea
    Frequent Contributor
    Robert, thank you for your answer. I will use the infinite loop for now. My problem is, that we run this test on different systems and the differences are measurable in minutes (!) when heavy calculations are running. The script that has started TestExecute will shutdown an infinite loop after half an hour so this is OK for me for now.
  • vex's avatar
    vex
    Contributor
    Just thought I'd throw this out there, I do this also and like to add a timer so that if it's busy I can tell how long it's been running so if its WAY over expected time I will know when looking at the log.





    Set bar = Aliases.WebBrowser.pageStuff.Stuff.SomePanel.SomeControl.Etc.Etc.Etc



    sTime = aqDateTime.Time

    While bar.WaitAliasChild("imgBar", 500).Exists = True

      eTime = aqDateTime.Time

      Call Delay(1500, "Program is busy -- Elapsed Time: "& aqConvert.DateTimeToFormatStr(aqDateTime.TimeInterval(sTimeSec, eTimeSec), "%H:%M:%S"))

    WEnd



    eTime = aqDateTime.Time

    Log.Message "The duration of process was: " & aqConvert.DateTimeToFormatStr(aqDateTime.TimeInterval(sTimeSec, eTimeSec), "%H:%M:%S")