Given my .csv data file in format name:reference
:-
Johnson;464758,
Smith;839393,
Jones;940392,
Davidson;182939,
Arthurs;938494
And given my test code:
final static String DELIMITER = ",";
@DataProvider(name="references")
public Iterator<Object[]> refDataProvider(){
try{
Scanner scanner = new Scanner(new File(CSV_FILE)).useDelimiter(DELIMITER);
return new Iterator<Object[]>() {
@Override
public boolean hasNext() {
return scanner.hasNext();
}
@Override
public Object[] next() {
return new Object[]{scanner.next()};
}
};
}catch(FileNotFoundException e){
e.printStackTrace();
return null;
}
}
@Test(dataProvider = "references")
public void submitNewCustomers(String reference){
visit(customerHomePageUrl);
customerHomepagePage().selectCustomer();
customerSearchPage().typeInCustomerNumber(reference);
}
I only wish to pass the customer reference, not the name i.e. just 464758
to the DataProvider. Is there a way I can split the file using a further delimiter on the semi-colon ;
?