Apratim Chaudhuri
Apratim Chaudhuri

Reputation: 43

Run Keyword If in RobotFramework

Could you please help me out that how Run Keyword If works in RIDE?

I want to click the "EXIT" button if there is any online error in the page after clicking on "Create" Button. I have put the code like this. But it did not work. After running, the test case did not fail but at the same time, the EXIT button was not clicked also.

Click Button    xpath=//*[@id="divHeader"]/table/tbody/tr/td[5]/input

${Result}    Page Should Contain Element    //*[@id="divError"]

Run Keyword If    '${Result}'=='PASS'    Click Button    xpath=//*[@id="MyForm"]/div[4]/table/tbody/tr/td[2]/input

Expected: As there is an online error, It should click the "Exit" button.

Upvotes: 0

Views: 705

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385840

Page should contain doesn't return a result. It either throws an exception or returns None.

If you need to get the pass/fail status of a keyword you need to use Run keyword and return status. However, it doesn't return "Pass" or "Fail". It returns the a boolean (either True or False).

${result}  Run keyword and return status
...  Page should contain element  //*[@id="divError"]

You can use the value directly as the condition in Run keyword if, like the following:

Run keyword if  ${result}
...  Click Button    xpath=//*[@id="MyForm"]/div[4]/table/tbody/tr/td[2]/input     

Upvotes: 3

Related Questions