Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ArrayList<Object> getDataFromExcel() throws EncryptedDocumentException, InvalidFormatException, IOException
- {
- ArrayList<Object> al=new ArrayList<Object>();
- FileInputStream fis=new FileInputStream("E:\LoginData.xlsx");
- Workbook wb=WorkbookFactory.create(fis);
- Sheet sh=wb.getSheet("Logins");
- Row rows=sh.getRow(0);
- Cell cells=rows.getCell(0);
- for(int rowCount=0;rowCount<sh.getLastRowNum();rowCount++)
- {
- String username=sh.getRow(rowCount).getCell(0).getStringCellValue();
- String password=sh.getRow(rowCount).getCell(1).getStringCellValue();
- Object[] ob={username,password};
- al.add(ob);
- }
- return al;
- }
- WebDriver driver;
- @BeforeMethod
- public void setUp() {
- System.setProperty("webdriver.gecko.driver",
- "E:\All_JARs\geckodriver.exe");
- driver.get("https://www.facebook.com");
- driver.manage().window().maximize();
- }
- @Test(dataProvider = "fetchDatafromExcel")
- public void loginTest(String username, String password) {
- driver.findElement(By.xpath("//input[@type='email']")).sendKeys(
- username);
- driver.findElement(By.xpath("//input[@type='password']")).sendKeys(
- password);
- driver.findElement(
- By.xpath("//input[@data-testid='royal_login_button']")).click();
- }
- @DataProvider(name = "fetchDatafromExcel")
- public Iterator<Object> fetchDatafromExcel()
- throws EncryptedDocumentException, InvalidFormatException,
- IOException {
- ArrayList<Object> testdata = ExcelUtilites.getDataFromExcel();
- return testdata.iterator();
- }
- @AfterMethod
- public void tearDown() {
- driver.quit();
- }
- public class Credentials {
- private String userName;
- private String password;
- public Credentials() { }
- public Credentials(String userName, String password) {
- this.userName = userName;
- this.password = password;
- }
- public String getUserName() { return userName; }
- public void setUserName(String userName) { this.userName = userName; }
- public String getPassword() { return password; }
- public void setPassword(String password) { this.password = password; }
- }
- @Test(dataProvider = "dpit")
- public void f(Credentials cred) {
- System.out.println(cred.getUserName());
- System.out.println(cred.getPassword());
- }
- @DataProvider(name = "dpit")
- public Iterator<Credentials[]> createData() {
- Credentials[] s1arr = {new Credentials("hello", "hellopass")};
- Credentials[] s2arr = {new Credentials("bye", "byepass")};
- List<Credentials[]> sm = new ArrayList<>();
- sm.add(s1arr);
- sm.add(s2arr);
- return sm.iterator();
- }
Add Comment
Please, Sign In to add comment