在运行关键字If - 机器人框架中处理多个语句



只有在使用机器人框架传递条件时才需要执行多个语句

请查看代码:请注意这是一个示例代码

*** Settings ***
Library    Selenium2Library
Library    Collections
*** Keywords ***
Parent Routine
${isElementExist}    Run Keyword And Return Status    Element Should Be Visible   id=txt1
Run Keyword If    ${isElementExist}     click element      id=btn1
Run Keyword If    ${isElementExist}     click element      id=btn2
Run Keyword If    ${isElementExist}     click element      id=btn3
*** Test Cases ***
Sample Test Case
[Documentation]   Simple test for If Condition
Parent Routine

我不知道如何将click element的所有陈述捆绑在Run Keyword If ${isElementExist}范围内.

请协助我。

当然,我们可以在Run Keyword If中执行多个语句

If 语句应为

Run Keyword If    ${isElementExist}    Run Keywords    click element      id=btn1
...   AND    click element      id=btn2
...   AND    click element      id=btn3

完整的代码是

*** Settings ***
Library    Selenium2Library
Library    Collections
*** Keywords ***
Parent Routine
${isElementExist}    Run Keyword And Return Status    Element Should Be Visible   id=txt1
Run Keyword If    ${isElementExist}    Run Keywords    click element      id=btn1
...   AND    click element      id=btn2
...   AND    click element      id=btn3
*** Test Cases ***
Sample Test Case
[Documentation]   Simple test for If Condition
Parent Routine

您可以使用Run Keywords,它将按顺序执行所有给定的关键字。

${isElementExist}    Run Keyword And Return Status    Element Should Be Visible   id=txt1
Run Keyword If    ${isElementExist}     Run Keywords    click element      id=btn1
...    AND    click element      id=btn2
...    AND    click element      id=btn3

Set Test Variable ${temp} rxu 如果 '${temp}'=='rxu' 则运行关键字 ... 运行关键字 ... 登录到控制台 这是其中之一 ... 和 登录到控制台 这是两个 ... 否则 运行关键字日志以控制台另一个块

每行前的空格应确认 python 间距准则

最新更新