Pages

Monday, February 10, 2014

Parameterization through testNG for selenium WebDriver

import java.util.Arrays;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;


public class ParameterizationExp {
static WebDriver driver;
 @DataProvider
 public Object[][] getData(){
Xls_Reader Data = new Xls_Reader("D://WebDriverTest//JunitProject//src//Data.xlsx");
int rowCount = Data.getRowCount("Data");
//System.out.println(rowCount);
int colCount = Data.getColumnCount("Data");
Object sampleData[][] = new Object[rowCount-1][colCount];
for(int i=2;i<=rowCount;i++) {
for(int j=0; j<colCount;j++) {
sampleData[i-2][j] = Data.getCellData("Data", j, i);
}

}
return sampleData;

 }

@BeforeClass
public static void initBrowser(){
driver = new FirefoxDriver();
}
@Test(dataProvider="getData")
public void SubmitForm(String name, String question, String color, String comment) {
driver.navigate().to("http://google.com");
driver.findElement(By.xpath("html/body/form/input")).sendKeys(name);
driver.findElement(By.xpath("html/body/form/p[1]/input")).sendKeys(question);
driver.findElement(By.xpath("html/body/form/p[2]/select")).sendKeys(color);
driver.findElement(By.xpath("html/body/form/p[4]/textarea")).sendKeys(comment);
driver.findElement(By.xpath("html/body/form/p[5]/input")).click();
}
@AfterClass
public void closeBroser() {
driver.quit();

}

}

No comments:

Post a Comment