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
Related
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
I am running a TestNG.xml
I have created a maven project for my automation selenium script and added all the required dependencies to pom.xml. If I run the suite defined in the Testng.xml file using TestNG.run() command TestNG test result console is blank.
And please do share if there is any other way to run the testNG.xml from main() method so that I can get each test case status in testNG console
Please refer the code that I have used
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add(currdir+"/tempTestNG.xml");//path of xml..
testng.setTestSuites(suites);
testng.run();
Please refer the testNG.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<parameter name="ExecutionType" value="Regression"/>
<listeners>
<listener class-name="config.TestListener"/>
</listeners>
<test name="Test">
<classes>
<class name="testsuits.VerificationOfWiki">
<methods>
<include name="VerifyMainpagetextonWiki"/>
<include name="VerifyRandomArticletextonWiki"/>
</methods>
</class>
</classes>
</test>
</suite>
When I try to run a single TestNG test class from the command line using the command
mvn test -Dtest=NBC1
where NBC1 is the name of my test class, I get an error message saying "Failed to execute goal... No tests wre executed!
I am running this using Java. My current configuration is that I have one master testng.xml suite file in my project root. I have this listed in my POM file as an XmlSuiteFile. This testng.xml file contains other suite files which contain the actual test classes. I have tried moving these out and not nesting my suite files, but it still does not work. Each test class contains only 1 test method.
Here is where I specify my top-level suite file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
And this is what my suite file looks like
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name = "Test Suite">
<listeners>
<listener class-name="com.project.selenium.utilities.AnnotationTransformer" />
</listeners>
<suite-files>
<suite-file path="src/main/java/com/project/selenium/testsuites/foo1/FullSuite.xml" />
<suite-file path="src/main/java/com/project/selenium/testsuites/foo2/FullSuite.xml" />
</suite-files>
</suite>
This is what one of the FullSuite.xml files looks like. I've left off some suite-files for simplicity's sake
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="AssureTrak Full Suite">
<suite-files>
<suite-file path="src/main/java/com/project/selenium/testsuites/foo1/Cleanup.xml" />
<suite-file path="src/main/java/com/project/selenium/testsuites/foo1/DataSetup.xml" />
</suite-files>
</suite>
And, finally, this is a lowest level suite file looks like
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name = "DataSetup">
<test name = "DataSetup">
<classes>
<class name="com.project.selenium.testcases.foo1.datasetup.nbc.NBC1" />
<class name = "com.project.selenium.testcases.foo1.datasetup.nbc.NBC2" />
<class name = "com.project.selenium.testcases.foo1.datasetup.nbc.NBC3" />
<class name = "com.project.selenium.testcases.foo1.datasetup.nbc.NBC4" />
<class name = "com.project.selenium.testcases.foo1.datasetup.nbc.NBC5" />
</classes>
</test>
</suite>
Try upgrading to the latest version of TestNG as you might be suffering from a form of a bug
Try providing fully qualified class name like
mvn -Dtest=com.project.selenium.testcases.foo1.datasetup.nbc.NBC1 test
You can always come up with a testng.xml file to kick off the desired class like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestNG Debug Single Class">
<test name="testng">
<classes>
<class name="com.project.selenium.testcases.foo1.datasetup.nbc.NBC1"/>
</classes>
</test>
</suite>
however if points 1 and 2 will not help it looks like a bug so you could report it
Check out example TestNG integration instruction for more information
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.
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.