Create a TestNG runner class for each running thread using Cucumber
up vote
1
down vote
favorite
I'm writing a framework that uses TestNG and Appium in order to conduct mobile app tests in parallel. Right now i'm trying to implement Cucumber into the framework, which requires a TestNG runner class in order to run the Cucumber tests (see below).
package org.cucumber.tests;
@CucumberOptions(
features="src/test/resources/features",
glue={"org.cucumber.stepdefs"},
plugin = {
"com.cucumber.listener.ExtentCucumberFormatter:" }, monochrome = true)
public class TestNGRunner extends BaseTest {
private static TestNGCucumberRunner testRunner;
@BeforeClass
public void setUP() {
testRunner = new TestNGCucumberRunner(TestNGRunner.class);
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setReportPath("output/" + this.hashCode() + "-report.html");
}
@Test(description="Tests",dataProvider="features")
public void setUpClass(CucumberFeatureWrapper cFeature) {
testRunner.runCucumber(cFeature.getCucumberFeature());
}
@DataProvider(name="features")
public Object getFeatures() {
return testRunner.provideFeatures();
}
@AfterClass
public static void teardown() {
testRunner.finish();
}
}
I have my tests running in parallel on each connected mobile device using ThreadLocal AppiumDriver (WebDriver) instances and specifying parameters in my testNG.xml file within <test>
tags and setting the parallelism to 'tests', example:-
<suite name="Parallel Testing" verbose="1" parallel="tests">
<test name="Samsung Galaxy S7">
<parameter name="platform" value="Android 6.0.1" />
<parameter name="udid" value="#############" />
<parameter name="browserName" value="Chrome" />
<parameter name="chromeDriverPort" value="9515" />
<parameter name="systemPort" value="8201" />
<parameter name="deviceName" value="Samsung Galaxy S7" />
<packages>
<package name="org.cucumber.tests"/>
</packages>
</test>
<test name="Nexus 6P">
<parameter name="platform" value="Android 7.1.1" />
<parameter name="udid" value="########" />
<parameter name="browserName" value="Chrome" />
<parameter name="chromeDriverPort" value="9516" />
<parameter name="systemPort" value="8202" />
<parameter name="deviceName" value="Nexus 6P" />
<packages>
<package name="org.cucumber.tests"/>
</packages>
When it comes to generating a report using ExtentReports, all the tests from every running thread are placed into the same report - see below example.
My understanding of this is that the ExtentProperties.INSTANCE
is shared between each of the running threads, so the file path is always overridden.
What i would like is an indiviual report for each running thread, which results in a report for each connected mobile device.
Presumably what i need to do is create a separate instance of the TestNGRunner class for each running thread. My question is - is this actually possible and if so, do i need to change my approach?
java cucumber testng extentreports
add a comment |
up vote
1
down vote
favorite
I'm writing a framework that uses TestNG and Appium in order to conduct mobile app tests in parallel. Right now i'm trying to implement Cucumber into the framework, which requires a TestNG runner class in order to run the Cucumber tests (see below).
package org.cucumber.tests;
@CucumberOptions(
features="src/test/resources/features",
glue={"org.cucumber.stepdefs"},
plugin = {
"com.cucumber.listener.ExtentCucumberFormatter:" }, monochrome = true)
public class TestNGRunner extends BaseTest {
private static TestNGCucumberRunner testRunner;
@BeforeClass
public void setUP() {
testRunner = new TestNGCucumberRunner(TestNGRunner.class);
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setReportPath("output/" + this.hashCode() + "-report.html");
}
@Test(description="Tests",dataProvider="features")
public void setUpClass(CucumberFeatureWrapper cFeature) {
testRunner.runCucumber(cFeature.getCucumberFeature());
}
@DataProvider(name="features")
public Object getFeatures() {
return testRunner.provideFeatures();
}
@AfterClass
public static void teardown() {
testRunner.finish();
}
}
I have my tests running in parallel on each connected mobile device using ThreadLocal AppiumDriver (WebDriver) instances and specifying parameters in my testNG.xml file within <test>
tags and setting the parallelism to 'tests', example:-
<suite name="Parallel Testing" verbose="1" parallel="tests">
<test name="Samsung Galaxy S7">
<parameter name="platform" value="Android 6.0.1" />
<parameter name="udid" value="#############" />
<parameter name="browserName" value="Chrome" />
<parameter name="chromeDriverPort" value="9515" />
<parameter name="systemPort" value="8201" />
<parameter name="deviceName" value="Samsung Galaxy S7" />
<packages>
<package name="org.cucumber.tests"/>
</packages>
</test>
<test name="Nexus 6P">
<parameter name="platform" value="Android 7.1.1" />
<parameter name="udid" value="########" />
<parameter name="browserName" value="Chrome" />
<parameter name="chromeDriverPort" value="9516" />
<parameter name="systemPort" value="8202" />
<parameter name="deviceName" value="Nexus 6P" />
<packages>
<package name="org.cucumber.tests"/>
</packages>
When it comes to generating a report using ExtentReports, all the tests from every running thread are placed into the same report - see below example.
My understanding of this is that the ExtentProperties.INSTANCE
is shared between each of the running threads, so the file path is always overridden.
What i would like is an indiviual report for each running thread, which results in a report for each connected mobile device.
Presumably what i need to do is create a separate instance of the TestNGRunner class for each running thread. My question is - is this actually possible and if so, do i need to change my approach?
java cucumber testng extentreports
1
If you are using Vimal's ExtentCucumberFormatter - then the INSTANCE variable is a singleton which will be the same for all threads.. You would probably need to fork the project and create a custom implementation that gives you an individual report per device. However, as devices increase, it will be difficult to read through all reports. I suggest marking tests with tags instead.
– foursyth
Nov 14 at 13:52
Thanks, foursyth!
– BIGJOHN
Nov 15 at 8:25
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm writing a framework that uses TestNG and Appium in order to conduct mobile app tests in parallel. Right now i'm trying to implement Cucumber into the framework, which requires a TestNG runner class in order to run the Cucumber tests (see below).
package org.cucumber.tests;
@CucumberOptions(
features="src/test/resources/features",
glue={"org.cucumber.stepdefs"},
plugin = {
"com.cucumber.listener.ExtentCucumberFormatter:" }, monochrome = true)
public class TestNGRunner extends BaseTest {
private static TestNGCucumberRunner testRunner;
@BeforeClass
public void setUP() {
testRunner = new TestNGCucumberRunner(TestNGRunner.class);
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setReportPath("output/" + this.hashCode() + "-report.html");
}
@Test(description="Tests",dataProvider="features")
public void setUpClass(CucumberFeatureWrapper cFeature) {
testRunner.runCucumber(cFeature.getCucumberFeature());
}
@DataProvider(name="features")
public Object getFeatures() {
return testRunner.provideFeatures();
}
@AfterClass
public static void teardown() {
testRunner.finish();
}
}
I have my tests running in parallel on each connected mobile device using ThreadLocal AppiumDriver (WebDriver) instances and specifying parameters in my testNG.xml file within <test>
tags and setting the parallelism to 'tests', example:-
<suite name="Parallel Testing" verbose="1" parallel="tests">
<test name="Samsung Galaxy S7">
<parameter name="platform" value="Android 6.0.1" />
<parameter name="udid" value="#############" />
<parameter name="browserName" value="Chrome" />
<parameter name="chromeDriverPort" value="9515" />
<parameter name="systemPort" value="8201" />
<parameter name="deviceName" value="Samsung Galaxy S7" />
<packages>
<package name="org.cucumber.tests"/>
</packages>
</test>
<test name="Nexus 6P">
<parameter name="platform" value="Android 7.1.1" />
<parameter name="udid" value="########" />
<parameter name="browserName" value="Chrome" />
<parameter name="chromeDriverPort" value="9516" />
<parameter name="systemPort" value="8202" />
<parameter name="deviceName" value="Nexus 6P" />
<packages>
<package name="org.cucumber.tests"/>
</packages>
When it comes to generating a report using ExtentReports, all the tests from every running thread are placed into the same report - see below example.
My understanding of this is that the ExtentProperties.INSTANCE
is shared between each of the running threads, so the file path is always overridden.
What i would like is an indiviual report for each running thread, which results in a report for each connected mobile device.
Presumably what i need to do is create a separate instance of the TestNGRunner class for each running thread. My question is - is this actually possible and if so, do i need to change my approach?
java cucumber testng extentreports
I'm writing a framework that uses TestNG and Appium in order to conduct mobile app tests in parallel. Right now i'm trying to implement Cucumber into the framework, which requires a TestNG runner class in order to run the Cucumber tests (see below).
package org.cucumber.tests;
@CucumberOptions(
features="src/test/resources/features",
glue={"org.cucumber.stepdefs"},
plugin = {
"com.cucumber.listener.ExtentCucumberFormatter:" }, monochrome = true)
public class TestNGRunner extends BaseTest {
private static TestNGCucumberRunner testRunner;
@BeforeClass
public void setUP() {
testRunner = new TestNGCucumberRunner(TestNGRunner.class);
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setReportPath("output/" + this.hashCode() + "-report.html");
}
@Test(description="Tests",dataProvider="features")
public void setUpClass(CucumberFeatureWrapper cFeature) {
testRunner.runCucumber(cFeature.getCucumberFeature());
}
@DataProvider(name="features")
public Object getFeatures() {
return testRunner.provideFeatures();
}
@AfterClass
public static void teardown() {
testRunner.finish();
}
}
I have my tests running in parallel on each connected mobile device using ThreadLocal AppiumDriver (WebDriver) instances and specifying parameters in my testNG.xml file within <test>
tags and setting the parallelism to 'tests', example:-
<suite name="Parallel Testing" verbose="1" parallel="tests">
<test name="Samsung Galaxy S7">
<parameter name="platform" value="Android 6.0.1" />
<parameter name="udid" value="#############" />
<parameter name="browserName" value="Chrome" />
<parameter name="chromeDriverPort" value="9515" />
<parameter name="systemPort" value="8201" />
<parameter name="deviceName" value="Samsung Galaxy S7" />
<packages>
<package name="org.cucumber.tests"/>
</packages>
</test>
<test name="Nexus 6P">
<parameter name="platform" value="Android 7.1.1" />
<parameter name="udid" value="########" />
<parameter name="browserName" value="Chrome" />
<parameter name="chromeDriverPort" value="9516" />
<parameter name="systemPort" value="8202" />
<parameter name="deviceName" value="Nexus 6P" />
<packages>
<package name="org.cucumber.tests"/>
</packages>
When it comes to generating a report using ExtentReports, all the tests from every running thread are placed into the same report - see below example.
My understanding of this is that the ExtentProperties.INSTANCE
is shared between each of the running threads, so the file path is always overridden.
What i would like is an indiviual report for each running thread, which results in a report for each connected mobile device.
Presumably what i need to do is create a separate instance of the TestNGRunner class for each running thread. My question is - is this actually possible and if so, do i need to change my approach?
java cucumber testng extentreports
java cucumber testng extentreports
asked Nov 14 at 12:11
BIGJOHN
14410
14410
1
If you are using Vimal's ExtentCucumberFormatter - then the INSTANCE variable is a singleton which will be the same for all threads.. You would probably need to fork the project and create a custom implementation that gives you an individual report per device. However, as devices increase, it will be difficult to read through all reports. I suggest marking tests with tags instead.
– foursyth
Nov 14 at 13:52
Thanks, foursyth!
– BIGJOHN
Nov 15 at 8:25
add a comment |
1
If you are using Vimal's ExtentCucumberFormatter - then the INSTANCE variable is a singleton which will be the same for all threads.. You would probably need to fork the project and create a custom implementation that gives you an individual report per device. However, as devices increase, it will be difficult to read through all reports. I suggest marking tests with tags instead.
– foursyth
Nov 14 at 13:52
Thanks, foursyth!
– BIGJOHN
Nov 15 at 8:25
1
1
If you are using Vimal's ExtentCucumberFormatter - then the INSTANCE variable is a singleton which will be the same for all threads.. You would probably need to fork the project and create a custom implementation that gives you an individual report per device. However, as devices increase, it will be difficult to read through all reports. I suggest marking tests with tags instead.
– foursyth
Nov 14 at 13:52
If you are using Vimal's ExtentCucumberFormatter - then the INSTANCE variable is a singleton which will be the same for all threads.. You would probably need to fork the project and create a custom implementation that gives you an individual report per device. However, as devices increase, it will be difficult to read through all reports. I suggest marking tests with tags instead.
– foursyth
Nov 14 at 13:52
Thanks, foursyth!
– BIGJOHN
Nov 15 at 8:25
Thanks, foursyth!
– BIGJOHN
Nov 15 at 8:25
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299947%2fcreate-a-testng-runner-class-for-each-running-thread-using-cucumber%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If you are using Vimal's ExtentCucumberFormatter - then the INSTANCE variable is a singleton which will be the same for all threads.. You would probably need to fork the project and create a custom implementation that gives you an individual report per device. However, as devices increase, it will be difficult to read through all reports. I suggest marking tests with tags instead.
– foursyth
Nov 14 at 13:52
Thanks, foursyth!
– BIGJOHN
Nov 15 at 8:25