I am new to Selenium Webdriver Testng and trying to Develop Data Driven framework using CSVReader
I have 5 tests in Testng and have to run those all on different environments. So basically I have to pick a different url and client, but other pages, elements remain same.
My Question is, Where do I put while loop so that it reads first line and execute all the tests and then read second line and so on.
I tried initialize CSV reader at class level, before suite, before method etc. but it throws error, it works for a particular test if I am putting inside @Test
but that doesn't resolve the purpose, I couldn't find any relevant answer on the internet.
Below is the high level code:
public class Portal1 {
WebDriver driver;
@BeforeSuite
public void beforeMethod() {
}
@BeforeTest
public void SetUp() {
config = new Configreader();
}
@DataProvider(name = "TestData")
public Object [][] getData() { Object [][]
data=new Object[2][2];
data[0][0]="url1";
data[0][1]="client1";
data[1][0]="url2";
data[1][1]="client2";
return data;
}
@Test(dataProvider = "TestData",priority =0)
public void RI_Select_an_Employer_page(String url,String client) throws Exception {
driver.get(url);
}
@Test(dataProvider = "TestData",priority =1)
public void RI_Employer_Information_page(String url,String client) {
WebElement linkclient = driver.findElement(By.linkText(client));
linkclient.click();
@AfterMethod
public void tearDown(ITestResult result) {
}
@AfterSuite
public void tearDown() {
driver.quit();
}