Why group name mentioned in testng.xml has high preference? - java

I have below testng.xml file where I've mentioned a group name to execute all testcases which has the same group name in my test suite
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestDive" verbose="0" parallel="methods" thread-count="2">
<test name="HereWeGo" enabled="true">
<groups>
<run>
<include name="SANITY_PROD"/>
</run>
</groups>
<classes>
<class name="com.xyz.Classname"/>
</classes>
</test>
</suite>
Now if i pass the group name from command line e.g. mvn clean test -DtestSuiteFile="config/sanity_suite.xml" -DincludeGroups=SANITY_STAGE
The problem is it still executes the all test case with group SANITY_PROD as mentioned in xml file.
Am i doing something wrong here ?

I am not sure about includeGroups attribute but try like this:
mvn clean test -Dgroups=SANITY_STAGE

Related

How to run a single test from TestNG.XML file in command line from Gradle Kotlin

I have testNG file which has multiple methods.
In this testNG file I added the parameters to pass the parameter on code from xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="LocalIosTestSuite" parallel="tests" thread-count="1" >
<test name="iphonetest">
<parameter name="platformName" value="iphonetest" />
<classes>
<class name="tests.TestKotlin">
</class>
</classes>
</test>
<test name="androidtest">
<parameter name="platformName" value="androidtest" />
<classes>
<class name="tests.TestKotlin">
</class>
</classes>
</test>
</suite>
Kotlin Class
import org.testng.annotations.Parameters
import org.testng.annotations.Test
class TestKotlin {
#Parameters("platformName")
#Test()
fun Testmethod(platformName:String)
{
println("TestKotlin")
println(platformName)
}
}
Command to run a single test from testng file
./gradlew test -Psuite5 -testnames iphonetest
This is not working for me please help me any solution to run a specific test on gradle

TestNG XML file not running tests sequentially - Selenium Java

I would like all my classes running sequentially. Below is my testng xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="instances" thread-count="1">
<test name="Test">
<classes>
<class name="atk.tests.Printer"/>
<class name="atk.tests.Rejecteur"/>
<class name="atk.tests.Specfeatures"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
I've tried in suite name tag to do :
<suite name="Suite" parallel="instances" thread-count="1"> then
<suite name="Suite" parallel="false" >
And then in classes:
<classes parallel="methods">
No solution is working to make my tests running sequentially. For the moment, they are running in parallel and i would like to avoid that.
Is anyone able to provide a solution for that ? Thanks
By default, TestNG will run your tests in the order they are found in the XML file. If you want the classes and methods listed in this file to be run in an unpredictable order, set the preserve-order attribute to false
For this ordering, you can use the XML attribute group-by-instances. This attribute is valid either on <suite> or <test>
<suite name="Suite" group-by-instances="true">
or
<test name="Test" group-by-instances="true">
try once with preserver order true and parallel none
<suite name="Suite" parallel="none" preserve-order="true">

TestNG: Running specific group tests using Testng XML file

I have a testng xml file that is setup to run a specific class that has methods containing the following group tags or are grouped as one of the following:
parallel-test
sequential-test
smoke-test
Although some of my tests are designated as either parallel or sequential, some of the test may contain an additional tag 'smoke-test.' In this scenario, I want to be able to just run those that are grouped as 'smoke-test.' When I run the tests, it either cannot find any tests or it just runs all tests grouped as 'sequential-test.' I cannot seem to restrict the test run from this xml file to just those tests grouped as 'smoke-test.' In the same class, I have multiple testNG methods that have either the 'parallel-test' group or the 'sequential-test' group. What it looks like the TestNG xml file is doing is just ignoring the 'parallel-test' group. Thats great, but what if there is Testng method that contains the group 'parallel-test' and 'smoke-test?' I want to run every test regardless of whether it is for parallel testing or sequential, but ONLY those that have the additional group tag 'smoke-test.' My environment is the following:
IntelliJ
Maven
TestNG
Java
Please help. See sample test method in the WebTest.Test class:
#Test(groups = {"sequential-test","smoke-test"},description = "Test will validate something")
public void RunTest()
{
//do something
}
Here is the sample xml file below
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!--This is a template to be modified for QA environment tests-->
<suite name="Smoke Test">
<listeners>
<listener class-name="Listeners.Listeners"/>
<listener class-name="Listeners.ExtentListeners"/>
</listeners>
<parameter name="environment" value="QA"></parameter>
<test verbose="2" name="Sequential tests" parallel="methods" thread-count="1">
<!--<groups>
<run>
<exclude name="parallel-test"/>
</run>
</groups>-->
<classes>
<class name="WebTests.Test">
<methods>
<include name="smoke-test"/>
</methods>
</class>
</classes>
</test>
</suite>
Below XML Suite should run the all test method having group 'smoke-test'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!--This is a template to be modified for QA environment tests-->
<suite name="Smoke Test">
<listeners>
<listener class-name="Listeners.Listeners"/>
<listener class-name="Listeners.ExtentListeners"/>
</listeners>
<parameter name="environment" value="QA"></parameter>
<test verbose="2" name="Sequential tests" parallel="methods" thread-count="1">
<groups>
<run>
<include name="smoke-test"/>
</run>
</groups>
<classes>
<class name="WebTests.Test"/>
</classes>
</test>
</suite>

how to run test by name with parameters in testng xml on maven command line

I have a testng.xml like below. I am trying to run test by names which are in testng.xml (myfirstcase or mysecondcase) by using maven command line.
command line:
mvn -Dtest=myfirstcase -Dsurefire.suiteXmlFiles=/Users/huseyintumer/IdeaProjects/experitestandroid/testng.xml test -f /Users/huseyintumer/IdeaProjects/experitestandroid/pom.xml
When i command line below, it works. But parameters in testng.xml does not pass.
mvn -Dtest=firstTest -Dsurefire.suiteXmlFiles=/Users/huseyintumer/IdeaProjects/experitestandroid/testng.xml test -f /Users/huseyintumer/IdeaProjects/experitestandroid/pom.xml
Actually i dont want to run test by class name. I need to run test by test names in testng.xml with parameters.
testng.xml:
<suite name="Suite" parallel="tests">
<test name="myfirstcase">
<classes>
<class name="firstTest">
<parameter name="udid" value="CQ300002LG" />
</class>
</classes>
</test>
<test name="mysecondcase">
<classes>
<class name="firstTest">
<parameter name="udid" value="BH90018AAX" />
</class>
</classes>
</test>

Show all failed tests of multiple test suite in one testNG report

Actually I'm testing multiple website for my company. All the website have the same structure and i'm testing various things on each.
For my test i have a Selenium Java Maven project using TestNG. For each web site, i've created a sub folder and generate a specific testing.xml file to specify each test i'm doing for the website.
Here the structure : http://imgur.com/g0VHfMw
My testing.xml files are like this :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test suite website 1" parallel="tests" thread-count="2">
<test name="Test1">
<classes>
<class name="package.for.mytest1"></class>
</classes>
</test>
<test name="Test2">
<classes>
<class name="package.for.mytest2"></class>
</classes>
</test>
<test name="Test3">
<classes>
<class name="package.for.mytest3"></class>
</classes>
</test>
</suite>
How can I merge this 4 test suite in one testNG report ? And if it's possible, is there a way to only show the unstable or failed test on it ?
Any ideas ? Thanks for your help
Try Allure it could easily generate combined report for several suites and show only failed/broken tests by default.
Either you can Use Suite-XML tag in TestNG.xml file to report all your test in single report or implement a reporter of your own to collect all the results and then at the end flush everything into report of your own format with whatever information you need.
You can create a separate testng.xml file in which you can give the path of other testsuites files.
eg:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name= "Allsuites" verbose="1" preserve-order="true" >
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"/>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
</listeners>
<suite-files preserve-order="true">
<suite-file path="testng1.xml" />
<suite-file path="testng2.xml" />
<suite-file path="testng3.xml" />
</suite-files>
</suite>

Categories