Is there a way in a coded step to accomplish the ELSE clause below?
LOOP (10) Times
IF element not present
Refresh to see if element becomes present
ELSE
Coded step to set for iteration to max so no more loops occur (or break out through other means without erroring)
Is there a way with a coded step to accomplish the ELSE clause above? I would like to fast-forward the LOOP iteration to the end by overriding the current iteration value with 10 once the element exists? Because of the required refresh, I can't just wait for it to exist.
I have workable solutions with both LOOP and WHILE, but both have drawbacks. The FOR doesn't require coded steps (only a simple coded step if the above ELSE is possible) but fills the log with iterations that don't do anything. The WHILE stops once my condition is met and doesn't do the excessive logging but requires far more complicated coded steps. This approach would be hard for me to teach to our test writers who, for the most part, are not code developers.
Thank you.
Hi Todd,
Can you elaborate on the specific scenario?
I wonder if a simple wait for exists step in the if statement won't work to cover this, without using the loops at all? You might need to increase its wait for element time in the step properties if you need to wait for more than 30 seconds.
Thank you in advance.
Regards,
Elena
Hi Todd,
Thanks for folllowing up with these clarifications.
Isn't it the While..Loop option suitable to cover this scenario without the need of coded steps?
In this case it should look similar to the below sample in order to click that referesh button only until the expected element is not present on the page. Once the element exists, the While...Loop will be exited without the need of coded steps.
Thank you for your cooperation.
Regards,
Elena
The challenge with the WHILE loop is that the condition you are looking for may never occur and you have to give up at some point. As far as I know, this requires coded steps to setup and maintain a timestamp or counter, then an error has to be raised to break out of the while loop once the maximum wait has been exceeded. Between the two solutions I've come up with, leveraging a WHILE loop is more complicated when it comes to ensuring we don't loop infinitely.
For the most part, those writing these tests are not code developers and I was hoping for a simple exit from either loop without having to raise an error. A step that simply breaks out of a loop would be great, but I don't see where that exists. If the ability to change the LOOP iteration via a coded steps exists, this seems like it would be another viable option.
As-is, a LOOP does exactly what I need (i.e. refreshes the page a maximum number of times, looking for a record to show up). The only shortcoming is that I have to wait for any remaining iterations to complete which is a minor time slowdown for the test and a lot of "noise" in the log files. I'll keep the LOOP solution. I was just hoping there was a way to avoid the iterations that do absolutely nothing, without raising an error, because the record showed up.
Thank you Elena.
Hey Todd,
Thank you for following up on this thread.
It seems you have found the most feasible approach to cover the scenario. You are right that if there is a chance that the condition is never met, you can't rely on the WHILE loop as it becomes infinite.
But I have to admit that there is no straight forward way to exit the loop or maintain its iterations. Such scenario can be covered in a coded step but if this is not convenient for the team working on the project, it sounds a better idea to stick to the curent solution. Although it takes a little longer run time and floods the execution log.
I appreciate your cooperation in our conversation.
Regards,
Elena