简体   繁体   English

使用范围报告获取 Null 指针异常

[英]Getting Null Pointer Exception with Extent Reports

I m trying to run a small test program with Extent Reports but getting Null Pointer Exception.我正在尝试使用 Extent Reports 运行一个小型测试程序,但得到 Null 指针异常。 If i am running this code, without using Extent Report functionality it's working fine.如果我正在运行此代码,而不使用范围报告功能,它工作正常。 Kindly help.请帮忙。 Below is my code-下面是我的代码-

package selenium.ExtentReports;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import io.github.bonigarcia.wdm.WebDriverManager;

public class ExtentReportDemo {

    ExtentReports extent;
    WebDriver driver;

    @BeforeTest
    public void config() {

        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();

        String path = System.getProperty("user.dir") + "//Reports//index.html";
        ExtentSparkReporter reporter = new ExtentSparkReporter(path);
        reporter.config().setReportName("Web Automation Results");
        reporter.config().setDocumentTitle("Test Results");

        ExtentReports extent = new ExtentReports();
        extent.attachReporter(reporter);
        extent.setSystemInfo("Tester", "Gaurav Singh");
    }

    @Test
    public void initialDemo() {
        extent.createTest("Initial Demo");
        driver.get("https://rahulshettyacademy.com");
        System.out.println(driver.getTitle());
        extent.flush();
    }

}

Error which i am getting我得到的错误

FAILED: initialDemo
java.lang.NullPointerException
    at selenium.ExtentReports.ExtentReportDemo.initialDemo(ExtentReportDemo.java:38)

I have just instantiate the extent variable outside the clas.我刚刚在类之外实例化了范围变量。 And it's working for me now.它现在对我有用。 ExtentReports extent = new ExtentReports(); ExtentReports 范围 = new ExtentReports();

ExtentReports extent = new ExtentReports();

Don't initialize in @BeforeTest methods once you declared it Publicly.公开声明后,不要在@BeforeTest方法中进行初始化。 Instead Use:而是使用:

extent = new ExtentReports();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用范围报告时出现空指针异常 - Null pointer exception when using extent report c#nunit范围报告未获取屏幕截图,并传递异常 - c# nunit extent reports not getting screenshot, passing on exception 在带有范围报告的selenium POM中截取屏幕时出现空指针异常 - Null pointer exception while taking screenshot in selenium POM with extent report 在selenium的范围报告中获取错误 - Getting Error in extent reports for selenium 没有为Extent Test Manager报告打印日志 - Log is not getting printed for Extent Test Manager reports 获取Appium驱动程序“空指针异常” - Getting Appium Driver “Null pointer exception” 范围报告:测试步骤在范围报告中的最后一个测试中合并,当并行执行测试时 - Extent Reports: Test Steps are getting merged in last test in Extent Reports, When executing test in Parallel 对于获取 wiered Exception Null_Pointer_Exception 的flipkart 项目 - For a flipkart project getting the wiered Exception Null_Pointer_Exception 扩展报告:日志被追加到报告中的单个测试用例上 - Extent Reports: Logs are Getting Appended on to a Single Test Case in the Report 使用 Selenium Java 获取输入时获取空指针异常 - Getting Null Pointer Exception while taking input by using Selenium Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM