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.



Extent Report



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?










share|improve this question


















  • 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















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.



Extent Report



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?










share|improve this question


















  • 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













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.



Extent Report



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?










share|improve this question













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.



Extent Report



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?