Parameterization in TestNG Using DataProvider Annotation

package seleniumprograms;


import java.util.concurrent.TimeUnit;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class Parameterization {
WebDriver driver;

@BeforeMethod
public void setUp(){

System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"\\drivers\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://newtours.demoaut.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);

}

@Test(dataProvider="loginDataProvider")
public void search(String username, String password, String expTitle) {
driver.findElement(By.name("userName")).sendKeys(username);
driver.findElement(By.name("password")).sendKeys(password);
driver.findElement(By.name("login")).click();

Assert.assertEquals(driver.getTitle(), expTitle);
}

@DataProvider(name="loginDataProvider")
public Object[][] provideDataForLogin(){
Object[][] loginData = new Object[3][3];
loginData[0][0]= "admin";
loginData[0][1]= "admin";
loginData[0][2] = "Sign-on: Mercury Tours";
loginData[1][0]= "mercury";
loginData[1][1]= "admin";
loginData[1][2]= "Sign-on: Mercury Tours";
loginData[2][0]= "mercury";
loginData[2][1]= "mercury";
loginData[2][2] = "Find a Flight: Mercury Tours:";
return loginData;

}

@AfterMethod
public void tearDown(){
driver.quit();
}
}


Test Execution Report
=========================
PASSED: search("admin", "admin", "Sign-on: Mercury Tours")
PASSED: search("mercury", "admin", "Sign-on: Mercury Tours")
PASSED: search("mercury", "mercury", "Find a Flight: Mercury Tours:")

===============================================
    Default test
    Tests run: 3, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================


Comments

Post a Comment

Popular posts from this blog

Encoding and Decoding in Selenium using Base64 Class of Java

Parallel Execution In TestNG Framework Using ThreadLocal Concept

How to handle calendar or date picker using dynamic XPATH?