Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

cucumber - Cannot invoke "com.aventstack.extentreports.ExtentTest.fail(com.aventstack.extentreports.markuputils.Markup)" because "extenttest" is null

#Scenario Outline: Check login is successful with valid credentials#

src/test/resources/features/login.feature:15

##Inside Step - User Is on Login Page##

###This is Switch block ###

####Given user is on login page # StepDef.LoginSteps_POM.user_is_on_login_page() ####

#####java.lang.NullPointerException: Cannot invoke"com.aventstack.extentreports.ExtentTest.fail(com.aventstack.extentreports.markuputils.Markup)" because "extenttest" is null #####

public class extentReportListener {

public static ExtentHtmlReporter report =null;
public static ExtentReports extent =null;
public static ExtentTest test = null;

public static ExtentReports setUp() {
    String reportLocation = "./reports/Extent_Report.html";
    report = new ExtentHtmlReporter(reportLocation);
    report.config().setDocumentTitle("Veronica-Test-Report");
    report.config().setReportName("Veronica-Test-Report");
    report.config().setTheme(Theme.STANDARD);
    System.out.println("Report Location Initialized...");
    report.start();

    extent = new ExtentReports();
    extent.attachReporter(report);
    extent.setSystemInfo("Application", "MCM");
    extent.setSystemInfo("Operating System", System.clearProperty("os.name"));
    extent.setSystemInfo("User Name", System.getProperty("user.name"));
    System.out.println("System Info set in Extent report");     
    return extent;

}

public static void testStepHandle (String teststatus, WebDriver driver,ExtentTest extenttest, Throwable throwable )
{
    switch(teststatus) {
    case "FAIL":
        System.out.println("This is Switch block "); //Reached here.
        extenttest.fail(MarkupHelper.createLabel("Test Case Failed: ", ExtentColor.RED)); //Getting error on this extenttest
        extenttest.error(throwable.fillInStackTrace());
        
        if(driver != null) {
            driver.quit();
        }

        break;

    case "PASS":
        extenttest.pass(MarkupHelper.createLabel("Test Case is Passed :", ExtentColor.GREEN));
        
    default:
        break;
        

    }
}

}

question from:https://stackoverflow.com/questions/65922257/cannot-invoke-com-aventstack-extentreports-extenttest-failcom-aventstack-exten

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...