I'm trying to use data in multiple test data files in the same script here. Suppose there are 2 data files with login credentials (Login1.csv and Login2.csv).
I need to use credentials in Login1.csv in one environment (on-premise) and credentials in Login2.csv in another environment (cloud) and need to use data in both files in the same script. I have created 2 test cases there (test1 and test2) but I have about 50 test cases in the real project.
The script below is working fine for the first csv file (Login1.csv) but I'm not sure if it's possible to use credentials in Login2.csv in same script (in test1 and test2).
public class Test_Login2 {
@Test(dataProvider = "dp")
public void test1(HashMap<String, String> b) {
System.out.println(b.get("Username"));
System.out.println(b.get("Password"));
System.out.println("*************************");
// -------------other scripts----------------
}
@Test(dataProvider = "dp")
public void test2(HashMap<String, String> b) {
System.out.println(b.get("Username"));
System.out.println(b.get("Password"));
System.out.println("*************************");
// -------------other scripts----------------
}
@DataProvider(name = "dp")
public Object[][] dpmethod() throws Exception {
// test data file for one environment (on-premise)
String csvfile = "C:\\Users\\.....\\Login1.csv";
CSVReader reader1 = new CSVReader(new FileReader(csvfile));
//----------script for reading data in login1 file
// test data file for another environment (cloud)
String csvfile = "C:\\Users\\.....\\Login2.csv";
CSVReader reader2 = new CSVReader(new FileReader(csvfile));
//----------script for reading data in login2 file
}
}
Test_Login2and passdataas required to that methods from the new class.