【发布时间】:2018-04-20 05:00:47
【问题描述】:
我们如何将范围报告日志用于各个步骤。我的主要测试如下
@Test(testName = "Validate SinglePage and Multiple Page", enabled = true, priority = 1, groups = {"Section Formatting"})
public void SingleSection(String username, String password, String viewName, String r1, String r2, String r3, String r4, String r5, String SecItem1, String SecItem2, String DispStyle, String fType) throws InterruptedException {
extentTest = extent.startTest("SingleSection");
extentTest.log(LogStatus.INFO, "Login to the system");
login.loginToTenant(username, password);
extentTest.log(LogStatus.INFO, "Access the content menu");
// select view from content menu button
createContentMenuButton.setContentMenuButton();
extentTest.log(LogStatus.INFO, "Select the view");
// choose view
reportView.selectView(viewName);
extentTest.log(LogStatus.INFO, "Create the report");
// create the report in report builder
createChart.createReport(r1, r2, r3, r4, r5);
extentTest.log(LogStatus.INFO, "Add fields to sections");
// Adds fields to sections
sections.dragAndDropToSections(SecItem1, SecItem2);
例如,如果我想为ex-loginToTenant方法之一设置步骤,系统会出现空值异常错误。
方法loginToTenant的代码如下
public class loginPage extends ConfigReader {
WebDriver driver;
public ExtentReports extent;
public ExtentTest extentTest;
public loginPage(WebDriver driver) {
this.driver = driver;
}
// locators for login page
By userName = By.name("email");
By password = By.name("password");
By submitButton = By.id("logonButton");
By licenseWarning = By.partialLinkText("Click Here To Continue");
By plusButton = By.className("create-menu-container");
By banner = By.className("i4sidenav_width");
By logout = By.id("logoffBtn");
/**
* perform login to yellowfin and verify successful login
*
* @param uName
* @param passwd
* @return
*/
public String loginToTenant(String uName, String passwd) {
String loginmsg = null;
long d = 1000;
try {
extentTest.log(LogStatus.INFO, "Login to the system"); //I am getting an error on this line with null pointer exception
driver.findElement(userName).clear();
driver.findElement(userName).sendKeys(uName);
driver.findElement(password).clear();
driver.findElement(password).sendKeys(passwd);
driver.findElement(submitButton).click();
【问题讨论】:
-
您基本上有两个选择:将日志记录步骤手动添加到报告中,或者使用 BDD 工具(例如 Cucumber 或 JBehave)并使用 ExtentReports 中的 BDD 选项将步骤映射到报告中,如果使用 Cucumber 会更容易,但我已经在 JBehave 中实现了自己的类来完成或多或少相同的事情。
-
感谢您的回复。如何手动添加步骤?请指教。
标签: extentreports selenium-extent-report