cancel
Showing results for 
Search instead for 
Did you mean: 

Loop Test

SOLVED
Highlighted
Frequent Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
Frequent Contributor

Re: Loop Test

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.

 

 

9 REPLIES 9
Community Hero

Re: Loop Test

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Frequent Contributor

Re: Loop Test


@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:

 

image.png

 

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

 

image.png

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

Community Hero

Re: Loop Test

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Frequent Contributor

Re: Loop Test


@tristaanogre wrote:

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.


Would you be kind enough to provide me with an example of a code expression utilizing WaitAliasChild to "search" for the buttonNext ?

 

Thanks

G

Community Hero

Re: Loop Test

Aliases.MyApp.MyForm.WaitAliasChild('buttonNext', 1000).Enabled

 

Put this in as a code expression.  It will return the "buttonNext" object's enabled property after a search and find of the object, waiting 1000 ms for it to resolve.  


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Community Manager

Re: Loop Test

Hi @gdave,

 

Did @tristaanogre's suggestions help you find a solution?

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Frequent Contributor

Re: Loop Test


@tristaanogre wrote:

Aliases.MyApp.MyForm.WaitAliasChild('buttonNext', 1000).Enabled

 

Put this in as a code expression.  It will return the "buttonNext" object's enabled property after a search and find of the object, waiting 1000 ms for it to resolve.  


Hi

Sorry for the delay in getting back on this as I was away for few days.

 

So I did try the code snippet here but the behaviour hasn't changed at all. It still iterates through all values from the ListBox36 and does not drop out of the loop as soon as 'Next' button is enabled.

 

I also tried changing the sequence of code snippet ie: placing it before and after ListBox36 item but still no success.

image.png

 

I then also tried to change the suggest code to :Aliases.TransactConsole.omTransactFormWizardView.PanelDataEntry.PanelButtons.BitBtnNext.Wait(1000).Enabled

This gave me a different result altogether. Screenshot below:

 

image.png

Not sure what exactly will help this to work as there are quiet a few test which rely on the success of this step. Thanks

 

 

Frequent Contributor

Re: Loop Test

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.

 

 

Frequent Contributor

Re: Loop Test

You were absolutely correct. Data-Driven Loop translates to a While Not loop forcing the test to complete the iteration instead of dropping out of the loop at specific condition which was set.

 

So in order to counter the above issue, I used While Loop along with If...Then statement so that the test drops out of the loop as soon as the Enable property is True. Also as suggested, I used Go To Label.

 

Please find the screenshot of my solution below:

 

image.pngSolution.

Thanks.

Ask a SmartBear
Top Kudoed Authors