Robot框架小黄瓜风格的参数语法



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

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

*** 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

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

最新更新