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?
If you want your classes / methods to be run in an unpredictable order, then we should go for preserve-order attribute in testng. In TestNg bydefault the preserve-order attribute will be set to 'true', this means, TestNG will run your tests in the order they are found in the XML file.
The hierarchy in the testng xml file is very simple to understand. Very first tag is the Suite tag<suite>, under that it is the Test tag<test> and then the Class tag<classes>.
In such cases, TestNG follows an alphabetical order while executing them. The below example has two test methods (a and b), and both have the same default priority that is 0. Therefore, the order of execution will be method a followed by b.
You just have to set parallel value to none
<suite name="ABC" parallel="none">
it works for me !
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With