Data driven framework in selenium webdriver using excel for login account for validating with multiple credentials

package SeleniumLearn;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;
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.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;

public class DataDrivenFramework {
    public WebDriver driver;
    public String str;
    
        
@Test
public void LoginRetesting() throws Exception{
    driver.get("http://www.seleniumlearn.com/user");
    driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);
    FileInputStream fi=new FileInputStream("C:\\lib\\TestData\\LoginRetesting.xls");
    Workbook w=Workbook.getWorkbook(fi);
    Sheet s=w.getSheet("Sheet1");
    for(int i=1; i < s.getRows(); i++)
    {
        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();
        Thread.sleep(5000);
    try{
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        driver.findElement(By.linkText("Log out")).click();
        System.out.println("Pass");
    }catch(Exception e){System.out.println("Fail");}
}    
}

 @BeforeTest
      public void beforeTest() {
           driver=new FirefoxDriver();
          driver.manage().window().maximize();
        /*System.setProperty("webdriver.chrome.driver","C:\\lib\\chromedriver.exe"); //--->chrome browser path
        driver=new ChromeDriver();*/
        
      }

  @AfterTest
  public void afterTest() {
     
  }

}

 

Comments