Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I have a test ready to be executed but it takes a long time to finish. In this test I'm feeding in csv data, so basically the whole test will run 56 times. I was wondering if there's anyway I could use multiple browser instance and divide the workload to four instance. It will save me some time. I tried to use TestNG's ThreadPoolSize but it's not doing what I want it to. It's using the same data for four instances of firefox. I want each browser to have it's own unique data. Please check my code and let me know what I'm missing. I really appriciate every one's help.

public class StudentPageTest {
WebDriver driver;
DesiredCapabilities capability; 
WebElement element;
WebDriverWait wait;
private String baseURL;

public void setUp() throws MalformedURLException{
//capability = DesiredCapabilities.firefox();
//driver = new FirefoxDriver();
//wait = new WebDriverWait(driver, 120);
baseURL = "http://somewebsite.com";

@Test(threadPoolSize = 4)
public void StudentPortalTest() throws InterruptedException, IOException{
driver = new FirefoxDriver();
wait = new WebDriverWait(driver, 120);
String studentId = "studentID.csv";
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";

br = new BufferedReader(new FileReader(studentId));
while ((line = br.readLine()) != null) {
    String[] student_id = line.split(cvsSplitBy);

    //Logging in Student Portal---------------------------------------------------------------------------------------------------------------|
    for (int i = 0; i < student_id.length; i++) {       
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
               n      driver.findElement(By.cssSelector("#Password")).sendKeys("EvenMoreSecretPassword");
        driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
       ...............and the test goes on below................... 
public void tearDown(){
share|improve this question
BTW, you use Thead.sleep(). This is an anti-pattern in test automation (see more at sqa.stackexchange.com/questions/3764/…) –  dzieciou Jun 6 at 21:24

1 Answer 1

Your have four threads, each running test in a separate browser instance, but reading whole file again and again. This is because each thread knows nothing about what test data other threads used.

A solution to the problem is to move loading and distributing test data among threads outside the test so that something else passes test data D1 to thread T1, D2 to T2, etc.

In TestNG this boils down to just a few steps:

  1. Implementing @DataProvider annotated method that will load test data from file (see sample implementation here)
  2. Telling @DataProvider method to run in parallel as well

    @DataProvider(name = "loadData", parallel = true)
  3. Telling the test to use the defined data provider but omitting threadPoolSize parameter.

    @Test(dataProvider =  "loadData")
  4. Configuring how many data provider instances in parallel must be run:

    Parallel data providers running from an XML file share the same pool of threads, which has a size of 10 by default. You can modify this value in the tag of your XML file:

      <suite name="Suite1" data-provider-thread-count="20" >
share|improve this answer
There may be some value in running some of those tests in a different process in case the test crashes. –  user246 Jun 7 at 16:59
@user246, that would require parallelization on a lavel of CI server (e.g., Jenkins), right? –  dzieciou Jun 7 at 18:26
That would be one way. Another would be to build a fork/exec capability into the test runner, with results delivered over a socket or something. I'll bet someone's already done that with JUnit/TestNG. –  user246 Jun 7 at 18:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.