Data Driven Using TestNG
Am going to Read Data from excel sheet and fill the username and password of gmail.
Please find the source code below:
import java.io.FileInputStream;
import jxl.Sheet;
import jxl.Workbook;
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.Test;
public class EmailTest {
private WebDriver driver;
@BeforeClass
public void Startup() {
driver = new FirefoxDriver();
}
@Test(description = "Read Gmail account")
public void Login() throws Exception {
FileInputStream fi = new FileInputStream("E:\\testemail.xls");
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
driver.get("http://www.gmail.com");
try {
for (int i = 1; i < s.getRows(); i++) {
// Read data from excel sheet
String s1 = s.getCell(0, i).getContents();
String s2 = s.getCell(1, i).getContents();
driver.findElement(By.name("Email")).sendKeys(s1);
driver.findElement(By.name("Passwd")).sendKeys(s2);
driver.findElement(By.name("signIn")).click();
Thread.sleep(9000);
}
} catch (Exception e) {
System.out.println(e);
}
}
@AfterClass
public void teardown() {
driver.quit();
}
}
No comments:
Post a Comment