damianszczepanik/maven-cucumber-reporting

net.masterthought - No JSON report file was found

SeleniumNinja opened this issue · 8 comments

I get the following error when I run the code

About to generate Cucumber report.
May 02, 2023 6:55:06 PM net.masterthought.cucumber.ReportBuilder generateErrorPage
WARNING: Unexpected error
net.masterthought.cucumber.ValidationException: No JSON report file was found!
        at net.masterthought.cucumber.ReportParser.parseJsonFiles(ReportParser.java:61)
        at net.masterthought.cucumber.ReportBuilder.generateReports(ReportBuilder.java:97)
        at net.masterthought.cucumber.CucumberReportGeneratorMojo.execute(CucumberReportGeneratorMojo.java:236)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:370)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:351)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:171)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:163)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:294)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:960)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
CucumberOptions file

Runner


import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
 
@RunWith(Cucumber.class)
@CucumberOptions(features="src/test/java/features",
        plugin = {"pretty", "json:target/reports/cucumber.json",
                "html:target/reports/cucumber.html"},
        glue= {"stepDefs"},
        stepNotifications = true,
        monochrome = true
        )
public class TestRunner {
}

Pom


<?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>org.example</groupId>
    <artifactId>Cucumber</artifactId>
    <version>1.0-SNAPSHOT</version>
 
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
 
 
    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.4.0</version>
        </dependency>
 
 
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
 
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>7.8.1</version>
        </dependency>
 
 
 
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>7.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>compile</scope>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.23.1</version>
            <scope>test</scope>
        </dependency>
 
 
        <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>
 
 
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.9.11</version>
        </dependency>
 
 
        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>31.1-jre</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.8.3</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.26</version>
            <scope>compile</scope>
        </dependency>
 
 
        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>2.0.7</version>
            <scope>test</scope>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.7</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
 
        <!-- https://mvnrepository.com/artifact/com.opencsv/opencsv -->
        <dependency>
            <groupId>com.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>5.7.1</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/picocontainer/picocontainer -->
        <!-- https://mvnrepository.com/artifact/picocontainer/picocontainer -->
        <!-- https://mvnrepository.com/artifact/picocontainer/picocontainer -->
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
        <!-- https://mvnrepository.com/artifact/picocontainer/picocontainer -->
 
 
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
        <!-- https://mvnrepository.com/artifact/picocontainer/picocontainer -->
        <dependency>
            <groupId>picocontainer</groupId>
            <artifactId>picocontainer</artifactId>
            <version>1.2</version>
        </dependency>
 
 
        <!-- https://mvnrepository.com/artifact/de.monochromata.cucumber/reporting-plugin -->
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-html -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-html</artifactId>
            <version>0.2.7</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
 
 
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>7.11.2</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/net.masterthought/maven-cucumber-reporting -->
        <!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
        <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports-cucumber4-adapter -->
 
        <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
 
        <!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
 
        <!-- https://mvnrepository.com/artifact/net.masterthought/maven-cucumber-reporting -->
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>maven-cucumber-reporting</artifactId>
            <version>5.7.5</version>
        </dependency>
 
 
    </dependencies>
 
 
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>5.7.5</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>Cucumber</projectName>
                            <!-- optional, per documentation set this to "true" to bypass generation of Cucumber Reports entirely, defaults to false if not specified -->
                            <skip>false</skip>
                            <!-- output directory for the generated report -->
                            <outputDirectory>${project.build.directory}/reports</outputDirectory>
                            <!-- optional, defaults to outputDirectory if not specified -->
                            <inputDirectory>${project.build.directory}/reports</inputDirectory>
                            <jsonFiles>
                                <!-- supports wildcard or name pattern -->
                                <param>**/*.json</param>
                            </jsonFiles>
                            <!-- optional, defaults to outputDirectory if not specified -->
 
                            <!-- optional, set true to group features by its Ids -->
                            <mergeFeaturesById>false</mergeFeaturesById>
                            <!-- optional, set true to get a final report with latest results of the same test from different test runs -->
                            <mergeFeaturesWithRetest>false</mergeFeaturesWithRetest>
                            <!-- optional, set true to fail build on test failures -->
                            <checkBuildResult>false</checkBuildResult>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
 
 
</project>

It says that in given directory it could not find any JSON file that is a cucumber report

i got this same error "net.masterthought.cucumber.ValidationException: No JSON report file was found"

@damianszczepanik if you can please answer these 5 simple questions i have tried solution from stackoverflow but they dont work ?

Question 1) which file path is required ?
Question 2) Where it has to be mentioned ?

Question 3) is it cucumber.json which is there in cucumber-html-reports folder which has content like this

[ { "line": 1, "elements": [ { "start_timestamp": "2023-05-03T12:32:09.543Z", "before": [ { "result": { "duration": 5683003700, "status": "passed" }, "match": { "location": "stepDefinitions.Hooks.setup(io.cucumber.java.Scenario)" } } ],

or is it the json.json file which is generated by the plugin and looks like belwo
[{ "useNaturalConf": true, "startTime": "May 2, 2023, 2:48:19 PM", "endTime": "May 2, 2023, 2:49:09 PM", "status": "FAIL", "level": 0, "isLeaf": false,

Question 4) Does it need to be mentioned like below

<outputDirectory>${project.build.directory}/../../outputfolder</outputDirectory> <inputDirectory>${project.build.directory}/../../outputfolder/cucumber-html-reports</inputDirectory> <jsonFiles> <param>${project.build.directory}/../../outputfolder/**/*.json</param> </jsonFiles>

Question 5) Do you see any mistake in this ? can we use ** in the path

ok, is there a way to add screenshot to this html report ?
I have sth like this

@after
public void afterTest(Scenario scenario) throws IOException {
if (!scenario.isFailed()) {
final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, "image/png", scenario.getName());
}
}

ok, is there a way to add screenshot to this html report ? I have sth like this

@after public void afterTest(Scenario scenario) throws IOException { if (!scenario.isFailed()) { final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); scenario.attach(screenshot, "image/png", scenario.getName()); } }

you can add the below in properties file to see it embedded, better to ask this as separate question

extent.reporter.spark.base64imagesrc=true

There is sample configuration in README file. Suggest to start from that point.

There is sample configuration in README file. Suggest to start from that point.

@damianszczepanik can you please reply to my 5 question above, as i got the similar error

I started from README and have some specific questions, if you can answer may be then i can add clarification for them in README as well.

@SeleniumNinja How did you solve the original problem?