Run testng methods across different tests in parallel - maven

I have more than one test tags in my testng.xml file that I am running using maven. I have set the parallel attribute at the suite level to methods and the thread-count as 5. The problem I am facing is that the tests are executed sequentially and only the methods inside the test cases are executed in parallel. To be more clear, though there are unused threads(Selenium nodes in the grid in my case) available the subsequent tests waits till all the methods in the previous test are executed.
Here is the testng.xml that i have used,
<suite name="Suite1" verbose="1" parallel="methods" thread-count="5" preserve-order="false">
<test name="Login" >
<classes>
<class name="testSuite.TestSet1" />
</classes>
</test>
<test name="Product Search">
<classes>
<class name="testSuite.TestSet2"/>
</classes>
</test>
</suite>
As I have more than 10 nodes available in my selenium grid, this behavior increases the execution time considerably and defeats the purpose of having a grid architecture. Please let me know if there's a way using which I can execute the test methods across the suite in parallel. I am sure that I am missing something silly, but could you please help me point that?

<suite name="Suite1" verbose="1" parallel="tests" thread-count="2" preserve-order="false">
<test name="Login" parallel="methods" thread-count="5">
<classes>
<class name="testSuite.TestSet1" />
</classes>
</test>
<test name="Product Search" parallel="methods" thread-count="5">
<classes>
<class name="testSuite.TestSet2"/>
</classes>
</test>
First allow your Suite to run "tests" in parallel with the number of test suites to run at a time (example 2).
Second allow your test to run "methods" parallel with the number of methods each can run (example 5 in each).
If you are bumping against the your thread limit be careful when adjusting these numbers. For example if you add another test group with thread-count of 5 and change your suite thread-count to 3. You'll now be at 15 threads.

Type parallel="tests" in your TestNG xml file

Parallel=methods would do exactly that - "methods inside the test cases are executed in parallel".
If you want your test tags to be executed parallely use parallel=tests.
This would run all your test tags in parallel.
But you state you have 10 nodes available. If above is the only xml you have then only two nodes would be used up at a time since you have just two test tags.

Related

How can I run a specific test from testng.xml file?

hope someone help me with this question, thanks !
I have this in testng.xml
<suite name="Test Project" verbose="1" thread-count="1" configfailurepolicy="continue">
<listeners>
<listener class-name="com.tests.TestListener"/>
</listeners>
<test name="Test1">
<classes>
<class name="com.tests.test1.LoginTest1"></class>
</classes>
</test>
<test name="Test2">
<classes>
<class name="com.tests.test2.LoginTest2"></class>
</classes>
</test>
</suite>
How can I run only the 'Test2'?
I tried mvn test -Dtest=Test2 but it was not working, run both tests
As explained in "maven command to run specific test class got org.testng.TestNGException"
You are mixing the two modes of execution. TestNG lets you run tests in two modes:
Via a TestNG suite xml file
Individual test classes by specifying the fully qualified class names of them.
In your case, you would need to use the class name of your Test2:
mvn test -Dtest=com.tests.test2.LoginTest2

Can we pass multiple browser names to execute parallelly through command line in Selenium Cucumber Maven framework

Iam using Selenium Cucumber Maven framework with Junit. I need to run the feature file in different browsers in parallel(at the same time).
Does this work if we pass browsernames like this ?
mvn test "-Dbrowser=chrome" , "-Dbrowser=firefox" through command line ?
If not please help me with a solution.
I have been asking this doubt for 2 weeks and Iam not getting any reply. It would be really great if you guys help me with a solution. Thanks in advance .
You can have a look at this post and this github project:
Basically, you can use gherkin with qaf to do something like this:
<suite name="run test in parallel Suite" parallel="tests" verbose="1" configfailurepolicy="continue" thread-count="2">
<test name="Tests in FF">
<parameter name="driver.name" value="firefoxDriver" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
<test name="Tests in Chrome">
<parameter name="driver.name" value="chromeDriver"/>
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
</suite>
Community NOTE : Since the referenced SO post does not have an accepted or upvoted answer, I could not mark this as duplicate.

How to pass TestNG groups comma separated(group1, group2) through terminal?

In my current build.gradle, i am using below target to run a specific group through command line
test {
jvmArgs "-DisParallel=true"
useTestNG(){
suites testngxml
includeGroups System.properties['groups']
}
}
Now i want to pass multiple groups with comma separated gradlew clean test -Dgroups='group1,group2'
any help please
Why not manage this at the TestNG Suite xml file instead of trying to manage this at the Gradle build file level ?
You can make use of a BeanShell within your TestNG suite xml file, that has the ability to read the group name as a JVM argument and then parse it and run tests accordingly ?
Below is an example which accepts a group name as a JVM argument and then dynamically lets tests run if and only if they belong to the group name that was passed. You can enhance this by adding your split logic and then leveraging the same containsKey() logic.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
<test name="Test">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[whatGroup = System.getProperty("groups");
groups.containsKey(whatGroup);
]]>
</script>
</method-selector>
</method-selectors>
<classes>
<class name="organized.chaos.GroupsPlayGround" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
For more information you can refer to the following :
TestNG Documentation
My Blog post

How to run a specific test in testng

I am trying to run a unique test from testng.xml.My testng.xml is as below:
<suite name="Suite">
<test name="one">
<parameter name="browser" value="firefox"/>
<parameter name="os" value="win"/>
<classes>
<class name="com.snapdeal.qa.Tests.MyAccount.SignUpTest"/>
</classes>
</test>
<test name="two">
<parameter name="browser" value="chrome"/>
<parameter name="os" value="win"/>
<classes>
<class name="com.snapdeal.qa.Tests.MyAccount.BaseTest"/>
<class name="com.snapdeal.qa.Tests.MyAccount.SignUpTest"/>
</classes>
</test>
</suite>
I am using maven and i am passing which test to run through sure-fire like this:
test -Dtests="one"
But its running all tests defined in testng.Where is actually i am wrong. and how to run a specfic test like this in any way
Code should be like below if you want to run only 1 test from xml :
<suite name="Suite">
<test name="one">
<parameter name="browser" value="firefox"/>
<parameter name="os" value="win"/>
<classes>
<class name="yourpackagename.yourclasname"/>
</classes>
</test>
</suite>
Just use test which you want to run like above. Pass package name and class name which you want to run.
If you want to skip specific test then you can set like : #Test(enabled = false) in yout java class file. So testNG will not run that test. So set (enabled = false) for test which you do not want to run.

how to run a single test on multiple machines using selenium grid, i am using maven and test ng

I have a testng.xml like this :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite verbose="0" name="Selenium Parallel Aim Suite" parallel="tests" >
<test name="FB login and Screen capture" parallel="true">
<classes>
<class name="com.jm.webdriver.JTest1"/>
</classes>
</test>
<test name="Google Search" parallel="true">
<classes>
<class name="com.jm.webdriver.JTest2"/>
</classes>
</test>
</suite>
I want to launch these two test cases on say three machines 1. Windows, 2 linux 3. Mac parallelly, How to do so ?
It should be parallel = "true" for suite tag and parallel property is not required for test tags. If you are looking for grid setup then refer the seleniumhq.org documentation.

Resources