Friday, 5 February 2016

test case priority in selenium using testng

test case priority in selenium using testng:
=================================
Based on our requirements we can execute the test cases based on priority level using testng framework.

If we dont assign any priority to testcases defaulty it will asssign to zero.
Testng executes the priority test cases from high priority to low priority ie 1......n

'1' will be the highest priority..ie while running; lower priorities will be scheduled first.

We can give priority at test case level using priority attribute.

It will always take integer as an argument.

example:

-----------
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(priority=1)
public void testScript1() 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(priority=2)
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("rameshselenium.blogspot.in");
webDriver.findElement(By.linkText("Parallel execution in selenium webdriver")).click();
webDriver.quit();
}
@Test(priority=3)
public void testScript3()
{
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();
}

}
conclusion:
================
execution order:
=============
testScript1
testScript2
testScript3

No comments:

Post a Comment