Friday, 5 February 2016

Test cases execution using enabled in testNG

Test cases execution using enabled in testNG:
===================================

In order to execute or if you dont want to execute a particular test case use enabled attribute in testNG Framework.

When ever you specify enabled=false that tetcase will not execute.
ex:@Test(@enabled=false)
By default whether you specify or not enabled=true.
 //sample example on enabled attribute
---------------------------------------------------
package testngdemo;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Test;

public class ParallelRunDemo {


WebDriver webDriver;


@Test(enabled=true)
public void testScript() throws InterruptedException 
{

System.setProperty("webdriver.chrome.driver", "D:\\Ramesh\\ChromeDriver.exe");
   webDriver = new ChromeDriver();
//webDriver=new FirefoxDriver();
webDriver.manage().window().maximize();
webDriver.manage().deleteAllCookies();
webDriver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
webDriver.get("https://google.com");
webDriver.findElement(By.name("q")).sendKeys("selenium by ramesh");
webDriver.findElement(By.name("btnG")).click();
Thread.sleep(3000);
webDriver.findElement(By.linkText("Selenium By Ramesh Anapati")).click();
webDriver.quit();
}

@Test(enabled=false)
public void testScript1()
{

System.setProperty("webdriver.chrome.driver", "D:\\Ramesh\\ChromeDriver.exe");
   webDriver = new ChromeDriver();
//webDriver=new FirefoxDriver();
webDriver.manage().window().maximize();
webDriver.manage().deleteAllCookies();
webDriver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
webDriver.get("rameshselenium.blogspot.in");
webDriver.findElement(By.linkText("Parallel execution in selenium webdriver")).click();
webDriver.quit();
}
@Test(enabled=false)
public void testScript2()
{
System.setProperty("webdriver.chrome.driver", "D:\\Ramesh\\ChromeDriver.exe");
   webDriver = new ChromeDriver();
//webDriver=new FirefoxDriver();
webDriver.manage().window().maximize();
webDriver.manage().deleteAllCookies();
webDriver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
webDriver.get("seleniumhq.org");
webDriver.quit();
}

}

No comments:

Post a Comment