Test case execution in selenium based on grouping:
=======================================
‘Groups‘ is one more annotation of TestNG which can be used in the execution of multiple tests.
This annotation we need to declare at test level.
//Sample example on grouping mechanism in selenium testng
---------------------------------------------------------------------------------
Sample1.java
------------------
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 Sample1 {
WebDriver webDriver;
@Test(groups="regression testing")
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(groups="sanity testing")
public void hello()
{
System.out.println("hello");
}
}
=======================================
‘Groups‘ is one more annotation of TestNG which can be used in the execution of multiple tests.
This annotation we need to declare at test level.
//Sample example on grouping mechanism in selenium testng
---------------------------------------------------------------------------------
Sample1.java
------------------
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 Sample1 {
WebDriver webDriver;
@Test(groups="regression testing")
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(groups="sanity testing")
public void hello()
{
System.out.println("hello");
}
}
Sample2.java
------------------
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 Sample2 {
WebDriver webDriver;
@Test(groups="regression testing")
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();
}
}
Sample3.java
------------------
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 Sample3 {
WebDriver webDriver;
@Test(groups="regression testing")
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();
}
}
Sample4.java
-------------------
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 Sample4 {
WebDriver webDriver;
@Test(groups="sanity testing")
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();
}
}
testng.xml:
------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
<test name="Test">
<groups>
<run>
<include name="regression testing">
</include>
<include name="sanity testing">
</include>
</run>
</groups>
<classes>
<class name="testngdemo.Sample1" />
<class name="testngdemo.Sample3" />
<class name="testngdemo.Sample2" />
<class name="testngdemo.Sample4" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
No comments:
Post a Comment