Cucumber TestNG Gradle Parallel Execution ThreadCount - java

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
}

Related

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"

Cucable plugin: How can I avoid running the '[CUCABLE:FEATURE].feature' (java template file)?

Following is my cucumber template java file.
package some.template;
import cucumber.api.CucumberOptions;
//import cucumber.api.junit.Cucumber;
import cucumber.api.testng.CucumberFeatureWrapper;
import cucumber.api.testng.PickleEventWrapper;
import cucumber.api.testng.TestNGCucumberRunner;
//import org.junit.runner.RunWith;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
//#RunWith(Cucumber.class)
#CucumberOptions(
glue = "com.fifa.stepdefs",
features = {"target/parallel/features/[CUCABLE:FEATURE].feature"},
plugin = {"json:target/cucumber-report/[CUCABLE:RUNNER].json"}
)
public class CucableJavaTemplate implements IRetryAnalyzer {
private int count = 0;
private static int maxTry = 3;
#Override
public boolean retry(ITestResult iTestResult) {
if (!iTestResult.isSuccess()) { ;//Check if test not succeed
if (count < maxTry) { //Check if maxtry count is reached
count++; //Increase the maxTry count by 1
iTestResult.setStatus(ITestResult.FAILURE); //Mark test as failed
return true; //Tells TestNG to re-run the test
} else {
iTestResult.setStatus(ITestResult.FAILURE); //If maxCount reached,test marked as failed
}
} else {
iTestResult.setStatus(ITestResult.SUCCESS); //If test passes, TestNG marks it as passed
}
return false;
}
private TestNGCucumberRunner testNGCucumberRunner;
#BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
System.out.println("Before Scenario ****");
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}
#Test(groups = "cucumber", description = "Runs Cucumber Scenarios", dataProvider = "scenarios",retryAnalyzer = CucableJavaTemplate.class)
public void scenario(PickleEventWrapper pickleEvent, CucumberFeatureWrapper cucumberFeature) throws Throwable {
testNGCucumberRunner.runScenario(pickleEvent.getPickleEvent());
}
#DataProvider
public Object[][] scenarios() {
return testNGCucumberRunner.provideScenarios();
}
#AfterClass(alwaysRun = true)
public void tearDownClass() throws Exception {
System.out.println("After Scenario ****");
testNGCucumberRunner.finish();
}
}
When I run mvn clean verify, the following happens:
Scenario in feature files are broken into multiple scenarios and
individual runners are generated
Tests are run. But before the actual tests are run, cucumber-testng also tries to run '[CUCABLE:FEATURE].feature' and fails with error:
[Utils] [ERROR] [Error] java.lang.IllegalArgumentException: Not a file or directory: /projectpath/target/parallel/features/[CUCABLE:FEATURE].feature
How can I avoid running the '[CUCABLE:FEATURE].feature'?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
I think I figured this out. Added the above plugin and those tests are now skipped.

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

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

Categories