title: TestNG and Selenium - parallel execution issues
body: <p>I'm having some issues with parallel execution of tests using TestNG + Selenium (Chrome WebDriver). Basically, my tests don't actually appear to be truly executed in parallel.</p>
  
  <p><strong>Trying to achieve:</strong>
  Data being read from an Excel spreadsheet. All test cases in TestSuite.java should execute for every row of data, in separate WebDriver instances - running in parallel. E.g. testing 5 separate login/password combinations simultaneously in separate browser windows.</p>
  
  <p><strong>Simplified illustration:</strong></p>
  
  <pre><code>public class TestSuite {
      private String param;
  
      @DataProvider
      public static Object[][] provider() {
          return new Object[][] {{"1"},{"2"}};
      }
  
      @Factory(dataProvider = "provider")
      public TestSuite(String data) {
          this.param = data;
          System.out.println(String.format("[Thread: %d] TestSuite (%s)", Thread.currentThread().getId(), param));
          // Can't initialise webdriver instances here, different thread
      }
  
      @BeforeClass
      public void init() {
          System.out.println(String.format("[Thread: %d] BeforeClass (%s)", Thread.currentThread().getId(), param));
          // This is where I'm retrieving webdriver instances
      }
  
      @Test
      public void TC_001() {
          System.out.println(String.format("[Thread: %d] TC_001 (%s)", Thread.currentThread().getId(), param));
      }
  
      @Test
      public void TC_002() {
          System.out.println(String.format("[Thread: %d] TC_002 (%s)", Thread.currentThread().getId(), param));
      }
  }
  </code></pre>
  
  <p><em>TestNG.xml:</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" &gt;
  &lt;suite name="Suite" parallel="instances" group-by-instances="true"&gt;
    &lt;test name="Test"&gt;
      &lt;classes&gt;
        &lt;class name="TestSuite" /&gt;
      &lt;/classes&gt;
    &lt;/test&gt;
  &lt;/suite&gt;
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>[Thread: 1] TestSuite (1)
  [Thread: 1] TestSuite (2)
  [Thread: 11] BeforeClass (1)
  [Thread: 11] TC_001 (1)
  [Thread: 11] TC_002 (1)
  [Thread: 12] BeforeClass (2)
  [Thread: 12] TC_001 (2)
  [Thread: 12] TC_002 (2)
  </code></pre>
  
  <p>The main issue here is that my tests are clearly being executed SEQUENTIALLY. Can anyone explain what I have done wrong - what is the correct approach to achieve the desired outcome that I explained above?</p>