Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run the test classes in particular order using SeleniumWebDriver(Java) with TestNG?

I want to run the Selenium WebDriver (Java) test classes in the particular order using TestNG.

For eg. I have 3 classes such as Test1, Test2 and Test3. I want to run in the order Test2, Test1 and Test3. Is it possible without grouping?

I tried the following way, but I runs in its own order (Alphabetical order).

<suite name="MyTestSuite" verbose="4">

<test name="MyTest">
   <classes>
        <class name="com.mypackage.Test2" />
        <class name="com.mypackage.Test1" />
        <class name="com.mypackage.Test3" />
   </classes>
</test>

Is there any other way to do this? Without grouping is this possible?

like image 257
Rajaa Avatar asked Aug 16 '26 07:08

Rajaa


1 Answers

Just use preserve-order="true" to make classes to run in given order.

<suite name="MyTestSuite" verbose="4">

<test name="MyTest" >
   <classes preserve-order="true">
        <class name="com.mypackage.Test2" />
        <class name="com.mypackage.Test1" />
        <class name="com.mypackage.Test3" />
   </classes>
</test>
like image 150
Santoshsarma Avatar answered Aug 18 '26 05:08

Santoshsarma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!