Wednesday, February 27, 2013

Selenium : Throw new SkipException


Program to skip all the tests in a file using "Throw new SkipException". The below file contains 2 @Test which is test1 ,test2 and we have @BeforeMethod. By inserting "Throw new SkipException" statement in the @BeforeMethod all the test can be skipped while executing through TestNG.


Example :

package package_name;

import org.testng.SkipException;
import org.testng.annotations.BeforeMethod;


public class Test
{

@BeforeMethod
public void Method()
{
System.out.println("BeforeMethod");
throw new SkipException ("Skipping test");//Instruction to Skip
}

@org.testng.annotations.Test
public void test1()
{
System.out.println("Testing 1");
}

@org.testng.annotations.Test
public void test2()
{
System.out.println("Testing 2");
}

}

No comments:

Post a Comment