Robot框架Gherkin风格中的参数语法

时间:2014-09-01 10:34:13

标签: robotframework gherkin

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

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

*** 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 是第二个参数。

1 个答案:

答案 0 :(得分:2)

使用嵌入式参数时,请将它们嵌入关键字名称中,并省略[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!