I am working on a project I am closing to being done with. I know my methods with and the code overall works, but I am stuck on how to read in a specific row or column from a CSV file.
Example - My CVS looks something like this...
- Title One, URL 1, Login1, Password1 |
- Title Two, URL 2, Login2, Password2 |
- Title Three, URL 3, Login3, Password3 |
- ...and so on
This is my @DataProvider that reads in the CSV file
//opens and reads in CVS file from resource folder
@DataProvider
public Iterator<Object[]> expectedTitles() throws IOException {
List<Object []>testData = new ArrayList<>();
String[] data = null;
BufferedReader br = new BufferedReader(new FileReader("src/main/resources/expectedTitles.csv"));
String line;
while ((line = br.readLine()) != null){
data = line.split(",");
testData.add(data);
}
return testData.iterator();
}
I also have a @Test method for every line of data in the CSV that looks something like this.
//executes sideNavAboutLink test
@Test(dataProvider = "expectedTitles")
public void sideNavAboutLink(String pageTitle){
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
AboutLink page = new AboutLink(driver);
page.loadPage();
page.clickSideAbout(); //clicks on link
page.validateURLSideNav(); //Validates URL
page.validateTitleSideNav(pageTitle); //Validates Page Title
}
Current this this all works more or less because I don't have my CSV filled out all the way yet it just has the pageTitle, but like I stated above I would like to be able to call any given row or column to get rid of redundant code. I have looks at some other examples but I haven't figured out how to adapt it to my code above.
Please any help would be great thank you.
