cucumber.json file does not generating - maven

I am trying to execute a cucumber selenium setup.
pom.xml is like.
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>execution</id>
<phase>test</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>ExecuteAutomation</projectName>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
</configuration>
</execution>
</executions>
</plugin>
and cucumber jvm is
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.8.0</version>
</dependency>
whenever I verify the build by maven it always shows cucumber.json does not exist.
which suppose to be auto generated.
runner file is
#CucumberOptions(features = { "src/test/features/Login.feature" },monochrome = false,
plugin = {"json:target/cucumber.json","html:target/site/cucumber-pretty"},
glue = { "steps" })

Okay! I back track the problem
first I comment maven-cucumber-reporting plugin section and try to execute through testng. there was a warning which need to resolve by -Dtestng.dtd.http=true.
and then it works!
Thanks!

Related

maven-cucumber-reporting plugin is not generating the report - nothing happens

when adding the following plugin into my pom.xml, a report should be generated in my target folder, but nothing is generated. my project just runs and finishes without any report. Can someone look over this for any errors?
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>2.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>CucumberWebGui</projectName>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
</configuration>
</execution>
</executions>
</plugin>
As you didn't show all configuration, I guess you might miss the plugin configuration in the Runner class. Find below a working project.
assume following structure
pom.xml
src/test/java/TestRunner.java
src/test/java/stepdefs/StepDefinitions.java
src/test/resource/features/demo.feature
pom.xml
<?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.suboptimal</groupId>
<artifactId>cuke-test.so</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>2.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>CucumberWebGui</projectName>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
TestRunner.java
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"src/test/resource/features"},
glue = {"stepdefs"},
plugin = {"json:target/cucumber.json"})
public class TestRunner {
}
StepDefinitions.java
package stepdefs;
import org.junit.Assert;
import cucumber.api.java.en.Given;
public class StepDefinitions {
#Given("^a successful step$")
public void aSuccessfulStep() throws Throwable {
System.out.println("a successful step");
}
#Given("^a not successful step$")
public void aNotSuccessfulStep() throws Throwable {
System.out.println("a not successful step");
Assert.fail();
}
}
demo.feature
Feature: Test cucumber reporting plugin
Scenario: Run a non failing scenario
Given a successful step
Scenario: Run a failing scenario
Given a not successful step
running mvn clean test will generate the Cucumber report file
target/cucumber.json
running mvn verify -DskipTests will generate the cucumber-report-html based on the cucumber.json
target/cucumber-report-html/cucumber-html-reports/src-test-resource-features-demo-feature.html
target/cucumber-report-html/cucumber-html-reports/...
running mvn clean verify will do all together
Please try to use the below code snippet.Just give the path of json file in the tag. In my case it is inside the target folder, so I used the below code and it working for me. Hope this helps!
<configuration>
<projectName>ExecutionResult</projectName>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<inputDirectory>${project.build.directory}</inputDirectory>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
</configuration>
For integration test if you are using maven failsafe plugin, make sure that you have passed the environment variables inside the configuration of failsafe configuration because failsafe not pick any values from property-files like , junit-platform.properties, sample configuration is failsafe configuration follows
failsafe
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<environmentHost>localhost</environmentHost>
<environmentPort>8082</environmentPort>
<!--IMPORTANT : failsafe plugin will not read any property files -->
<!-- It will ignore the values from junit-platform.properties, so you have to provide it-->
<spring.profiles.active>docker-integration-tests</spring.profiles.active>
<cucumber.filter.tags>#regression</cucumber.filter.tags>
<cucumber.plugin>html:target/jsonReports/cucumber-report.html, json:target/jsonReports/cucumber.json, junit:target/jsonReports/cucumber.xml, pretty</cucumber.plugin>
</systemPropertyVariables>
<parallel>none</parallel>
<classesDirectory>${project.build.testOutputDirectory}</classesDirectory>
<classpathDependencyExcludes>
<classpathDependencyExcludes>${project.groupId}:${project.artifactId}</classpathDependencyExcludes>
</classpathDependencyExcludes>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.outputDirectory}
</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>post-integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
Assumes all your unit test class ends with *Test.java
and Integration Test runs with *IT.java and you are using cucumber for integration test ( i have not used surefire with cucumber report plugin so no idea it will work or not with the following conf.
Also in the feature file give the annotation #regression as 1st line for the cucumber to identify test during execution. Example follows
#regression
Feature: Wiremock the your controller for Integration test
now the cucumber report plugin from :
net.masterthought
plugin version : 5.4.0
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>${maven-cucumber-reporting.version}</version>
<executions>
<execution>
<id>execution-dwp-employment-income-api</id>
<goals>
<goal>generate</goal>
</goals>
<!-- report generation is happening at this phase, so please dont change-->
<phase>integration-test</phase>
<configuration>
<projectName>${project.name}</projectName>
<skip>false</skip>
<!-- output directory for the generated report -->
<outputDirectory>${project.build.directory}/jsonReports/reports</outputDirectory>
<!-- optional, defaults to outputDirectory if not specified -->
<inputDirectory>${project.build.directory}/jsonReports</inputDirectory>
<jsonFiles>
<!-- supports wildcard or name pattern -->
<param>**/*.json</param>
</jsonFiles>
<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>
now use mvn post-integration-test or mvn verify to generate the report. this is for integration test.

Maven Plugin conflict

What all i want to do is run test in phase integration-test and then generate report.
by mvn verify
But only test are executed report never runs. When i comment first plugin then other is executed. Any idea how to fix it?
I have below in my pom
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<executableDependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
</executableDependency>
<mainClass>cucumber.api.cli.Main</mainClass>
<arguments>
<argument>target/test-classes/feature</argument>
<agrument>--glue</agrument>
<argument>integration</argument>
<argument>src\test\java</argument>
<argument>--plugin</argument>
<argument>pretty</argument>
<argument>--plugin</argument>
<argument>html:target/cucumber-report</argument>
<argument>--plugin</argument>
<argument>json:target/cucumber-report/cucumber.json</argument>
<argument>--tags</argument>
<argument>~#ignore</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>poc.selenium.it</projectName>
<outputDirectory>target/cucumber-report</outputDirectory>
<cucumberOutput>target/cucumber-report/cucumber.json</cucumberOutput>
<enableFlashCharts>true</enableFlashCharts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The problem is due to the fact that cucumber.api.cli.Main calls System.exit and therefore terminates the Maven process before the other plugin gets to be executed.
One way to fix the problem would be to use the exec goal of the exec-maven-plugin, rather than the java goal, as it runs in a separate process.
However, a better (and easier) solution is to define a JUnit test that will configure and run your cucumber tests, for example:
package integration;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(plugin = "json:target/cucumber-report/cucumber.json")
public class RunTest {
}
You can then use either the maven-surefire-plugin or the maven-failsafe-plugin plugin to execute that test. The maven-cucumber-reporting plugin will then execute successfully and create the report.
You can see this in action on a github branch I have just pushed.

Use dependency command line parameters with maven build

I am using findbugs-maven-plugin in the verify phase of the maven life cycle. i.e. it runs on mvn clean install. This is the code I have in my parent pom.xml (in a multi-module project).
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>findbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<findbugsXmlOutputDirectory>target/findbugs</findbugsXmlOutputDirectory>
<failOnError>false</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>target/findbugs</dir>
<outputDir>target/findbugs</outputDir>
<stylesheet>plain.xsl</stylesheet>
<fileMappers>
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</plugin>
This is working fine and html files are being generated in each module target. However I want to take this a step further by being able to use parameters allowed by findbugs during the maven build (for example onlyAnalyze). I do not want to add configuration in the pom.xml.
I want the build process to remain the same unless I specify by some command that I want to analyze only one class, for example by running:
mvn clean install -Dfindbugs:onlyAnalyze=MyClass
Do you know of a way I can do this?
This is how you can call a standalone goal:
plugin-prefix:goal or groupId:artifactId:version:goal to ensure the right version.
In your case: findbugs:findbugs
With -Dkey=value you can set plugin parameters if they are exposed. http://mojo.codehaus.org/findbugs-maven-plugin/findbugs-mojo.html doesn't show that option. Just to compare: http://mojo.codehaus.org/findbugs-maven-plugin/help-mojo.html does have such options. Here it is still called Expression with ${key}, nowadays it's generated as User property with just key.
If you want onlyAnalyze to be set from commandline, either ask the mojo-team to fix that, or do the following:
<project>
<properties>
<findbugs.onlyAnalyze>false</findbugs.onlyAnalyze> <!-- default value -->
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<configuration>
<onlyAnalyze>${findbugs.onlyAnalyze}</onlyAnalyze>
</configuration>
</plugins>
</build>
</project>
Now you can call mvn findbugs:findbugs -Dfindbugs.onlyAnalyze=true

Using fmpp in gradle to generate java files

I have an existing maven project which I am attempting to port to gradle.
One sub module uses fmpp/freemarker to generate a whole lot of java files which are then fed back into the build.
I'm new to gradle, and was wondering if anyone knows of an easy way to do this.
Any help would be appreciated.
My current pom.xml looks like this:
<build>
<plugins>
<!-- Freemarker maven plugin for code generation -->
<plugin>
<groupId>com.googlecode.fmpp-maven-plugin</groupId>
<artifactId>fmpp-maven-plugin</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.unix4j</groupId>
<artifactId>unix4j-tools</artifactId>
<version>0.1-SNAPSHOT</version>
<optional>true</optional>
</dependency>
</dependencies>
<configuration>
<cfgFile>src/main/resources/codegen/config.fmpp</cfgFile>
<outputDirectory>target/generated-sources/main/java</outputDirectory>
<templateDirectory>src/main/resources/codegen/templates</templateDirectory>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/generated</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Sorry, should have spent more time googling first. This is the solution which worked for me:
project(':unix4j-core:unix4j-command') {
configurations {pmd}
dependencies {
compile project(':unix4j-core:unix4j-base')
compile project(':unix4j-tools')
pmd project(':unix4j-tools')
}
task generateFmppSources(dependsOn: ":unix4j-tools:compileJava") << {
println "Generating sources...."
ant.taskdef(name:'fmpp', classname:'fmpp.tools.AntTask', classpath:configurations.pmd.asPath);
ant.fmpp configuration:"src/main/resources/codegen/config.fmpp", sourceRoot:"src/main/resources/codegen/templates", outputRoot:"target/generated-sources/main/java";
}
compileJava.dependsOn generateFmppSources
sourceSets {
main {
java {
srcDir 'target/generated-sources/main/java'
}
}
}
}

maven-failsafe-plugin not seeing my tests (seleniumHQ)

i'm writing tests via selenium web driver here's my code :
Pom.xml
<project>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.24.1</version>
</dependency>
</dependencies>
<build>
<finalName>SeleniumebDriverProject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.11</version>
<configuration>
<!-- Skip the normal tests, we'll run them in the integration-test phase-->
<skip>false</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My test class named GoogleTest.java.
after reading this post : failsafe plugin won't run on one project but will run on another -- why?
I changed the name of my class so it's:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.11</version>
<configuration>
<!-- Skip the normal tests, we'll run them in the integration-test phase-->
<skip>false</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
<executions>
</plugin>
But the problem persist.
The goal of the maven-failsafe-plugin is named integration-test instead of test. Furthermore if you changed your naming convention to the convention of maven-failsafe-plugin than you don't need any configuration which includes etc. files. Just use the defaults.
Furthermore i assume you have started running the integration tests via:
mvn verify

Resources