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 in testng as true

you have an web-application and for which you wrote automation script. and in your automation script all the Methods and Class depend on other then  you want to execute your testcases in sequence for sequential execution you have to use "preserve-order" text and its attribute value as
true in testng xml file.

preserve-order is default attribute as true then class and methods should be executed in sequence
TestNG will run all methods and Class in the order as we defined in the sequence in XML file.

in our example we have three class and each class content two methods and we will try to execute the same.

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'.
<TestngCode> <?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="true">
    <classes>
   <class name="testng_Example.includeExculde"/>
        <class name="testng_Example.test_second"/>
       <class name="testng_Example.test_three"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

</testngCodeend>

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


[TestNG] Running:
  C:\Users\workspace\Blogger_Example\testng.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

===============================================
Suite
Total tests run: 6, Failures: 0, Skips: 0
===============================================


No comments

Post a Comment

Powered by Blogger.