How Create Data Driven Framework using Selenium WebDriver with Java ?

package SeleniumLearn.COM;
import org.testng.annotations.Test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.concurrent.TimeUnit;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class TechLearn_Login_Retesting_Results {
public class Login_ReTesting_Results {
public WebDriver driver;
public String str;
@Test
      public void TechLearn_Login_Retesting_Result() throws Exception{
        FileInputStream fi=new FileInputStream("/home/chinna/Selenium/Testdata/Login.xls"); // Add your LoginCredentials.xls sheet
        Workbook w=Workbook.getWorkbook(fi);
        Sheet s=w.getSheet(0);
        FileOutputStream fo=new FileOutputStream("/home/chinna/Selenium/Testdata/LoginResults.xls"); //Add your LoginResults.xls sheet (Empty Sheet)
        WritableWorkbook wb=Workbook.createWorkbook(fo);
        WritableSheet ws=wb.createSheet("Results", 0);
    for (int i = 1; i < s.getRows(); i++) {
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        driver.get("http://www.techlearn.in/user");
        driver.findElement(By.id("edit-name")).sendKeys(s.getCell(0, i).getContents());
        driver.findElement(By.id("edit-pass")).sendKeys(s.getCell(1, i).getContents());
        driver.findElement(By.id("edit-submit")).click();
    try{
        driver.findElement(By.linkText("Log out")).click();
        str="Pass";
       }
    catch(Exception e){str="Fail";}
        Label result=new Label(2,i,str);
        ws.addCell(result);
    for (int j = 0; j < s.getColumns(); j++) {
        System.out.println(s.getCell(j, i).getContents());
        Label un=new Label(j, i, s.getCell(j, i).getContents());
        ws.addCell(un);
        }}
      Label un=new Label(0,0,"Username");
      Label pw=new Label(1,0,"Password");
      Label rs=new Label(2,0,"Result");
     
      ws.addCell(un);
      ws.addCell(pw);
      ws.addCell(rs);
      wb.write();
      wb.close();
      }
@BeforeTest
      public void beforeTest() {
      driver=new FirefoxDriver();
         // System.setProperty("webdriver.chrome.driver","/home/chinna/lib/chromedriver"); //--->chrome browser path
         // driver=new ChromeDriver();
          driver.manage().window().maximize();}
@AfterTest
      public void afterTest() {
      }
       }
    }

 
 

Tags: