Below is the code for Mercury Tours Login functionality using Selenium WebDriver.
We are Providing Login Details from Excel Sheet.
package selenium_examples;
import java.io.FileInputStream;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample {
WebDriver driver = new FirefoxDriver();
public void login() throws BiffException, IOException, InterruptedException
{
FileInputStream fi=new FileInputStream("F:\\Sel1.xls");
Workbook WB = Workbook.getWorkbook(fi);
Sheet sheet = WB.getSheet("Sheet1");
System.out.println("Number of Rows in Excel Sheet =" +sheet.getRows());
for (int i=1;i
String s=sheet.getCell(0,i).getContents();
String t=sheet.getCell(1,i).getContents();
System.out.println("Username=" +s);
System.out.println("Password= " +t);
driver.get("http://newtours.demoaut.com/");
driver.findElement(By.name("userName")).sendKeys(s);
driver.findElement(By.name("password")).sendKeys(t);
driver.findElement(By.name("login")).click();
Thread.sleep(3000);
driver.findElement(By.linkText("SIGN-OFF")).click();
}
fi.close();
}
public static void main(String[] args) throws BiffException, IOException, InterruptedException
{
Sample s1=new Sample();
s1.login();
}
}
Output:-
Number of Rows in Excel Sheet =4
Username=mercury
Password= mercury
Username=mercury1
Password= mercury1
Username=mercury2
Password= mercury2
No comments:
Post a Comment