title: Sharing a WebDriver instance when using Selenium, TestNG, and Cucumber-JVM
body: <p>I am trying to add Cucumber-JVM to a TestNG and Selenium project I've been working on, where I currently re-use browsers on a grid via a testsuite something like this:</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="Grid" thread-count="2" parallel="tests"&gt;
      &lt;test name="Firefox 27.0"&gt;
          &lt;parameter name="browser" value="Firefox"/&gt;
          &lt;parameter name="browser_version" value="27.0"/&gt;
          &lt;packages&gt;
              &lt;package name="[Test package name]"/&gt;
          &lt;/packages&gt;
      &lt;/test&gt;
      &lt;test name="IE 11"&gt;
          &lt;parameter name="browser" value="IE"/&gt;
          &lt;parameter name="browser_version" value="11.0"/&gt;
          &lt;packages&gt;
              &lt;package name="[Test package name]"/&gt;
          &lt;/packages&gt;
      &lt;/test&gt;
  &lt;/suite&gt;
  </code></pre>
  
  <p>Each test class in the package then takes the parameters in a setUp method in the base class which looks like this:</p>
  
  <pre><code>@BeforeClass
  @Parameters({"browser", "browser_version"})
  public void setUp(String browser, String browser_version) throws MalformedURLException {
      // Do the setup with WebDriver and assign to an object property
  }
  </code></pre>
  
  <p>However, I'd like to have a static or injected class that is shared between all the test classes to avoid re-initialising the browser each time, which should also let me share the WebDriver instance between the various step definition files. Does anyone know how to do this?</p>