Guest User

Untitled

a guest
Apr 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. public static ArrayList<Object> getDataFromExcel() throws EncryptedDocumentException, InvalidFormatException, IOException
  2. {
  3. ArrayList<Object> al=new ArrayList<Object>();
  4. FileInputStream fis=new FileInputStream("E:\LoginData.xlsx");
  5. Workbook wb=WorkbookFactory.create(fis);
  6. Sheet sh=wb.getSheet("Logins");
  7. Row rows=sh.getRow(0);
  8. Cell cells=rows.getCell(0);
  9.  
  10. for(int rowCount=0;rowCount<sh.getLastRowNum();rowCount++)
  11. {
  12. String username=sh.getRow(rowCount).getCell(0).getStringCellValue();
  13. String password=sh.getRow(rowCount).getCell(1).getStringCellValue();
  14.  
  15. Object[] ob={username,password};
  16. al.add(ob);
  17.  
  18. }
  19. return al;
  20.  
  21. }
  22.  
  23. WebDriver driver;
  24.  
  25. @BeforeMethod
  26. public void setUp() {
  27. System.setProperty("webdriver.gecko.driver",
  28. "E:\All_JARs\geckodriver.exe");
  29. driver.get("https://www.facebook.com");
  30. driver.manage().window().maximize();
  31.  
  32. }
  33.  
  34. @Test(dataProvider = "fetchDatafromExcel")
  35. public void loginTest(String username, String password) {
  36.  
  37. driver.findElement(By.xpath("//input[@type='email']")).sendKeys(
  38. username);
  39. driver.findElement(By.xpath("//input[@type='password']")).sendKeys(
  40. password);
  41. driver.findElement(
  42. By.xpath("//input[@data-testid='royal_login_button']")).click();
  43.  
  44. }
  45.  
  46. @DataProvider(name = "fetchDatafromExcel")
  47. public Iterator<Object> fetchDatafromExcel()
  48. throws EncryptedDocumentException, InvalidFormatException,
  49. IOException {
  50. ArrayList<Object> testdata = ExcelUtilites.getDataFromExcel();
  51. return testdata.iterator();
  52.  
  53. }
  54.  
  55. @AfterMethod
  56. public void tearDown() {
  57. driver.quit();
  58. }
  59.  
  60. public class Credentials {
  61.  
  62. private String userName;
  63. private String password;
  64.  
  65. public Credentials() { }
  66.  
  67. public Credentials(String userName, String password) {
  68. this.userName = userName;
  69. this.password = password;
  70. }
  71.  
  72. public String getUserName() { return userName; }
  73.  
  74. public void setUserName(String userName) { this.userName = userName; }
  75.  
  76. public String getPassword() { return password; }
  77.  
  78. public void setPassword(String password) { this.password = password; }
  79. }
  80.  
  81. @Test(dataProvider = "dpit")
  82. public void f(Credentials cred) {
  83. System.out.println(cred.getUserName());
  84. System.out.println(cred.getPassword());
  85. }
  86.  
  87. @DataProvider(name = "dpit")
  88. public Iterator<Credentials[]> createData() {
  89.  
  90. Credentials[] s1arr = {new Credentials("hello", "hellopass")};
  91. Credentials[] s2arr = {new Credentials("bye", "byepass")};
  92.  
  93. List<Credentials[]> sm = new ArrayList<>();
  94. sm.add(s1arr);
  95. sm.add(s2arr);
  96.  
  97. return sm.iterator();
  98. }
Add Comment
Please, Sign In to add comment