In case of DataDriven Concept,We have to Read Data from Excel sheets.This post helps you to Read Data from Excel files.
This is the Sample Test Data . Please improvise.
Click Here to Download TestData
import java.io.File;
import java.io.FileInputStream;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.firefox.FirefoxDriver;
import jxl.Sheet;
import jxl.Workbook;
public class excelyahoo
{
public static void main(String[] args) throws Exception
{
FileInputStream fs= new FileInputStream(“d:\\sample.xls”);
Workbook wb=Workbook.getWorkbook(fs);
Sheet s=wb.getSheet(0);
for ( int r=1; r<s.getRows(); r++)
{
FirefoxDriver fd =new FirefoxDriver();
fd.get(“http://www.yahoomail.com”);
Thread.sleep(4000);
fd.findElementByName(“login”).sendKeys(s.getCell(0, r).getContents());
fd.findElementByName(“passwd”).sendKeys(s.getCell(1, r).getContents());
fd.findElementByXPath(“.//*[@id=’pLabelC’]”).click();
fd.findElementByName(“.save”).click();
Thread.sleep(5000);
try {
if (fd.findElementByLinkText(“Sign Out”).isDisplayed());
{
System.out.println(“login is success”);
fd.findElementByLinkText(“Sign Out”).click();
}
}
catch (Exception e)
{
String str= fd.findElementByXPath(“.//*[@id=’fsLogin’]/div/strong”).getText();
System.out.println(str);
File f=fd.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(f, new File(“d:\\yahooSS”+r+”.jpg”));
}
fd.close();
}
}
}
Wonderful…thank you…i was trying to use POM, using data driven model..this method will help me a lot…great work..
LikeLike
Glad it helped
LikeLike