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
===============================================


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



Include and Exclude Java method on TestNG

TestNg provides an options to include or exclude Groups, Java class, Java methods using include and exclude tags in XML file.

Below is the example which give you how to user include and exclude tags for methods.
Let as take an example : if you have a class which contents 5 or 6 java method in which you want to executed only two method and remaining method does not execute know.

I will create a Java class which contents five methods, in which we will include two methods and remaining three would be exclude.

Below is the example class file with three test methods

package testng_Example;
import org.testng.annotations.Test;
public class includeExculde {

  @Test
  public void testingFrist() {
  System.out.println("======= which Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingSecond() {
  System.out.println("======= Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingThird() {
  System.out.println("======= Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingFourth() {
  System.out.println("======= Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingFifth() {
  System.out.println("======= Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
  }
}

In the above example, we have created five methods, 'testingFirst','testingSecond','testingThird','testingFourth' and 'testingFifth'

In testng.xml file we will include "testingFirst","testingSecond" and "testingFourth" and exclude "testingThird" & "testingFifth" and try to execute the same using testng.xml and it will execute the Three class and does not execute two classes. Methods always define inside class tag.




Powered by Blogger.