How to ensure that the order specified in TestNG.xml is saved?

When using TestNG + Selenium, I cannot provide the order in which classes are executed. The order below (in testng.xml) does not work -> ClassTwo is executed 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 guarantee that the order specified in TestNG.xml is preserved?

+5
source share
4 answers

According to TestNG Documentation :

By default, TestNG will run your tests in the order in which they are in the XML file. If you want the classes and methods listed in this file to run in an unpredictable order, set the save-order attribute to false

preserve-order, .

, , /:

  • .
  • , .
+4

none

<suite name="ABC" parallel="none">

!

+4

@Test( dependsOnGroups= { "dummyGroupToMakeTestNGTreatThisAsDependentClass" } ) ?

: TestNG Selenium: "" ,

Hope this helps!

0
source

.... Quite a bit after the event, but I had the same problem and I ended up here.

In the end, this was due to the fact that individual tests were prioritized in the annotation @Test, so in my case, but your example script.ClassTwohad a higher priority thanscript.ClassOne

0
source

All Articles