how to retrieve value from specific columns of excel using spring rest - java

Below is my controller code and service code. The service code is returning only the last value of the map, though I am adding it in the for loop. Not sure what I missing. Also in the postman, I am not getting any response, just the success code as 200. At least I should be getting the last value. The expected output is the following:
"testCaseId": "TA_SCEN01",
"testCaseDescription" : some test
"executionStatus": "Yes",
"executionBrowser": "Chrome"
Please excuse me for the long desciption of the problem statement. I just tried to give as much info for better understanding.
the controller code is below
#RestController
public class ExcelController {
#Autowired
ExcelService service;
#GetMapping(value="/{excelSheetName}/{sheetName}", produces = "application/json")
public ResponseEntity<List<Map<String, String>>> getExcelDetails(#PathVariable("excelSheetName") String excelSheetName, #PathVariable("sheetName") String sheetName) {
service.getExcelDetails(excelSheetName, sheetName);
return new ResponseEntity<List<Map<String, String>>>(HttpStatus.OK);
}
}
The service code is below
public List<Map<String, String>> getExcelDetails(String excelSheetName, String sheetName) {
//Map<String, String> map = new LinkedHashMap<String, String>();
//List list = new LinkedList<Object>();
List list = new LinkedList<Object>();
String excelPath = "C:\\Users\\140117\\Desktop\\NSARF\\Successfactor_TalentAcquisition_TestCase.xls";
FileInputStream fis;
try {
fis = new FileInputStream(excelPath);
HSSFWorkbook workSheet = new HSSFWorkbook(fis);
HSSFSheet sheet = workSheet.getSheetAt(0);
ExcelDetail excelObj = new ExcelDetail();
String testId = "testCaseId";
String testDesc = "testCaseDescription";
String status = "executionStatus";
String browser = "executionBrowser";
for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
Map map = new LinkedHashMap();
//Map<String, String> map = new LinkedHashMap<String, String>();
Cell tcId = sheet.getRow(i + 1).getCell(0);
Cell desc = sheet.getRow(i+1).getCell(1);
Cell execStatus = sheet.getRow(i + 1).getCell(2);
Cell execBrowser = sheet.getRow(i+1).getCell(5);
if(null != tcId || null != desc || execStatus != null || execBrowser != null) {
map.put(testId, tcId.toString());
map.put(testDesc, desc.toString());
map.put(status, execStatus.toString());
map.put(browser, execBrowser.toString());
list.add(map);
}else {
break;
}
//list.add(map);
System.out.println(list);
}
//list.add(map);
System.out.println(list);
return list;
}

Related

Reduce number of arguments when calling from DataProviders in testng using java

I am reading the data from Excel file, let us say I have 5 rows and 15 columns in Java testNG.
Review the below code
Class ReadExcel {
public String[][] getCellData(String path, String sheetName) throws InvalidFormatException, IOException {
FileInputStream stream = new FileInputStream(path);
XSSFWorkbook workbook = new XSSFWorkbook(stream);
Sheet s = workbook.getSheet(sheetName);
int rowcount = s.getLastRowNum();
int cellcount = s.getRow(0).getLastCellNum();
String data[][] = new String[rowcount][cellcount];
FormulaEvaluator evaluator= workbook.getCreationHelper().createFormulaEvaluator();
DataFormatter df = new DataFormatter();
for (int i = 1; i <= rowcount; i++) {
Row r = s.getRow(i);
for (int j = 0; j < cellcount; j++) {
Cell c = r.getCell(j);
try {
if(c!=null){
if (c.getCellType() == c.CELL_TYPE_STRING) {
data[i - 1][j] = c.getStringCellValue();
}else if (c.getCellType() == c.CELL_TYPE_FORMULA) {
data[i - 1][j] = df.formatCellValue(c, evaluator);
}
else if (c.getCellType() == c.CELL_TYPE_BOOLEAN) {
data[i - 1][j] = df.formatCellValue(c, evaluator);
}
else{
data[i - 1][j] = String.valueOf(c.getNumericCellValue());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return data;
}
}
Another class for processing the data
public class Sample
{
ReadExcel read = new ReadExcel();
#DataProvider (parallel= true)
public String[][] getFilterValues() throws InvalidFormatException, IOException, InterruptedException{
return read.getCellData("fileLoc","fileName");
}
#Test(dataProvider = "getFilterValues")
public void verifyReports(String row, String name, String age, String lastname and so on...) throws Exception
{
System.out.println(FileName);
}
So, here I need to reduce the argument count in verifyReports method and should able to retrieve the entire records in the same method.
Note: Argument count may be changed in future.
So I tried with Map concept but I could not find out.
The main goal is to reduce the no. of arguments in verifyReports method. How to achieve this.
I achieved by using the below code. But it would be in 2D array in order to use it in testNG DataProviders
Below is the code, I tried using list of map.
public ArrayList<String> readHeader(String path, String sheetName) throws IOException
{
FileInputStream stream = new FileInputStream(path);
XSSFWorkbook workbook = new XSSFWorkbook(stream);
Sheet s = workbook.getSheet(sheetName);
int rowcount = s.getLastRowNum();
int cellcount = s.getRow(0).getLastCellNum();
ArrayList<String> al = new ArrayList<String>();
Row r = s.getRow(0);
for(int i=0;i<cellcount;i++)
{
Cell c = r.getCell(i);
al.add(c.getStringCellValue());
}
return al;
}
public ArrayList<HashMap<String,String>> getCellData(String path, String sheetName) throws InvalidFormatException, IOException {
//ExcelConfig ec = new ExcelConfig();
FileInputStream stream = new FileInputStream(path);
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
XSSFWorkbook workbook = new XSSFWorkbook(stream);
Sheet s = workbook.getSheet(sheetName);
int rowcount = s.getLastRowNum();
int cellcount = s.getRow(0).getLastCellNum();
FormulaEvaluator evaluator= workbook.getCreationHelper().createFormulaEvaluator();
DataFormatter df = new DataFormatter();
ArrayList<String> head = ec.readHeader(path, sheetName);
for (int i = 1; i <= rowcount; i++) {
HashMap<String,String> map = new HashMap<String,String>();
Row r = s.getRow(i);
for (int j = 0; j < cellcount; j++) {
Cell c = r.getCell(j);
try {
if(c!=null){
if (c.getCellType() == c.CELL_TYPE_STRING) {
map.put(head.get(j), c.getStringCellValue());
}else if (c.getCellType() == c.CELL_TYPE_FORMULA) {
map.put(head.get(j), df.formatCellValue(c, evaluator));
}
else if (c.getCellType() == c.CELL_TYPE_BOOLEAN) {
map.put(head.get(j), df.formatCellValue(c, evaluator));
}
else{
map.put(head.get(j), String.valueOf(c.getNumericCellValue()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
list.add(map);
}
return list;
}
public void multiRec() throws InvalidFormatException, IOException
{
ArrayList<HashMap<String, String>> map = read.getCellData(fileLoc,"ComparisonStatus");
for(HashMap<String, String> ls : map)
{
System.out.println(ls.get("Row"));
System.out.println(ls.get("FileName"));
}
}
Here, Row and FileName are Excel file header. So now I reduced the no. of arguments. But how to convert it to 2D array will be the task now.
The best way would be to create a class containing all the arguments as fields of the class. Let the class name be CellData
class CellData {
private String row;
private String name;
// and all other relevant fields..
}
In the getCellData method, create and initialize an object of CellData with the relevant values of each row and instead of returning String[][] return CellData[]. Then make the below changes:
#DataProvider (parallel= true)
public Object[][] getFilterValues() throws InvalidFormatException, IOException, InterruptedException{
CellData[] cellData = read.getCellData("fileLoc","fileName");
Object[][] data = new Object[cellData.length][];
for(int i = 0; i < cellData.length; i++) {
data[i][0] = cellData[i];
}
return data;
}
#Test(dataProvider = "getFilterValues")
public void verifyReports(CellData data) throws Exception
{
// test code.
}
Since you are saying that new arguments could be introduced in the future, using a class would be very much beneficial as it could help the code be maintainable and readable. Any future updates would also require much less code changes as there is no need of updating the DataProvider method or the test method. The only change would be a new field in the CellData class and setting the values for the new fields in getCellData method.

IndexOutOfBoundsException for automation

I am trying to automate an application. For that, i am using hash map for excel data set and i have created my methods for performing action on that data.
Class file to execute is shown below
#Test
public void testLAP_Creamix() throws Exception {
try {
launchMainApplication();
Lapeyre_frMain Lapeyre_frMainPage = new Lapeyre_frMain(tool, test, user, application);
HashMap<String, ArrayList<String>> win = CreamixWindowsDataset.main();
SortedSet<String> keys = new TreeSet<>(win.keySet());
for (String i : keys) {
System.out.println("########### Test = " + win.get(i).get(0) + " ###########");
Lapeyre_frMainPage.EnterTaille(win.get(i).get(1));
Lapeyre_frMainPage.SelectCONFIGURATION(win.get(i).get(2));
Lapeyre_frMainPage.SelectPLANVASQUE(win.get(i).get(3));
Lapeyre_frMainPage.SelectCOULEUR(win.get(i).get(4));
Lapeyre_frMainPage.SelectPOIGNEES(win.get(i).get(5));
Lapeyre_frMainPage.SelectTYPE_DE_MEUBLE(win.get(i).get(6));
Lapeyre_frMainPage.VerifyPanierPrice(win.get(i).get(7));
Lapeyre_frMainPage.VerifyECO_PARTPrice(win.get(i).get(8));
Lapeyre_frMainPage.ClickCREAMIXReinit();
System.out.println("########### Test End ##############");
}
test.setResult("pass");
} catch (AlreadyRunException e) {
} catch (Exception e) {
verificationErrors.append(e.getMessage());
throw e;
}
}
Hash Map code :
public static HashMap<String, ArrayList<String>> main() throws IOException {
final String DatasetSheet = "src/test/resources/CreamixDataSet.xlsx";
final String DatasetTab = "Creamix";
Object[][] ab = DataLoader.ReadMyExcelData(DatasetSheet, DatasetTab);
int rowcount = DataLoader.myrowCount(DatasetSheet, DatasetTab);
int colcount = DataLoader.mycolCount(DatasetSheet, DatasetTab);
HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
// i = 2 to avoid column names
for (int i = 2; i < rowcount;) {
ArrayList<String> mycolvalueslist = new ArrayList<String>();
for (int j = 0; j < colcount;) {
mycolvalueslist.add(ab[i][j].toString());
j++;
}
map.put(ab[i][0].toString(), mycolvalueslist);
i++;
}
return map;
}
Query: I was able to run this code few days back, but now after adding some new columns it is giving me below mentioned error.
IndexOutOfBoundsException Index 7 out of bounds for length 7
I am not able to trace the issue here, what should i look for? please help!
for (String i : keys) {
arr = win.get(i);//debug here,watch it size
Lapeyre_frMainPage.EnterTaille(arr.get(1));
}

Clear an arraylist after return statement

I have a method that returns an ArrayList. I want to clear or re-initialise the the array list after the return statement so that the old data is not repopulated. I know we can use arrayList.clear() statement but I am not sure where to place it in the code so that the re-initialization happens after returning the array list .
My code snippet :
public static List<HashMap<String, String>> GetDataIteration(String strDataSheetPath, String sTCID) {
HashMap<String, String> hm;
//List<Map<String, String>> hmList = new ArrayList();
//List<HashMap<String, String>> hmList = new ArrayList<HashMap<String, String>>();
try {
String sTestDataFile ="C:\\AutomationGoldCopy\\IEDSS_Automation\\src\\TestData\\Support\\Support_TC_001_AddUserBuildProfile1.xlsx";
File file = new File(sTestDataFile);
FileInputStream inputstream = new FileInputStream(file);
Workbook wb = null;
if (sTestDataFile.contains(".xlsx"))
{
wb = new XSSFWorkbook(inputstream);
} else if (sTestDataFile.contains(".xls"))
{
wb = new HSSFWorkbook(inputstream);
}
Sheet sheet = wb.getSheetAt(0);
int count = sheet.getPhysicalNumberOfRows() ;
System.out.println(count);
for (int i=1 ; i <count ; i++)
{
Row headerrow = sheet.getRow(0);
hm = new HashMap<String, String>();
System.out.println(i);
Row currentRow = sheet.getRow(i);
for (int j = 0; j < headerrow.getPhysicalNumberOfCells(); j++)
{
Cell currentCell = currentRow.getCell(j,Row.CREATE_NULL_AS_BLANK);
hm.put(headerrow.getCell(j).toString(), currentCell.toString());
}
//hmList.clear();
hmList.add(hm);
for (HashMap<String, String> h : hmList) {
for (String key : h.keySet()) {
System.out.println(key + "\t" + h.get(key));
}
System.out.println("\n");
}
// hmList.clear();
}
} catch (Exception e) {
System.out.println(e);
}
return hmList;
}
Kindly help me with the same.
main method :
public static void main(String[] args) {
String dtDataSheetPath = null;
String dtTestCaseID = null;
List<HashMap<String, String>> TestDataList = Excel.GetDataIteration(dtDataSheetPath,dtTestCaseID);
for(Map<String, String> TestData : TestDataList) {
String name = TestData.get("TestCase Name");
String name1 = TestData.get("SMU_LastName");
System.out.println( "Got it : " + name + " " + name1);
}
There are three rows in the excel . The first is the hearder row and the last two rows are the header values.
I am converting the excel rows into a hashmap with header row as keys and the second and third rows as values of the hashmap.
In the second run ( when i =2 ) , the first row is repopulated again. I just wanted the second row. When I clear the ArrayList hmList , it works fine but I wanted to return the list too.
In your function the initialization hmList = new ArrayList>(); creates a new empty List each time the function is called so there is no need to clear it after the return statement (which, anyway, is not possible in the same function).
As hmList seems to me a static variable you can return a copy of this list and clear the hmList before the return, if your specification says hmList should be empty by the return of your function.

How to retrive specific rows from a matrix returned by reading a CSV file in java

I want to retrieve some rows of a 2d array.
example: I have file named as "data.csv", which contains
age sex zipcode classtype
21 m 23423 1
12 f 23133 2
23 m 32323 2
23 f 23211 1
The below mentioned code will give output like this:
{age=[21,12,23,23],sex=[m,f,m,f],zipcode=[23423,23133,32323,23211],classtype=[1,2,2,1]}
Now I want to retrieve rows which have classtype 1 and store this values in a new 2d array.
like partition1={{21,m,23423,1},{23,f,23211,1}}
public class CsvParser {
public static void main(String[] args) {
try {
FileReader fr = new FileReader((args.length > 0) ? args[0] : "data.csv");
Map<String, List<String>> values = parseCsv(fr, " ", true);
System.out.println(values);
List<List<String>> partition1 = new ArrayList<>(25);
List<String> classTypes = values.get("classtype");
for (int row = 0; row < classTypes.size(); row++) {
String classType = classTypes.get(row);
if ("1".equals(classType)) {
List<String> data = new ArrayList<>(25);
data.add(values.get("age").get(row));
data.add(values.get("sex").get(row));
data.add(values.get("zipcode").get(row));
data.add(values.get("classtype").get(row));
partition1.add(data);
}
}
System.out.println(partition1);
} catch (IOException e) {
e.printStackTrace();
}
}
public static Map<String, List<String>> parseCsv(Reader reader, String separator, boolean hasHeader) throws IOException {
Map<String, List<String>> values = new LinkedHashMap<String, List<String>>();
List<String> columnNames = new LinkedList<String>();
BufferedReader br = null;
br = new BufferedReader(reader);
String line;
int numLines = 0;
while ((line = br.readLine()) != null) {
if (StringUtils.isNotBlank(line)) {
if (!line.startsWith("#")) {
String[] tokens = line.split(separator);
if (tokens != null) {
for (int i = 0; i < tokens.length; ++i) {
if (numLines == 0) {
columnNames.add(hasHeader ? tokens[i] : ("row_"+i));
} else {
List<String> column = values.get(columnNames.get(i));
if (column == null) {
column = new LinkedList<String>();
}
column.add(tokens[i]);
values.put(columnNames.get(i), column);
}
}
}
++numLines;
}
}
}
return values;
}
}
FileReader file1 = new FileReader(file);
BufferedReader buffer = new BufferedReader(file1);
String line = "";
while ((line = buffer.readLine()) != null) {
StringBuilder sb = new StringBuilder();
String[] str = line.split(",");
if(str[0]!=null||str[1]!=null||str[2]!=null){
sb.append("'" + str[0] + "',");
sb.append("'" +str[1] + "',");
sb.append("'" +str[2] + "'");
}
CSV File Must to be split comma based it should be work
Once I changed Map<String, List<String>> values = parseCsv(fr, "\\s,", true); to Map<String, List<String>> values = parseCsv(fr, " ", true); I was able to get the data in the right format...
From there it was just a matter to read through each row of classtype, when I found a value that matched 1, I would pull out each property for the given row and add it to a List, forming a single row. This was then added to another List which would maintain all the matching rows, for example...
List<List<String>> partition1 = new ArrayList<>(25);
List<String> classTypes = values.get("classtype");
for (int row = 0; row < classTypes.size(); row++) {
String classType = classTypes.get(row);
if ("1".equals(classType)) {
List<String> data = new ArrayList<>(25);
data.add(values.get("age").get(row));
data.add(values.get("sex").get(row));
data.add(values.get("zipcode").get(row));
data.add(values.get("classtype").get(row));
partition1.add(data);
}
}
System.out.println(partition1);
Which outputs...
[[21, m, 23423, 1], [23, f, 23211, 1]]
If you're looking for a more automated method, then I'm afraid you're out of luck, as Map makes no guarantee about the order that the keys are stored, iterated.
Of course, instead of using a List<List>, you could use a List<Map> which would maintain the keys for each value, for example...
List<Map<String, String>> partition1 = new ArrayList<>(25);
List<String> classTypes = values.get("classtype");
for (int row = 0; row < classTypes.size(); row++) {
String classType = classTypes.get(row);
if ("1".equals(classType)) {
Map<String, String> data = new HashMap<>(25);
for (String key : values.keySet()) {
data.put(key, values.get(key).get(row));
}
partition1.add(data);
}
}
System.out.println(partition1);
Which outputs...
[{sex=m, classtype=1, zipcode=23423, age=21}, {sex=f, classtype=1, zipcode=23211, age=23}]

How call variable from another class which is array?

I use Selenium Web Driver in Eclipse with IUnit. I have code which read data from excel file. Every column is presented as array. This is code:
class ReadExcel {
ArrayList path_name = new ArrayList();
ArrayList field_key = new ArrayList();
ArrayList field_name = new ArrayList();
ArrayList window_new = new ArrayList();
ArrayList link = new ArrayList();
lov_name = new ArrayList();
public void mai() {
int i = 0;
String path_namel = "", field_keyl = "", field_namel = "", window_newl = "", linkl = "", lov_namel = "";
String filename = "E:/data.xls";
if (filename != null && !filename.equals("")) {
FileInputStream fs = new FileInputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook(fs);
for (int k = 0; k < wb.getNumberOfSheets(); k++) {
int j = i + 1;
HSSFSheet sheet = wb.getSheetAt(k);
int rows = sheet.getPhysicalNumberOfRows();
for (int r = 1; r < rows; r++) {
HSSFRow row = sheet.getRow(r);
int cells = row.getPhysicalNumberOfCells();
HSSFCell cell1 = row.getCell(0);
path_namel = cell1.getStringCellValue();
HSSFCell cell2 = row.getCell(1);
field_keyl = cell2.getStringCellValue();
HSSFCell cell3 = row.getCell(2);
field_namel = cell3.getStringCellValue();
HSSFCell cell4 = row.getCell(3);
window_newl = cell4.getStringCellValue();
HSSFCell cell5 = row.getCell(4);
linkl = cell5.getStringCellValue();
HSSFCell cell6 = row.getCell(5);
lov_namel = cell6.getStringCellValue();
path_name.add(path_namel);
field_key.add(field_keyl);
field_name.add(linkl);
window_new.add(window_newl);
link.add(linkl);
lov_name.add(lov_namel);
}
i++;
}
}
}
}
In my selenium test I have such cycle:
for (int i=0; i<path_name.length; i++){
driver.findElement(By.xpath(path_name[i])).click();
}
Here I use variable path_name which is array and must be equal path_name from class ReadExcel. Actually I want use this values from excel as array. How should I call variable from ReadExcel?
Edit
I try use getter and setter methods.
int q;
String g;
public String getG() {
return g;}
public void setG(String g) {
this.g = g;}
public int getQ() {
return q;}
public void setQ(int q) {
this.q = q;}
q=path_name.size();
g=path_name.get(i).toString();
I my test I call variables in such way
ReadExcel h = new ReadExcel();
String k= h.getG();
ReadExcel p = new ReadExcel();
int n= p.getQ();
for (int j=0; j<n; j++){
driver.findElement(By.xpath(k)).click();}
Have no errors in editor, but cycle do not work. It should click on links (k), but have no effect.
Also I try this (was suggested in first answer)
ReadExcel readExcel = new ReadExcel();
ArrayList<String> path_name = readExcel.getPath_name();
for(String pathName: path_name){
driver.findElement(By.xpath(pathName)).click();
}
The same effect. It does not click on links
Can you convert your variable into field of that class? And then add a method there to return value of that field to anyone interested.
One way would be to implement setter() and getter() methods in your ReadExcel class for the variables that you want to access. And they would obviously be public methods.
Edit:
Guessing from what you've tried to update and my understanding, you're doing a lot of things wrong. Assuming that you're calling your last piece of code from another class, here's what you really should have done:
Also, I'm assuming that you've modified your ReadExcel class to look something like this
public class ReadExcel {
ArrayList<String> pathName = new ArrayList<String>();
ArrayList<String> fieldKey = new ArrayList<String>();
ArrayList<String> fieldName = new ArrayList<String>();
ArrayList<String> windowNew = new ArrayList<String>();
ArrayList<String> link = new ArrayList<String>();
public ReadExcel() {
pathName = new ArrayList<String>();
fieldKey = new ArrayList<String>();
fieldName = new ArrayList<String>();
windowNew = new ArrayList<String>();
link = new ArrayList<String>();
}
/**
* Not so sure of this method name. But make sure that this method is called before
* you try to call getXX() methods
*/
public void mai() {
String filename = "E:/data.xls";
if(fileName == null || "".equals(fileName))
return;
HSSFWorkbook workBook = null;
FileInputStream fileInputStream = null;
HSSFSheet sheet;
HSSFRow row;
int rows;
try{
fileInputStream = new FileInputStream(new File(fileName));
workBook = new HSSFWorkbook(fileInputStream);
for(int sheetIndex = 0; sheetIndex < workBook.getNumberOfSheets(); sheetIndex++){
sheet = workBook.getSheetAt(sheetIndex);
rows = sheet.getPhysicalNumberOfRows();
for(int rowIndex = 0; rowIndex < rows; rowIndex++){
/**
* Update with your own logic for retrieval
*/
row = sheet.getRow(rowIndex);
if(row.getPhysicalNumberOfCells() < 6)
continue;
pathName.add(row.getCell(0).getStringCellValue());
fieldKey.add(row.getCell(0).getStringCellValue());
fieldName.add(row.getCell(0).getStringCellValue());
windowNew.add(row.getCell(0).getStringCellValue());
link.add(row.getCell(0).getStringCellValue());
}
}
} catch (FileNotFoundException fileNotFoundException) {
fileNotFoundException.printStackTrace();
} catch (IOException ioException) {
ioException.printStackTrace();
}finally{
if(fileInputStream != null){
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
workBook = null;
}
}
}
/**
* The getter/setter methods for the variables
*/
public ArrayList<String> getPathName() {
return pathName;
}
public void setPathName(ArrayList<String> pathName) {
this.pathName = pathName;
}
public ArrayList<String> getFieldKey() {
return fieldKey;
}
public void setFieldKey(ArrayList<String> fieldKey) {
this.fieldKey = fieldKey;
}
public ArrayList<String> getFieldName() {
return fieldName;
}
public void setFieldName(ArrayList<String> fieldName) {
this.fieldName = fieldName;
}
public ArrayList<String> getWindowNew() {
return windowNew;
}
public void setWindowNew(ArrayList<String> windowNew) {
this.windowNew = windowNew;
}
public ArrayList<String> getLink() {
return link;
}
public void setLink(ArrayList<String> link) {
this.link = link;
}
}
And I hope that you're somewhere calling your mai() method (this name sounds really weird though) to retrieve the data from the excel and store them in the ArrayList before you're trying to call the following piece of code:
ReadExcel readExcel = new ReadExcel();
ArrayList<String> path_name = readExcel.getPath_name();
for(String pathName: path_name){
driver.findElement(By.xpath(pathName).click();
}
Some pointers to your code:
Use generics. Instead of defiing ArrayList pathNameList consider, using ArrayList<String> pathNameList
It looks good if you use Java Naming Convention when you code. One of them is to compose method names using mixed case letters, beginning with a lower case letter and starting each subsequent word with an upper case letter. So instead of having a getPath_name(), consider having something like getPathName() or even getPath_Name() (although most of us would prefer the 1st one). Here's a link that can help you with that.

Categories

Resources