Understanding parallel=instances functionality

21 views
Skip to first unread message

garvita girotra

unread,
Nov 2, 2020, 9:26:07 AM11/2/20
to testng-users
Hi,

I am having understanding gap for parallel=instances functionality. Rest way of running tests in parallel is clear and i have implemented well.

As per documentation : parallel="instances": TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running in different threads.

I tried simple example below as per my understanding that just opens browser .

public class TestClass {
WebDriver driver;

@Test
public void method1() {
System.out.println("method 1");
driver = new ChromeDriver();
driver.quit();
}
}


public class ParallelExample {

TestClass tc1, tc2;

@Test
public void display() {
tc1 = new TestClass();
tc1.method1();

tc2 = new TestClass();
tc2.method1();
}
}



<suite name="Suite" configfailurepolicy="continue">
<test name="test run " parallel="instances" thread-count="2">
<classes>
<class name="testngrun.ParallelExample"/>
</classes>
</test>
</suite>


I thought i am making 2 instances so they will run in parallel but they are running sequentially. Can someone explains and share some example how parallel=instances works.

Thanks !!

Nisarg Dave

unread,
Nov 2, 2020, 10:28:47 AM11/2/20
to testng-users
When you use @Factory annotation to impose factory design pattern, this creates multiple instances of a test class based on conditions you give such as different test-data-set.

garvita girotra

unread,
Nov 4, 2020, 12:39:31 PM11/4/20
to testng-users
I tried it with factory annotation and it worked. Thank you !!
Reply all
Reply to author
Forward
0 new messages