首先,您需要根据以下大纲修改方案。
Scenario Outline: To test if the given list of users credentials are valid
Given user is already at Login page
And In credentails, user enters name as <Username> and Pwd as <Password>
Examples: Checking Login Scenarios
| Username | Password |
| user1 | password1 |
| user2 | invalid |
其次让我们考虑以下是您的步骤实现
package my.package.name
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.And;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
public class MyStepDefinitions {
@Given("^user is already at Login page$")
public void user_is_already_at_login_page() throws Throwable {
throw new PendingException();
}
@And("^In credentails, user enters name as (.+) and Pwd as (.+)$")
public void in_credentails_user_enters_name_as_and_pwd_as(String username, String password) throws Throwable {
throw new PendingException();
}
}
第三,让我们说在上述步骤实现下,您编写操作以登录站点并且操作因密码无效而失败。现在根据您使用的报告,您需要根据报告的 API 编写一种方法,就像我分享的范围一样。
public static synchronized void logFail(String message) {
try {
testReport.get().fail("<details>" + "<summary>" + "<b>" + "<font color=" + "red>" + "</font>" + "</b >" + "</summary>" + "<br>" + "<h6>" + "<b>" + BasePage.returnLocator(message) + "</b>"+ "</h6>" + "</br>" + message +"</details>"+" \n");
}
catch(Exception e) {
}
}
最后,按照上述层次结构,您将能够在报告中打印通过/失败。