Forum Discussion

gdave's avatar
gdave
Regular Contributor
6 years ago

Loop Test

Hi all

 

I intend to design a loop test where my keyword test will look at the 'Next' button on the screen and its property. If the button is disabled it will select number 2 from one of the drop down list, if still disabled then it must select number 3 from the dropdown list and so on. So this loop must continue to select the next available number until the 'Next' button is enabled.

I am bit struggling to come up with a keyword test solution which will continue to select next available number from the list until the the button in question is enabled. Any help around this will be much appreciated.

 

Thanks

G

  • I'm not 100% positive, but I believe your issue is the Data-Driven Loop inside of your While loop.

     

    If you convert the keyword test to script you will see that a Data-Driven Loop translates to a While Not loop. So you have a While Not Loop inside of a While Loop. The code will not exit the While Not Loop until all data is read from the Data-Driven Loop.

     

    I recommend finding a different way to feed the different data to your keyword test

    OR

    instead of using a While Loop use an If.. Then statement to exit your Data-Driven Loop. In other words, for each iteration of the Data-Driven Loop check the Enable property and exit the loop using a Go To label if the property is set as you want.

     

    Hope that helps.

     

     

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I would do something like this... pseudo code, you understand, but translate to a keyword test.

     

    set variable(boolean) HasNext = Aliases.MyApp.MyForm.buttonNext.Enabled
    set variable(integer) rowtoclick = 0
    while HasNext not equal to true
       Click row(rowtoclick)
    set variable rowtoclick = rowtoclick + 1; set variable(boolean) HasNext = Aliases.MyApp.MyForm.buttonNext.Enabled

    Essentially, check the enabled property of the button and, with a while loop, click on each row, incrementing the row number each time.

     

    Hope this helps give you direction.

    • gdave's avatar
      gdave
      Regular Contributor

      tristaanogre wrote:

      I would do something like this... pseudo code, you understand, but translate to a keyword test.

       

      set variable(boolean) HasNext = Aliases.MyApp.MyForm.buttonNext.Enabled
      set variable(integer) rowtoclick = 0
      while HasNext not equal to true
         Click row(rowtoclick)
      set variable rowtoclick = rowtoclick + 1; set variable(boolean) HasNext = Aliases.MyApp.MyForm.buttonNext.Enabled

      Essentially, check the enabled property of the button and, with a while loop, click on each row, incrementing the row number each time.

       

      Hope this helps give you direction.


      So here's what I did:

       

       

      However the problem now is that it does not drop out of the loop as soon as the button is enabled and continues to iterate through numbers 1 to 12

       

      In the above scenario the button is enabled when list box item 02 is selected however the test doesn't drop out of the loop at this stage and continues to iterate through all the remaining numbers. I dont want it to iterate through the remaining numbers if the button is enabled at early stages.

       

      Thanks

      G

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        I think what needs to happen is that you need to refresh the value being used in the while loop... that's why I reassigned the variable "HasNext" inside the loop, to make sure we get the latest version of it.  TestComplet caches some information so there needs to be some sort of refresh of the cache.

        Alternatively, in the "while" loop, in your evaluation of the Enabled property, instead of simply using "Object Property" use a code expression and utilize the WaitAliasChild method to "search" for the buttonNext which does a refresh of the object in memory.