Hi,
I asked above question because my script was giving error for CSVReader, It said either create enum/class/interface named CSVReader or change it to ClassReader when i moved and highlighted CSVReader. (I am not sure what to choose from above or how to proceed)
I am able to find an answer on my own after trial and error and referring below thread:
http://stackoverflow.com/questions/14135286/read-data-from-csv-file-using-java-in-webdriverSo the solution is if you are not using CSVReader and following the framework Tarun has explained, use below code to read from CSV file:
@DataProvider(name = "regCSVdata")
public static Object[][] getlogindata() throws IOException {
int i=0;
File file = new File("<path for CSV file>");
//CSVReader reader new CSVReader(new FileReader (WellbeingData.class.getResource("/regdata.csv").getPath()));
BufferedReader bufrder = new BufferedReader(new FileReader(file));
String line = null;
List<WellbeingData> reglist = new ArrayList<WellbeingData>();
while((line = bufrder.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line,",");
while(st.hasMoreTokens()) {
WellbeingData data = new WellbeingData();
data.setusername(st.nextToken());
data.setpassword(st.nextToken());
reglist.add(data);
i++;
}
}
Object[][] data1 = new Object[i][1];
for(int j=0; j<data1.length; j++) {
for(int k=0; k<data1[j].length; k++) {
data1[j][k] = reglist.get(j);
}
}
bufrder.close();
return(data1);
}
I hope this will help somebody. Let me know anybody has any comments.
Thanks.