Issue in executing step definition using ExtendedCucumber from com.github.mkolisnyk library - java

The moment I am adding extended cucumber dependency, the step definition is not executing, when I remove the extended cucumber dependency it works fine and execute step definitions.
Below is the Maven dependency which I am using.
<dependency>
<groupId>com.github.mkolisnyk</groupId>
<artifactId>cucumber-reports</artifactId>
<version>1.0.5</version>
</dependency>
/* This part of the code does not execute Step definitions*/
import org.junit.runner.RunWith;
import com.github.mkolisnyk.cucumber.runner.ExtendedCucumber;
import com.github.mkolisnyk.cucumber.runner.ExtendedCucumberOptions;
import cucumber.api.CucumberOptions;
#RunWith(ExtendedCucumber.class)
#ExtendedCucumberOptions(jsonReport = "target/cucumber.json",
overviewReport = true,
outputFolder = "target")
#CucumberOptions(features = {"./src/test/resources/features"}, plugin = { "html:target/cucumber-html-report",
"json:target/cucumber.json", "pretty:target/cucumber-pretty.txt",
"usage:target/cucumber-usage.json", "junit:target/cucumber-results.xml" },
glue = { "com/test/stepdefinition" },
monochrome = true)
public class RunCucumberTest {
}
/* This is working fine and executing step defnitions*/
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features = { "./src/test/resources/features" }, plugin = { "html:target/cucumber-html-report",
"json:target/cucumber.json", "pretty:target/cucumber-pretty.txt", "usage:target/cucumber-usage.json",
"junit:target/cucumber-results.xml" }, glue = {
"com/test/stepdefinition" }, monochrome = true)
public class RunCucumberTest {
}
I am not sure why this is happening, am I missing something here?

Update the all cucumber dependency to 1.2.5 then it will work

Related

Cucumber TestNG Gradle Parallel Execution ThreadCount

I am trying to run my Cucumber scenarios in parallel using the TestNG.
But when I run it 'parallel=true' it executes the test cases in thread count=10 (testng default).
I want to customise the thread count to say 2 or 3. How do I do that.?
I want to run this through IntelliJ as well as through the command line (terminal)
Tried using the 'jvmArgs(["-Ddataproviderthreadcount=2"])'
CucumberTestNGRunner
import io.cucumber.junit.Cucumber;
import io.cucumber.testng.CucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.runner.RunWith;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.DataProvider;
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"path/to/features"},
glue = {"path.to.stepdep.package"},
plugin = {"pretty"},
tags = "#smoke",
dryRun = false,
monochrome = true
)
public class CucumberTestNGRunner extends AbstractTestNGCucumberTests {
#Override
#DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
build.gradle (snippet) :
test {
useTestNG()
//jvmArgs(["-Ddataproviderthreadcount=2"])
scanForTestClasses = false
testLogging.showStandardStreams = true
systemProperties = System.properties
}

How to call a cucumberTestRunner?

How do I call my cucumberTestRunner from another class (cucumberTestMaster) and get it to run? Currently, it just seems to skip the tests. Below is what I have tried. I am limited by JUnit 4.8 for project reasons, and both files are written in Groovy.
//cucumberTestMaster
package cucumber
import cucumber.testRunners.CucumberTestRunner
import org.junit.runner.JUnitCore
import org.junit.runner.Result
class CucumberTestMaster {
try {
Class runner = CucumberTestRunner as Class
Result result = JUnitCore.runClasses(runner.class)
}
catch (Exception e)
{
println(e)
}
}
//cucumberTestRunner
package cucumber.testRunners
import io.cucumber.junit.Cucumber
import io.cucumber.junit.CucumberOptions
import org.junit.runner.RunWith
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/main/groovy/cucumber/features/addDeal/",
glue = "cucumber.stepDefinitions",
publish = false,
monochrome = true,
tags = "#Daily",
plugin = ["pretty", "junit:target/JUNITReports/report.xml", "html:target/HTMLReports/report.html",
"json:target/JSONReports/report.json"]
)
class CucumberTestRunner {
}
Thank you in advance for any help.

How do I show scenario name instead of feature name in Cucumber html report

By default cucumber report shows feature names.
Since I have several scenarios within 1 feature file,
I want to display scenario name instead of feature name.
To make the report more verbose
My Cucumber options are:
cucumberOptions = #CucumberOptions(
features = "src/test/resources/features",
monochrome = true,
glue = "stepDefinitions",
tags = {"not #disable"},
plugin = {
"pretty",
"json:build/cucumber-report/cucumber.json",
"html:build/cucumber-report/cucumber.html"},
strict = true
)
My report is showing scenario information also . I am using courgette-jvm with testNG here is my setup
package com.test;
import courgette.api.CourgetteOptions;
import courgette.api.CourgetteRunLevel;
import courgette.api.CucumberOptions;
import courgette.api.testng.TestNGCourgette;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
#Test
#CourgetteOptions(
threads = 10,
runLevel = CourgetteRunLevel.SCENARIO,
rerunFailedScenarios = true,
rerunAttempts = 1,
showTestOutput = true,
reportTitle = "Courgette-JVM Example",
reportTargetDir = "build",
environmentInfo = "browser=chrome; git_branch=master",
cucumberOptions = #CucumberOptions(
features = "src/test/resources/com/test/",
glue = "com.test.stepdefs",
//tags = {"#post or #get"},
publish = true,
plugin = {
"pretty",
"json:target/cucumber-report/cucumber.json",
"html:target/cucumber-report/cucumber.html"}
))
class AcceptanceIT extends TestNGCourgette {
}
package com.test;

I am trying use tag in my Cucumber runner but doesn't work. I am new to Cucumber

Please see the screenshotI am trying to run my cucumber runner with cucumber options and trying to use tags, but it doesn't work.
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
dryRun = false,
strict = true,
monochrome = true,
features = {"src/test/resources/"},
glue = {"com.learning"},
plugin = {"pretty",
"html:target/site/cucumber-html",
"json:target/cucumber1.json"},
tags = {"#BookingFlight"}
)
public class MyRunner {
}
Error is: java: annotation value not of an allowable type[enter image description here][1]
[1]: https://i.stack.imgur.com/P6OuL.png
You have to remove the curly brackets in tags attribute:
#RunWith(Cucumber.class)
#CucumberOptions(
dryRun = false,
strict = true,
monochrome = true,
features = {"src/test/resources/"},
glue = {"com.learning"},
plugin = {"pretty",
"html:target/site/cucumber-html",
"json:target/cucumber1.json"},
tags = "#BookingFlight"
)
public class MyRunner {
}
You can specify more than one tag in a single string, i.e.: "#BookingFlight or #BookingGeneral"

How to solve maven COMPILATION ERROR: package X does not exist? [duplicate]

This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 6 years ago.
I have 3 maven projects:
project-A
project-B
project-C
The second project (B) requires the dependency for the first project (A).
The third project (C) requires the dependencies for the first and second project (A, B).
I have defined these dependencies in the respective projects pom files:
project-B pom.xml :
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-A</artifactId>
<version>${project.version}</version>
</dependency>
project-C pom.xml :
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-A</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-B</artifactId>
<version>${project.version}</version>
</dependency>
Everything works OK on SpringToolSuite. I have tested the second project (which depends on the first project) and also tested the third project (which depends on both first and second project) and everything works OK from STS.
When I try to execute:
mvn clean install -U -DskipTests=true
it works perfectly well for project-A and project-B, but for project-C I get a:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] MyClassOnProjectC.java:[12,38] package XXX does not exist
[ERROR] MyClassOnProjectC.java:[22,17] cannot find symbol
symbol: class MyClassOnProjectB
location: class MyClassOnProjectC
Below there are 3 classes extracted from each of the projects:
Project-A:
User.java
package com.neweraed.datamodel;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "UserType", propOrder = {
"name",
"description",
})
public class User implements Serializable {
private static final long serialVersionUID = -876063526825526098L;
private String name;
private String description;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Project-B:
UserOperations.java
package com.neweraed.services.midpoint;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestOperations;
import com.neweraed.datamodel.User;
import com.neweraed.services.midpoint.utils.Constants;
import com.neweraed.services.midpoint.utils.Utils;
#Component
public class UserOperations {
private static final Logger logger = LoggerFactory.getLogger(UserOperations.class);
public User getUser(User user) {
RestOperations restOperations = Utils.createGenericRestTemplate();
ResponseEntity<User> response = null;
try {
response = restOperations.exchange(Constants.ENDPOIT_SEARCH_USER, HttpMethod.GET, new HttpEntity<Object>(Utils.createHeaders()), User.class);
logger.info("=== RESPONSE ===" + response + " === ");
} catch (Exception e) {
logger.error("=== ERROR === " + e.getMessage() + " === ");
}
return user;
}
}
Project-C:
UserService.java
package com.neweraed.rest;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.neweraed.datamodel.User;
import com.neweraed.services.midpoint.UserOperations;
#RestController
#RequestMapping(value="/api/v1/users")
public class UserService {
#RequestMapping(value="/", method=RequestMethod.POST)
public User addUser(#RequestBody User user) {
UserOperations userOperations = new UserOperations();
return userOperations.addUser(user);
}
}
It seems like everything is OK on my pom.xml files. How can I solve this?
According to your premises, pom.xml of the project B must be:
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-A</artifactId>
<version>${project.version}</version>
</dependency>
And project C doesn't need the dependency with A because it is defined on B

Categories