testng suite doesn't run in the order specified - java

I have below testng test suite.
<suite name="MySuite" parallel="false">
<test name="MyTest" parallel="false" preserve-order="true">
<classes>
<class name="com.my.package.Test1"/>
<class name="com.my.package.Test2"/>
<class name="com.my.package.Test3"/>
<class name="com.my.package.Test4"/>
<class name="com.my.package.Test5"/>
<class name="com.my.package.Test6"/>
<class name="com.my.package.Test7"/>
<class name="com.my.package.Test8"/>
<class name="com.my.package.Test9"/>
<class name="com.my.package.Test10"/>
<class name="com.my.package.Test11"/>
<class name="com.my.package.Test12"/>
<class name="com.my.package.Test13"/>
<class name="com.my.package.Test14"/>
<class name="com.my.package.Test15"/>
<class name="com.my.package.Test16"/>
<class name="com.my.package.Test17"/>
<class name="com.my.package.Test18"/>
<class name="com.my.package.Test19"/>
<class name="com.my.package.Test20"/>
<class name="com.my.package.Test21"/>
<class name="com.my.package.Test22"/>
<class name="com.my.package.Test23"/>
<class name="com.my.package.Test24"/>
<class name="com.my.package.Test25"/>
</classes>
</test>
</suite>
I use testng 6.14.3
And I execute the suite with following command.
mvn test -DsuiteXmlFile=suite.xml
I expect the tests to run in the order specified in the xml (I have used preserve-order="true" attribute). But, the tests are executed in below order.
com.my.package.Test1
com.my.package.Test23
com.my.package.Test2
com.my.package.Test24
com.my.package.Test3
com.my.package.Test25
com.my.package.Test4
com.my.package.Test5
com.my.package.Test6
...
...
If the number of test classes is less than 23, they run in the given order. But, when the count is 23 or more, tests are executed in above pattern.
What could be wrong here?

I found the issue. The cause was class Test22 not having any test methods in it. The test that was there had been commented out. When the test was added again to the class, suite started to run again in expected order.
Not sure whether this is a bug in Testng or not.

Related

How to run TestNG tests parallelly through xml with priority

I have a scenario where a class "Pre-Requisite" class have to be executed first and then I have 5 testng classes which have to use certain data gathered from "Pre-Requisite.java" class and execute all 5 classes parallelly. Eg. of an xml below:
<test name="Suite">
<classes>
<class name="Pre-Requisite"/> // To be run first
</test>
<test name="Suite">
<classes>
<class name="AClass"/> // To be run in parallel with below classes
<class name="BClass"/>
<class name="CClass"/>
<class name="DClass"/>
<class name="EClass"/>
</test>
</suite>
can someone please help me how do I achieve this?
You can mark the methods in the class "Pre-Requisite" with the TestNG annotations - "#BeforeClass" or "#BeforeSuite", so it will execute the code in the class "Pre-Requisite" first.
Then you can execute other classes in parallel through testng.xml, like:
<suite name="Suite">
<test name="Test1" parallel="classes">
<classes>
<class name="AClass"/>
<class name="BClass"/>
<class name="CClass"/>
<class name="DClass"/>
<class name="EClass"/>
</classes>
</test>
</suite>

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

I want to create xml in order to execute my classes

I have created a TestNG XML File, which I have called multiple classes. My concern is that I want to execute my test cases on all classes which I have arranged from top to bottom like below. However some of the bottom cases depend on upper cases, and whenever I run my XML File it selects the classes randomly. How would I go about doing this?
Type - 1
{
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite3">
<test name="Test3" preserve-order="true">
<classes>
<class name="com.netgearInsight.testReports.RegistrationTestCase"/>
<class name="com.netgearInsight.testReports.LoginTestCase"/>
<class name="com.netgearInsight.testReports.AddNetworkTestCase"/>
<class name="com.netgearInsight.testReports.AddDevicesTestCase"/>
<class name="com.netgearInsight.testReports.CreateSsidTestCase"/>
<class name="com.netgearInsight.testReports.DeleteDevicesTestCase"/>
<class name="com.netgearInsight.accountCheck.About"/>
<class name="com.netgearInsight.accountCheck.AccountManage"/>
<class name="com.netgearInsight.testRunEnd.GetTotalStatus"/>
<class name="com.netgearInsight.testRunEnd.SendReport"/>
</classes>
</test> <!-- Test3 -->
</suite> <!-- Suite3 -->
}
Type - 2
{
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite1">
<test thread-count="5" name="Test One" >
<classes>
<class name="com.netgearInsight.testReports.RegistrationTestCase"/>
<class name="com.netgearInsight.testReports.LoginTestCase"/>
</classes>
</test> <!-- Test -->
<test thread-count="5" name="Test Two" >
<classes>
<class name="com.netgearInsight.testReports.AddNetworkTestCase"/>
<class name="com.netgearInsight.testReports.AddDevicesTestCase"/>
<class name="com.netgearInsight.testReports.CreateSsidTestCase"/>
</classes>
</test> <!-- Test -->
<test thread-count="5" name="Test Three" >
<classes>
<class name="com.netgearInsight.testReports.UrlFilterTestCase"/>
<class name="com.netgearInsight.testReports.DeleteDomainTestCase"/>
<class name="com.netgearInsight.testReports.DeleteDevicesTestCase"/>
</classes>
</test> <!-- Test -->
<test thread-count="5" name="Test Four" >
<classes>
<class name="com.netgearInsight.testReports.AddDataVLAN"/>
<class name="com.netgearInsight.accountCheck.AccountManage"/>
<class name="com.netgearInsight.accountCheck.About"/>
<class name="com.netgearInsight.accountCheck.ChangePassword"/>
</classes>
</test> <!-- Test -->
<test thread-count="5" name="Test Five">
<classes>
<class name="com.netgearInsight.testRunEnd.GetTotalStatus"/>
<class name="com.netgearInsight.testRunEnd.SendReport"/>
</classes>
</test> <!-- Test -->`enter code here`
</suite> <!-- Suite -->
}

Selenium grid with webdriver and testNG

I am experiencing the following problem. I have set up a grid with 2 nodes, in order to run tests in parallel.My suite.xml file has two groups, one for each node:
<suite name="testSuites" configfailurepolicy="continue" thread-count="2" parallel="tests">
test name="testSuite1" preserve-order="true">
<classes>
<class name="testA1" />
<class name="testB1" />
<class name="testC1" />
</classes>
</test>
<test name="testSuite2" preserve-order="true">
<classes>
<class name="testA2" />
<class name="testB2" />
<class name="testC2" />
</classes>
</test>
Each class, for example testA1 has the following testNG configuration:
#BeforeClass(alwaysRun = true)
public void createInitialData() {
}
#Test(alwaysRun = true, description = "bla bla")
public void testStep_1() throws Exception{
}
#Test(alwaysRun = true, description = "bla bla ", dependsOnMethods ="testStep_1" )
public void testStep_2() {
}
Upon running I noticed that during the execution, the tests are executing in test step wise order, meaning:
testA1-testStep_1, testB1-testStep_1, testC1-testStep_1, testA1-testStep_2, testB1-testStep_2, testC1-testStep_2
whereas it should have been:
testA1-testStep_1, testA1-testStep_2, and then testB1-testStep_1, testB1-testStep_2, testC1-testStep_1, testC1-testStep_2
Any suggestions?
Try to set group-by-instances in your xml
<suite group-by-instances="true">
or
<test group-by-instances="true">
<test name="testSuite2" parallel="false">
Seem also be doing what you need.

TestNG:Cannot find class in classpath, testng.xml

This is my testng.xml file, i named it differently, but it should still work:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TEST_LINKS">
<test name="TECT на подбор спеца">
<classes>
<class name="Podbor_specalista_url_click_test" />
</classes>
</test>
<test name="TECT на клик блога">
<classes>
<class name="Blog_url_click_test" />
</classes>
</test>
</suite>
Now, i get the error, but where do I fix it?
i want to run the whole test suite consisting of these tests:
You need to give the fully qualified class name of the class you want to test in class tag, something like this
<suite thread-count="5" name="Ant suite" junit="false" annotations="JDK">
<test name="Ant test">
<classes>
<class name="com.sample.test.MyUnitTest"/>
</classes>
</test>
</suite>

Categories