Reputation: 1
While running a jar e.g:
java -jar a.jar -testjar a.jar -xmlpathjar Test.xml
<!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">
<groups>
<run>
<include name="brokenTests"/>
<include name="checkinTests"/>
</run>
</groups>
<classes>
<class name="organized.chaos.GroupsPlayGround" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
HOW TO GIVE ONLY brokenTests name in argument java -jar a.jar -testjar a.jar -xmlpathjar Test.xml
such that only this group testcases will be executed?
I'm expecting to give run groups in the argument itself.
Upvotes: 0
Views: 32
Reputation: 14736
If you would like to specify the group name via the commandline argument, then you should pass it as -groups
(Here I am assuming that your executable jar is going to directly invoke the main method from within org.testng.TestNG
java class
For more details, please refer to https://testng.org/#_command_line_parameters
If you are going to be making use of a suite file and you would still like to be able to specify the group name, then you should make use of a beanshell.
Please refer to the documentation for more details https://testng.org/#_beanshell_and_advanced_group_selection
Here's a sample xml file that shows how to make use of beanshell and then retrieve the groups name and use that to run is as below:
<?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("groupToRun");
groups.containsKey(whatGroup);
]]>
</script>
</method-selector>
</method-selectors>
<classes>
<class name="organized.chaos.GroupsPlayGround" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
You can refer to my blogpost for additional details https://rationaleemotions.com/beanshell_in_testng/
Upvotes: 0