Use Of preserve-order In TestNG With Selenium WebDriver

preserve-order Is real Important attribute In TestNG. In Selenium WebDriver seek out execution, Many times peoples are complaining similar my test cases execution non runs In right sequence as given In testng.xml file but they are beingness executed In random sequence(unpredictable order). Actually they have re-create pasted testng.xml file from somewhere amongst attribute preserve-order="fasle" but they don't know pregnant of this attribute. Let me effort to explicate you lot pregnant of this attribute.

  1. In testng.xml file, If you lot convey non fix preserve-order attribute amongst <test> node, By default It volition last true. So your seek out shape execution fellowship volition stay same every bit you lot convey given In testng.xml file.
  2. Sameway, If you lot fix attribute preserve-order="true" amongst <test> node, Your seek out execution volition last same every bit given In testng.xml file.
  3. But If you lot set preserve-order="false", Your seek out cases volition last executed In unpredictable order.
Let me order you lot examples amongst preserve-order="true" as well as preserve-order="false" attribute.

You tin let on to a greater extent than tutorial links on testng amongst webdriver at PAGE 1 as well as PAGE 2

Create iii seek out cases every bit bellow nether package Testing_Pack.

1. Test_One.java
package Testing_Pack;  import org.testng.annotations.Test;  world shape Test_One {  @Test  world void testCaseOne_ClassOne() {   System.out.println("Executing testCaseOne_ClassOne Of ClassOne");  } }

2. Test_Two.java
package Testing_Pack;  import org.testng.annotations.Test;  world shape Test_Two {  @Test  world void testCaseOne_ClassTwo() {   System.out.println("Executing testCaseOne_ClassTwo Of ClassTwo");  } }

3. Test_Three.java
package Testing_Pack;  import org.testng.annotations.Test;  world shape Test_Three {    @Test  world void testCaseOne_ClassThree() {   System.out.println("Executing testCaseOne_ClassThree Of ClassThree");  } }

Create bellow given testng.xml file nether your projection to run all higher upwards seek out cases.

testng.xml (with preserve-order="false")
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="preserve-order Suite">   <test name="preserve-order Test" preserve-order="false">     <classes>       <class name="Testing_Pack.Test_One"/>       <class name="Testing_Pack.Test_Two"/>       <class name="Testing_Pack.Test_Three"/>     </classes>   </test> </suite>

If you lot volition run higher upwards given testng.xml file, seek out classes execution fellowship volition looks similar bellow. You tin run across that seek out execution sequence Is non same every bit given In testng.xml file.


Now allow us purpose preserve-order="true" attribute In testng.xml file every bit bellow as well as let on execution result.

testng.xml (with preserve-order="true")
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="preserve-order Suite">   <test name="preserve-order Test" preserve-order="true">     <classes>       <class name="Testing_Pack.Test_One"/>       <class name="Testing_Pack.Test_Two"/>       <class name="Testing_Pack.Test_Three"/>     </classes>   </test> </suite>

Now run higher upwards testng.xml file as well as let on seek out classes execution order. It volition last same every bit given In testng.xml file every bit shown In bellow given Image.


So this Is the illustration of using preserve-order attribute In testng.xml file. To execute seek out cases In right order, you lot request to fix preserve-order=true as well as to execute them In unpredictable order, fix preserve-order=false.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post