2014-09-01 23 views
0

如何將參數放置在測試步驟描述的中間?機器人框架中的參數語法小黃瓜風格

當我創建這樣一切工序進行OK(參數是在步驟結束):

*** 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是第二個參數。

回答

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! 
+0

謝謝@Bryan奧克利! – LeeWay 2014-09-01 11:35:50