title: How to execute cucumber test cases in parallel using Grid?
body: <p>After doing a fair amount of research on how to run Cucumber test cases in parallel, I found the following very useful article on the subject matter:</p>
  
  <p><a href="https://www.opencredo.com/2013/07/02/running-cucumber-jvm-tests-in-parallel/" rel="nofollow noreferrer">https://www.opencredo.com/2013/07/02/running-cucumber-jvm-tests-in-parallel/</a></p>
  
  <p>The article has some pretty good information to get you started working with a multi-threaded environment, including some code you can download from Github.</p>
  
  <p><a href="https://github.com/tristanmccarthy/Cucumber-JVM-Parallel" rel="nofollow noreferrer">https://github.com/tristanmccarthy/Cucumber-JVM-Parallel</a></p>
  
  <p>If I understand the article correctly the driver should be configurable to work with Grid, enabling you to run multiple test cases across multiple devices. After doing some testing with the code using a chromedriver, it does seem to work as described in the article. However, once it is configured to work with Grid the test cases no longer get executed in parallel. Instead, they are executed sequentially.</p>
  
  <p>Currently, I have Grid configured to have 1 hub and 2 nodes. Each node can have a maximum of 2 sessions at any given time.</p>
  
  <p>Note: Without Cucumber I'm able to successfully deploy multiple test cases across multiple devices, So I don’t think the problem is related to my grid setup.</p>
  
  <p>Here is a sample of the code related to the web driver:</p>
  
  <pre><code>static {
      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setJavascriptEnabled(true);
      capabilities.setBrowserName("chrome");
      capabilities.setPlatform(Platform.ANY);
      try {
          REAL_DRIVER = new RemoteWebDriver(new URL("http://xxx.xxx.xxx.xxx:4444/wd/hub"), capabilities);
      } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      REAL_DRIVER.manage().timeouts().pageLoadTimeout(3000, TimeUnit.SECONDS);
      REAL_DRIVER.manage().window().maximize();
      Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
  }
  
  public SharedDriver() {
      super(REAL_DRIVER);
  }
  
  @Override
  public void close() {
      if (Thread.currentThread() != CLOSE_THREAD) {
          throw new UnsupportedOperationException(
                  "You shouldn't close this WebDriver. It's shared and will close when the JVM exits.");
      }
      super.close();
  }
  </code></pre>
  
  <p>I suspect that if you use more than one browser type that you should be able to run the test cases on multiple devices (1 browser per device), but in my case I am on using Chrome driver. Does anyone know what might be preventing the test cases from being distributed across multiple devices or have any better understanding of how Grid works with cucumber? Please share any articles or information related to this problem.</p>