Forum Discussion

SaloRB's avatar
SaloRB
Occasional Contributor
14 years ago

Wait for one or another object at the same time

I have this piece of code that waits for one object or another to continue the process



If Aliases.Setup.Error.Exists OR Aliases.Setup.Success.Exists Then

    Call Log.Message("Message")

End If



The problem is that if the first object doesn't exists and the second one does, it waits until the Auto-wait timeout finishes when the test realizes that the second object is the one that exists, making the test waste a lot of time if the Auto-wait timeout is set to more than 2 minutes.



Is there any way I can make the test search for both objects at the same time?

5 Replies

  • pmartin66's avatar
    pmartin66
    Occasional Contributor
    or, just don't use an OR statement



    write and If/Then for each case. even nest it if it makes sense. or implement it with a switch statement.
  • SaloRB's avatar
    SaloRB
    Occasional Contributor
    Hi Mike, Peter



    I tried using the WaitProperty Method, but if the first object doesn't show up it will never start looking for the second one, and the same happens if I use an If/Then for each case.



    Thanks for your help
  • Salomon,


    Try using the WaitAliasChild method to get the Error and Setup objects. If the last parameter of this method is 0, it doesn't use "Auto-wait timeout" and returns the result immediately.


    You will have to create a "waiting" loop like this --




    ...

    Counter = 0

    Found = False

    bWait = True


    While bWait

       If Aliases.Setup.WaitAliasChild("Error", 0).Exists  OR Aliases.Setup.WaitAliasChild("Success", 0).Exists Then

          Found = True

          bWait = False

       Else

          Delay 500  ' Wait for 0.5 sec

          Counter = Counter + 1

          ' If the total wait time is 20 * 0.5 = 10 sec, then exit...

          If Counter = 20 Then 

            bWait = False

          End If

       End If

    WEnd


    If Found Then

      ' Found

    Else

       ' Not found

    End If

    ...



  • SaloRB's avatar
    SaloRB
    Occasional Contributor
    Thank you very much Alex, I used something similar to solve it