How to automate login form using multiple users in selenium web driver in java.

Automate login form using multiple users in selenium web driver Task.

Data-driven automation using selenium web driver. Here is the automation example using selenium web driver where we are going to automate login form using 100 users in selenium web driver in java. Task description is given below.

Selenium web driver Task Description:

Need to automation a login form with 100 users. So the challenging part is you need to automate the same login form with 100 users.

Solution:

  • Create an excel file and write the username and password of 100 users.
  • Write the script to automate a login page with the loop count 100.
  • Create a separate method to read data and call the method when you need to get data from the excel file. The complete code is given below.

Automate login form using 100 users in selenium web driver in java.

import java.util.Properties;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import utilityClasses.TestListener;

publicclass Main {

 publicstatic XSSFSheet excelSheet;
 publicstatic XSSFCell cell;
 publicstatic WebDriver driver;

 publicstaticvoid main(String[] args) throws InterruptedException {

  System.setProperty("webdriver.chrome.driver", "D:\\Automation\\chromedriver_win32\\chromedriver.exe");
  driver = new ChromeDriver();
  
  excelSheet = Main.readExcel("Path of the excel file", "Sheet number");
  for (inti = 0; i<= 50; i++) {
   // Load URL getting.
   driver.get("http://erp.cisin.com/login.asp");
   // Locate element for login and password input and send data to inputs.
   driver.findElement(By.xpath("//*[@id=\"login-inner\"]/form/table/tbody/tr[1]/td/input"))
     .sendKeys(excelSheet.getRow(i).getCell(0).getStringCellValue());
   driver.findElement(By.xpath("//*[@id=\"login-inner\"]/form/table/tbody/tr[2]/td/input"))
     .sendKeys(excelSheet.getRow(i).getCell(1).getStringCellValue());
   // Click to the button for login.
   driver.findElement(By.xpath("//*[@id=\"login-inner\"]/form/table/tbody/tr[4]/td/input[1]")).click();
  }
  driver.close();
 }

 publicstatic XSSFSheet readExcel(String Path, String SheetName) {
  try {
   System.out.println(Path);
   // Open the Excel file
   FileInputStream ExcelFile = new FileInputStream(Path);
   // Access the required test data sheet
   ExcelWBook = new XSSFWorkbook(ExcelFile);
   ExcelWSheet = ExcelWBook.getSheet(SheetName);
  } catch (Exception e) {

   System.out.println(e);

  }
  returnExcelWSheet;
 }

}

Complete Automation tutorial using selenium web driver using java 

Add a Comment

Your email address will not be published. Required fields are marked *

16 − ten =