2

I need to test the Load More button using Do-While Loop in Robot Framework using Selenium. I don't know the syntax of do-while so I used a common syntax in the following code.

My Sample Code Logic

do {

    Run Keyword If    Run Keyword And Return Status    Element Should Be Visible   ${PO_FieldLabel}) == FALSE     FAIL Item not loaded Properly

} while (Run Keyword And Return Status    Element Should Be Visible   ${PO_LoadMore_Btn})

My logic is to loop the iteration till the Load More Button ${PO_LoadMore_Btn} is exist. If exist, check the Name Field ${PO_FieldLabel} is exist. Once the Name Field ${PO_FieldLabel} is NOT EXIST, FAIL the test case and skip the loop.

3 Answers 3

5

In Robot Framework, there is NO WHILE LOOP, DO-WHILE LOOP. It has only FOR LOOP We can perform the DO-WHILE LOOP using FOR LOOP

Kindly look the following code

:FOR    ${i}    IN RANGE    999999
/
/     YOUR LOGIC
/
/    Exit For Loop If    {bool expression}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer.
2

In Robot Framework looping is done using the :FOR loop construction. The Robot Framework userguide section on Loops has more information on the types of loops you can construct and the input they require.

1 Comment

Thanks for your answer.
0

While loops have been added to RobotFramework 5.0

This allows you to build a DO-While structure with in infinite While loop you conditionally break.

WHILE    True
    
    # Body of your Do-While loop here
    
    IF    ${some_condition}
        BREAK
    END
END

Documentation: v5.0 Latest

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.