Forum Discussion

mike_zone's avatar
mike_zone
Occasional Contributor
11 years ago
Solved

Help. Click button until...

There is a game that I need to automate. Everything worked until it did not take action:" Press the button with a delay until you see a certain value / How do you picture"

How do I add a function in my test?
  • Yeah, then a Do-While loop is pretty much your best bet here... and, again, it can be done both with Keyword tests and script code.  At some point, you need to tell TestComplete the condition for "falling out"... a while loop is your best bet.

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Rough pseudo-code would look something like:





    var ValueToTest

    do

    {

        Delay(500)

        Aliases.MyButton.Click()

        ValueToTest = Aliases.MyObject.PropertyValue

    }

    while (ValueToTest != 'What I Want');

     
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Yeah, then a Do-While loop is pretty much your best bet here... and, again, it can be done both with Keyword tests and script code.  At some point, you need to tell TestComplete the condition for "falling out"... a while loop is your best bet.
  • mike_zone's avatar
    mike_zone
    Occasional Contributor
    This code if ... And if the standard features of the program? Script or mandatory?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Are you clicking and HOLDING on the button or are you clicking the button multiple times?  I'm not clear on that piece...



    If you're clicking the button multiple times until a particular condition is met, whether you use Keyword testing or not, what you're asking is essentially described in that pseudo-code.  You want TestComplete to repeat a particular action until a condition is met.  



    I think you could do something similar with a Click and Hold action as well... the code would be a bit different, but you'd still need some sort of looping mechanism to test for the condition.



    Keyword tests have While loops as well.  You would need to take your action (clicking on the button) and wrap a While loop around it until your desired condition is met or (perhaps better code) until a certain period of time has elapsed.









  • mike_zone's avatar
    mike_zone
    Occasional Contributor
    Just click (without holding), click, click.........until necessary combination will not fall out