Skip to content

Instantly share code, notes, and snippets.

@Ramhm
Forked from charlottevaval/ExcelData
Created February 12, 2021 15:12
Show Gist options
  • Save Ramhm/faadb35ec16ed2c1a4b8ef74f933ac12 to your computer and use it in GitHub Desktop.
Save Ramhm/faadb35ec16ed2c1a4b8ef74f933ac12 to your computer and use it in GitHub Desktop.
Selenium login
Url Username Password Result
http://deltauat.managedmaint.com/auth/logout [email protected] test1234
http://deltauat.managedmaint.com/auth/logout [email protected] 125lkk
package MMIPackage;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class LoginTest {
@Test
public void login() throws IOException, Exception {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Charlotte\\selenium\\Driver\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
File src=new File("C:\\Users\\Charlotte\\selenium\\ExcelData\\LoginTest.xlsx");
FileInputStream fis=new FileInputStream(src);
XSSFWorkbook wb=new XSSFWorkbook(fis);
XSSFSheet sheet1=wb.getSheetAt(0);
String testUrl =sheet1.getRow(1).getCell(0).getStringCellValue();
String testUsername =sheet1.getRow(1).getCell(1).getStringCellValue();
String testPassword =sheet1.getRow(1).getCell(2).getStringCellValue();
driver.get(testUrl);
driver.findElement(By.id("email")).sendKeys(testUsername);
driver.findElement(By.id("password-text")).sendKeys(testPassword);
driver.findElement(By.id("Login")).click();
Thread.sleep(20000);
testUrl =sheet1.getRow(2).getCell(0).getStringCellValue();
testUsername =sheet1.getRow(2).getCell(1).getStringCellValue();
testPassword =sheet1.getRow(2).getCell(2).getStringCellValue();
driver.get(testUrl);
driver.findElement(By.id("email")).sendKeys(testUsername);
driver.findElement(By.id("password-text")).sendKeys(testPassword);
driver.findElement(By.id("Login")).click();
sheet1.getRow(1).createCell(3).setCellValue("Pass");
sheet1.getRow(2).createCell(3).setCellValue("Fail");
FileOutputStream fout=new FileOutputStream(src);
wb.write(fout);
wb.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment