【问题标题】:Arguments syntax in Robot framework Gherkin styleRobot 框架 Gherkin 风格中的参数语法
【发布时间】:2014-09-01 10:34:12
【问题描述】:

如何在测试步骤描述的中间放置参数?

当我创建这样的步骤时,一切正常(参数在步骤的末尾):

*** Test Cases ***
Scenario: Login as a valid user
     When user is logged in as:    user1    password1

*** Keywords ***
user is logged in as:
[Arguments]    ${arg_user}    ${arg_pass}
Click Link    id=loginLink
Page Should Contain    Use a local account to log in
Input Text    id=UserName    ${arg_user}
Input Text    id=Password    ${arg_pass}
Click Button    xpath=//*[@id="loginForm"]/form/fieldset/input

对于这样的步骤,*** Test Cases ****** Keywords *** 看起来如何:

When user user1 is logged in with the following password: password1

,其中 user1 是第一个参数,password1 是第二个参数。

【问题讨论】:

    标签: robotframework gherkin


    【解决方案1】:

    当使用嵌入式参数时,将它们嵌入到关键字名称中并省略使用[Arguments]。将参数放在引号中也是一个好习惯,尽管这不是绝对必要的。根据我的经验,它有助于减少歧义。

    这是一个以竖线分隔的示例:

    *** Keywords ***
    | When user "${user}" is logged in with the following password: "${password}"
    | | ${result}= | Set Variable | username is ${user} and password is ${password}
    | | [Return] | ${result}
    
    *** Test Cases ***
    | Example of how to use keyword with embedded arguments
    | | ${result}= | When user "bob" is logged in with the following password: "superSecret!"
    | | Should be equal | ${result} | username is bob and password is superSecret!
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      • 2016-08-30
      • 1970-01-01
      • 2019-10-05
      • 2018-12-27
      相关资源
      最近更新 更多