【问题标题】:Handle multiple statements in Run Keyword If - Robot Framework在 Run Keyword If - Robot Framework 中处理多个语句
【发布时间】:2018-06-06 02:48:39
【问题描述】:

仅当使用 Robot Framework 传递条件时,我才需要执行多个语句

请看代码:注意这是示例代码

*** 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}的范围内。

请帮助我。

【问题讨论】:

    标签: selenium robotframework


    【解决方案1】:

    我们可以在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
    

    【讨论】:

      【解决方案2】:

      您可以使用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
      

      【讨论】:

        【解决方案3】:

        设置测试变量 ${temp} rxu 运行关键字 if '${temp}'=='rxu' ...运行关键字 ...登录到控制台这是一个 ... AND 登录到控制台这是两个 ... ELSE 运行关键字日志以控制另一个块

        每行前的空格应符合 python 间距准则

        【讨论】:

          猜你喜欢
          • 2017-10-27
          • 1970-01-01
          • 1970-01-01
          • 2021-12-17
          • 1970-01-01
          • 2014-07-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多