如何为各个步骤使用范围报告

How to use extent reports for individual steps

我们如何为各个步骤使用范围报告日志。我的主要测试如下

@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();

如果您想为 loginToTenant 方法创建单独的步骤,您可以类似地在登录页面 class 中创建范围报告。它将为其创建单独的步骤。