Reputation: 146
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.?
Upvotes: 1
Views: 104
Reputation: 146
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();
workbook.close();
}
Upvotes: 1
Reputation: 14746
Sometime back I created a blog post that talks about using PageFactory, having the locators available in an external file such as JSON and then coupling both to work together. Here's the link.
Please see if that helps.
Upvotes: 0