我是新來的黃瓜。我想測試兩個登錄場景:使用Cucumber獲取「沒有匹配的膠水代碼」的空字段錯誤
- 具有有效憑據,其中用戶應該能夠成功地
- 登錄空的用戶名和密碼,如果用戶不應該能夠登錄
我有對於上述方案如下代碼:
Scenario Outline: Test login with valid credentials
Given Open firefox and start application
When I enter "<username>" and "<password>"
Then User should be able to login successfully
Examples:
| username | password |
| ro | mech |
Scenario Outline: Test login with empty credentials
Given Open firefox and start application
When I enter "<username>" and "<password>" (this shows a warning)
Then User should be not able to login
Examples:
| username | password |
| | |
在java文件我有以下代碼:
@When("^I enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void I_enter_and_(String username, String password) throws Throwable {
driver.findElement(By.id("ember629")).sendKeys(username);
driver.findElement(By.id("ember640")).sendKeys(password);
}
我的問題是方案2顯示了一個警告消息:
Step 'I enter "<username>" and "<password>"' does not have a matching glue code
這是否意味着像我需要寫一個單獨的Java功能有效,空和無效的憑證每一個場景?我不能使用相同的Java功能:
public void I_enter_and_(String username, String password)
適用於所有情況?如果我運行的特徵文件,我得到這樣的輸出:
You can implement missing steps with the snippets below:
@When("^I enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void i_enter_and(String arg1, String arg2) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
有什麼辦法重用Java函數I_enter_and_
?
你用什麼類運行? – mosaad