email2vimalraj / CucumberExtentReporter

A plugin to generate the cucumber jvm custom html report using ExtentsReport
http://www.vimalselvam.com/cucumber-extent-reporter/
MIT License
58 stars 75 forks source link

Getting Null pointer exception #23

Closed jagadishchandran closed 7 years ago

jagadishchandran commented 7 years ago

Getting the following error -

java.lang.NullPointerException
    at com.cucumber.listener.ExtentCucumberFormatter.close(ExtentCucumberFormatter.java:228)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at cucumber.runtime.Utils$1.call(Utils.java:40)
    at cucumber.runtime.Timeout.timeout(Timeout.java:16)
    at cucumber.runtime.Utils.invoke(Utils.java:34)
    at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:294)
    at com.sun.proxy.$Proxy16.close(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.close(JUnitReporter.java:232)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:102)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

This is the runner class file look like -

@CucumberOptions(
                    monochrome = true,
                    features = "src/test/resources/features/Login.feature",
                    format = { "pretty","html: cucumber-html-reports",
                    "json: cucumber-html-reports/cucumber.json" },
                    plugin = {"com.cucumber.listener.ExtentCucumberFormatter:output/report.html"}

This is the @BeforeClass


    @BeforeClass
    public static void setup() throws Throwable {

        // Initiates the extent report and generates the output in the output/Run_<unique timestamp>/report.html file by default.
        ExtentCucumberFormatter.initiateExtentCucumberFormatter();

        // Loads the extent config xml to customize on the report.
        ExtentCucumberFormatter.loadConfig(new File("src/test/resources/extent-config.xml"));

        // User can add the system information as follows
        String [] bInfo = new DriverFactory().browserInfo();

        ExtentCucumberFormatter.addSystemInfo("Browser Name", bInfo[0]);
        ExtentCucumberFormatter.addSystemInfo("Browser version", bInfo[1]);
        ExtentCucumberFormatter.addSystemInfo("Selenium version", "v2.53.0");

        Map<String, String> systemInfo = new HashMap<String, String>();
        systemInfo.put("Cucumber version", "v1.2.5");
        systemInfo.put("Extent Cucumber Reporter version", "2.41.1");
        ExtentCucumberFormatter.addSystemInfo(systemInfo);
    }
email2vimalraj commented 7 years ago

Just a wild guess, what happens when you remove the format add-on in your @CucumberOptions?

dirtmark333 commented 7 years ago

Hi All! I am also having this issue even without the format add-on in my @CucumberOptions. (My @BeforeClass is more or less the same.)

jagadishchandran commented 7 years ago

Hi Vimal, Is there any precondition like the setup method (for initializing the extent report) in @BeforeClass should be present only in Runner class. The krisp of this issue is like, if the @BeforeClass is present in Runner class, everything works fine. But if you keep in Feature step class, It is throwing this NullPointerException. Please help us to resolve.

email2vimalraj commented 7 years ago

@jagadishchandran : Apologies for the delayed reply. Could you please post some sample with the feature step class for me to reproduce. I'm also thinking of enhancing by removing the dependency of @BeforeClass. You will hear from me soon about the new feature.

NgocAnHa commented 7 years ago

Hi all, I have also got Null pointer exception but the Null point at com.cucumber.listener.ExtentCucumberFormatter.feature

java.lang.NullPointerException
    at com.cucumber.listener.ExtentCucumberFormatter.feature(ExtentCucumberFormatter.java:183)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at cucumber.runtime.Utils$1.call(Utils.java:40)
    at cucumber.runtime.Timeout.timeout(Timeout.java:16)
    at cucumber.runtime.Utils.invoke(Utils.java:34)
    at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:294)
    at com.sun.proxy.$Proxy10.feature(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.feature(JUnitReporter.java:165)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:69)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

I notice that feature() method always getting NULL at line "this.featureTest = extent.startTest("Feature: " + feature.getName());".

public void feature(Feature feature) {
        this.featureTest = extent.startTest("Feature: " + feature.getName());
        Iterator var2 = feature.getTags().iterator();

        while(var2.hasNext()) {
            Tag tag = (Tag)var2.next();
            this.featureTest.assignCategory(new String[]{tag.getName()});
        }
    }

My runner file as below:

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"com.cucumber.listener.ExtentCucumberFormatter"},features = {"src/test/java/BDD/FirstFeature.feature"}, glue={"steps"})
public class BDDRunner {

    @BeforeClass
    public static void initial()
    {
        ExtentCucumberFormatter.initiateExtentCucumberFormatter();
        ExtentCucumberFormatter.loadConfig(new File("src/extent-config.xml"));
    }
}

Dependency which I am using

         <dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>1.1.1</version>
        </dependency>

Please help me for the investigating Thanks for your great support.

email2vimalraj commented 7 years ago

Kindly try the latest version and see how it goes. Re-open in case you find any issues.

NgocAnHa commented 7 years ago

Hi @email2vimalraj, I notice that the latest version is 1.1.1. This version I am using and get the error that I mentioned. If you have time, pls help me to investigate. Many thanks 👍

email2vimalraj commented 7 years ago

The latest released version is 2.0.0. Kindly update in your pom and follow the instructions as mentioned in readme.

NgocAnHa commented 7 years ago

Hi @email2vimalraj The issue has been resolved after using "cucumber-extentsreport version 2.0.0". Thank you for your great support. 👍

Glorifind commented 6 years ago

Hi, I have recently encountered the same problem

my pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.samsung.sHealthAutomatedTests</groupId>
    <artifactId>sHealthAutomatedTests</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <fork>true</fork>
                        <!--<executable>C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe</executable>-->
                        <executable>${env.JAVA_HOME}\bin\javac.exe</executable>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                        <testErrorIgnore>false</testErrorIgnore>
                        <testFailureIgnore>false</testFailureIgnore>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
            <version>2.12.2</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.13.0</version>
        </dependency>

        <dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>

and my runner:

package cucumberFramework.runnerFiles;

import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.AfterClass;
import org.junit.runner.RunWith;

import java.io.File;

@RunWith(Cucumber.class)
@CucumberOptions (
        features = {"src/test/java/cucumberFramework/featureFiles"},
        glue = {"cucumberFramework.stepsFiles"},
        plugin = {"com.cucumber.listener.ExtentCucumberFormatter:output/report.html"}
)
public class MainRunner {
    @AfterClass
    public static void teardown() {
        //Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));
        Reporter.setSystemInfo("user", System.getProperty("user.name"));
        Reporter.setSystemInfo("os", "Windows");
        Reporter.setTestRunnerOutput("Sample test runner output message");
    }
}

and trace it throw at me:

java.lang.NullPointerException
    at com.cucumber.listener.ExtentCucumberFormatter.match(ExtentCucumberFormatter.java:289)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at cucumber.runtime.Utils$1.call(Utils.java:40)
    at cucumber.runtime.Timeout.timeout(Timeout.java:16)
    at cucumber.runtime.Utils.invoke(Utils.java:34)
    at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:294)
    at com.sun.proxy.$Proxy11.match(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.match(JUnitReporter.java:68)
    at cucumber.runtime.Runtime.runStep(Runtime.java:279)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:95)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:38)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Nikhil56-diatoz commented 4 years ago

Can Someone Help with how to use stubs with cucumber test.