LambdaTest Community

Find answers, support, and inspiration from other users

LambdaTest Community

Data driven Selenium tests

I have created a Selenium test that runs fine, but the application is still in development. Is there a way to place all the element ids/cssSelector/Xpath in one excel sheet and then pass the ones i need to each methods.?

Up Vote Down Vote 4 Votes
Posted 5 months ago


I did achieve this using an excel quite simply I used the following method:

public void dataLocator() throws Exception{
          FileInputStream file = new FileInputStream(new File("dataSheets\\testing doc.xlsx"));

          //Create Workbook instance holding reference to .xlsx file
          XSSFWorkbook workbook = new XSSFWorkbook(file);

          //Get first/desired sheet from the workbook
          XSSFSheet sheet = workbook.getSheet("Marketing Project");

          //Iterate through each rows one by one assigning cell value to variable
          account = sheet.getRow(1).getCell(0).getStringCellValue();
          projectname = sheet.getRow(1).getCell(1).getStringCellValue() +timestamp;
          reqType = sheet.getRow(1).getCell(2).getStringCellValue() ;
          Language = sheet.getRow(1).getCell(3).getStringCellValue();
          assetType = sheet.getRow(1).getCell(4).getStringCellValue();
          needReview = sheet.getRow(1).getCell(5).getStringCellValue();
          reviewer = sheet.getRow(1).getCell(6).getStringCellValue() ;
          date = sheet.getRow(1).getCell(7).getDateCellValue();
          stringDate = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH).format(date);
          moreInfo = sheet.getRow(1).getCell(8).getStringCellValue();

Up Vote Down Vote 3 Votes
Posted 5 months ago
1 Answer
5 months ago