Fast-forwarding a LOOP

0 Answers 76 Views
Coded Steps General Discussions Test Recording
Todd
Top achievements
Rank 1
Iron
Todd asked on 27 Jan 2023, 03:39 PM

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.

Elena
Telerik team
commented on 27 Jan 2023, 05:21 PM

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

Todd
Top achievements
Rank 1
Iron
commented on 27 Jan 2023, 05:55 PM

I do not believe a simple wait will work because of the need to periodically click a refresh button to reload the table's record. The record will not show up in the table, once it exists, automatically. The refresh button must be clicked to make the round trip back to the backend.
Elena
Telerik team
commented on 30 Jan 2023, 09:55 AM

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. 

WHILE Verify element exists not

         Click the refresh button. 
Please, let me know if this could work for you. I may be missing something from the test scenario, so, feel free to follow up if this suggestion is still not suitable. 

Thank you for your cooperation.

Regards, 
Elena

 

Todd
Top achievements
Rank 1
Iron
commented on 30 Jan 2023, 12:43 PM

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.

Elena
Telerik team
commented on 01 Feb 2023, 03:15 PM

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

 

No answers yet. Maybe you can help?

Tags
Coded Steps General Discussions Test Recording
Asked by
Todd
Top achievements
Rank 1
Iron
Share this question
or