Reputation: 4487
I want to run login test for 10 users. The user credentials are saved in an excel sheet. So, instead of running this test row after row, I want to run 3 in one go, means top 3 rows will have 3 dedicated chrome browsers launched, and then 3 more and then only 1.
But issue is, browsers picking data from different rows also.
To overcome this issue I tried using synchronized
keyword in Test Method but then browsers are not opening in parallel, they open sequentially, execute test and quit.
How can I fix this issue? I want one dedicated chrome browser for each row.
public class DemoParallelTesting{
WebDriver wdriver;
@BeforeMethod
public synchronized void parallelDemo() throws Exception {
// public void parallelDemo() throws Exception {
wdriver = new ChromeDriver();
wdriver.get("https://www.baseURL.com");
}
@Test(dataProvider = "loginData")
public void Registration_data(String testcasename, String sUserName, String sPassword) throws Exception {
// Do login
}
@DataProvider(name = "loginData", parallel = true)
public Object[][] getData() {
String filepath= System.getProperty("user.dir") + "/src/test/resources/testData/" + "loginData.xlsx";
Object data[][] = testData(filepath, "Sheet1");
return data;
}
public Object[][] testData(String filepath, String sheetName) {
// read excel file
return data;
}
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite" data-provider-thread-count="3">
<test name="DemoTest" parallel="methods">
<classes>
<class name="rough.DemoParallelTesting"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Upvotes: 1
Views: 991
Reputation: 176
Instead of picking up from the excel, use data provider class to do this test. Here, you need to change:
@Test(dataProvider = "loginData", dataProviderClass = DataProviderSource.class)
public void Registration_data(String testcasename, String sUserName, String sPassword) throws Exception {
// Do login
}
@DataProvider(parallel = true)
public static Object[][] loginData() {
Object[][] param = new Object[10][2];
param[0][0] = test_user1;
param[0][1] = passUser1;
param[1][0] = test_user2;
param[1][1] = passUser2;
param[2][0] = test_user3;
param[2][1] = passUser3;
}
Upvotes: 1