Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robot Framework More efficient way to "Sleep"

I am using Robot Framework,

At the moment I have 5-10 test cases and i use sleep to wait for the page to fully load after clicking a button,

*** Variables ***

${Name} =  example name
${Next_Button} =  xpath=//*[@id="app"]/div/div[1]/div[3]/div/div/div[1]/div[2]/div/div/div/button[2]

*** Keywords ***
Open Tab
    Click Element  xpath=//*[@id="app"]/div/div[1]/div[1]/div[2]/nav/ul/li[2]/a
    Sleep  5s

Open Details
    Click Element  xpath=//*[@id="app"]/div/div[1]/div[3]/div/div/div[1]/div[2]/div/div[1]/img
    sleep  5s


Navigate to Room Details
    click button   xpath=//*[@id="app"]/div/div[1]/div[3]/div/div/div[1]/div[2]/div/div/button
    click button  ${Next_Button}
    click button  ${Next_Button}
    sleep  3s

When my tests increase to a bigger number it will take a lot of time to run them,

Whats a more efficient way of using Sleep, or a different keyword that would work for a lot of tests. My web app loads from 1-5 seconds.

like image 339
AutoTester213 Avatar asked Jan 28 '23 15:01

AutoTester213


1 Answers

Explicit sleeps generally are not very good. Instead you should use Wait Until Element Is Visible and Wait Until Element Is Not Visible or Wait Until Page Contains Element and Wait Until Page Does Not Contain Element.

Additional info: https://github.com/robotframework/HowToWriteGoodTestCases/blob/master/HowToWriteGoodTestCases.rst#avoid-sleeping

like image 64
JaPyR Avatar answered Mar 29 '23 10:03

JaPyR