- Selenium Framework Design in Data-Driven Testing
- Carl Cocchiaro
- 129字
- 2025-02-18 04:59:04
CSV files
In many cases, data is stored in the CSV file format. CSV files have been used in automated testing for storing test data, environment data, mappings, and so on. The format is simple, and the data can be read using simple Java methods as outlined here:
/**
* extractData_CSV - method to extract CSV file data for use in testing
*
* @param csvFile - the CSV file to read
* @param rowID - The rowID to parse
* @return List<String>
* @throws Exception
*/
public static List<String> extractData_CSV(String csvFile,
String rowID)
throws Exception {
List<String> rows = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader(csvFile));
String line = "";
while ( (line = reader.readLine()) != null ) {
if ( line.startsWith(rowID)) {
rows.add(line);
}
}
reader.close();
return rows;
}