The blog gives you idea of testing and automation testing example of selenium webdriver,SQl and Jmeter, you see the basic example of selenium web driver and get idea how to do automation testing,

Preserver order False in Test NG

you have an web-application and for which you wrote automation script.
you have an independent Methods and Class which you want to execute at random or unpredictable order then you have to use "preserve-order" text and its attribute value has to be false in your testng xml file but if you want to execute your method in sequence then set "preserve-order" as true

preserve-order default attribute is true you do not have set it forcefully
TestNG will run your tests in the order they are found in the XML file.

in our example we have three class and each class content two methods and we will try to execute the same. initials we will set preserve-order attribute as false and will check the out-put

we have below classes.
=============================================================================
includeExculde.java

package testng_Example;
import org.testng.annotations.Test;
public class includeExculde {
  @Test
  public void testingOne() {
  System.out.println("======= includeExculde Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingTwo() {
  System.out.println("======= includeExculde Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
}
========================================================================
test_second.java
package testng_Example;
import org.testng.annotations.Test;
public class test_second {
@Test
 public void testingone() {
  System.out.println("======= test_second Class Test one is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
 }
 @Test
 public void testingtwo() {
  System.out.println("======= test_second Class test two is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
 }
}
========================================================================
test_three.java
package testng_Example;
import org.testng.annotations.Test;
public class test_three {
@Test
 public void testingthird1() {
  System.out.println("======= test_three Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
 }
@Test
 public void testingthird2() {
  System.out.println("======= test_three Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
 }
}

Now we will define the xml file with preserve-order attribute for tests and set the value as 'false'.
<Code View><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test" preserve-order="false">
    <classes>
      <class name="testng_Example.test_three"/>
      <class name="testng_Example.test_second"/>
      <class name="testng_Example.includeExculde"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->
</Code View End>

we have set the preserve-order attribute as false and now will see the execution in order. They will get executed in an unpredictable order of class

[TestNG] Running:
  C:\Users\ankitjain\AppData\Local\Temp\testng-eclipse--706368730\testng-customsuite.xml

======= includeExculde Class is executed and pass for TestNG ======testingOne
======= includeExculde Class is executed and pass for TestNG ======testingTwo
======= test_second Class Test one is executed and pass for TestNG ======testingone
======= test_second Class test two is executed and pass for TestNG ======testingtwo
======= test_three Class is executed and pass for TestNG ======testingthird1
======= test_three Class is executed and pass for TestNG ======testingthird2



No comments

Post a Comment

Powered by Blogger.