Reputation: 475
On using TestNG+Selenium , I'm not able to ensure the order of execution of classes.The order specified below (in testng.xml) is not working ->ClassTwo executes first and then ClassOne is executed.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="ABC" parallel="">
<test verbose="2" name="xyz" annotations="JDK" preserve-order="true">
<classes>
<class name="script.ClassOne"/>
<class name="script.ClassTwo"/>
</classes>
</test>
</suite>
How can I ensure that the order specified in TestNG.xml is retained?
Upvotes: 9
Views: 22045
Reputation: 142
In TestNG, the order of execution is based on alphabetical order so we could use a TestNG attribute Priority and there we could mention which class->methods you want to execute first.This is Priority annotation attribute you could give in the @Test annotation.
example: @Test(Priority=-1)
Lesser the number value the first it will execute.
Upvotes: 0
Reputation: 101
You just have to set parallel value to none
<suite name="ABC" parallel="none">
it works for me !
Upvotes: 7
Reputation: 56
....Quite a bit after the event but I had the same problem and found myself here.
In the end it was because the individual tests had been marked with a priority in the @Test
annotation, so in my case but your example script.ClassTwo
had a higher priority than script.ClassOne
Upvotes: 0
Reputation: 81
Did you try @Test( dependsOnGroups= { "dummyGroupToMakeTestNGTreatThisAsDependentClass" } )
in the class?
See this thread: TestNG & Selenium: Separate tests into "groups", run ordered inside each group
Hope this helps!
Upvotes: 0
Reputation: 5082
According to TestNG documentation:
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
I would suggest leaving the preserve-order
attribute out, since it is set by default.
However, you have two other options to force specific order to the test methods/classes:
Upvotes: 7