Saturday, 1 November 2014

How to use TestNG with Selenium Webdriver?

TestNG is the next generation testing framework. You can easily integrate your selenium scripts in TestNG.

Please follow below steps to run TestNG tests in Eclipse.

  1. Download TestNG at http://testng.org/doc/download.html
  2. Then Create a TestNG class in any project.
  3. Define test methods in that class using @Test annotation
  4. Right click on the TestNG class and run as TestNG class.
In below example, we have created a TestNG class called NewTest with 2 test methods Test1 and Test2.

package framework;

import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class NewTest {
  @Test
  public void Test1() {

   //Test something here.
   Assert.assertNotNull("abc");
  }
  
  @Test
  public void Test2() {
   //Test something here.
Assert.assertNull("jj"); } @BeforeSuite public void beforeSuite(){
      //this method is called once before test execution starts
//here you can write a code to launch the selenium web driver. } @AfterSuite public void afterSuite(){
      //this method is called once after test execution ends.
//here you can write a code to close and quit the selenium web driver. } }

What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com 

No comments:

Post a Comment

Buy Best Selenium Books

About Me

My photo

Self-motivated software professional