0

How could I place arguments in the middle of the test step description?

When I create a step like this everything goes OK (arguments are at the end of the step):

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

How does the *** Test Cases *** and *** Keywords *** look like for a step like this:

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

, where user1 is the first argument and password1 is the second one.

LeeWay
  • 793
  • 3
  • 16
  • 28

1 Answers1

2

When using embedded arguments, embed them in the keyword name and omit the use of [Arguments]. It's also a good practice to put the arguments in quotes, though it's not strictly necessary. In my experience it helps to reduce ambiguity.

Here is an example in the pipe-delimited format:

*** 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!
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685