Tuesday 8 July 2014

How to ignore/exclude test in webdriver using Junit



-> We can use @ignore inbuilt annotation will help us to ignore specific method from test for execution.
-> We need to put @Ignore annotation in test before @Test method which we want to exclude

Example:

If we want to ignore/exclude below test from execution. we need to put @ignore annotation in test before @Test method



package JuintPackage;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Junit_Test1 {

WebDriver driver1=new FirefoxDriver();

@Before
public void beforetest()
{
driver1.manage().window().maximize();
driver1.get("http://google.com");
}

@After
public void aftertest()
{
driver1.quit();
}


@Test
public void Execute_Process()
{

driver1.findElement(By.linkText("Gmail")).click();
}

// ignore below test from execution

@ignore
@Test
public void Execute_SecondProcess()
{

driver1.findElement(By.linkText("Images")).click();
}

}



From above example using @ignore annotation we can ignore/exclude Execute_SecondProcess() method from execution.

No comments:

Post a Comment