title: Sharing same selenium WebDriver between step definition files
body: <p>Right now we're working on adopting Cucumber to run functional tests on our Java8/Spring app. We want our step definition files to remain as DRY as possible and as such plan on using the same step definitions in different feature files. Since we are using a selenium <code>WebDriver</code> to drive our tests, we need to share the same driver between step definitions.</p>
  
  <p>To demonstrate why having multiple drivers is an issue for us, imagine a feature file that defines two steps: one to navigate to a page, and another to assert that a line appears on that page. If both steps happen to be defined in separate files, the first step definition will use its driver to navigate to the page. By the time the second step definition runs the assertion against its driver it hasn't navigated to the page (since those actions went to the other driver) and the test fails.</p>
  
  <p>We tried implementing a base class (that contains the driver) that each step definition file would extend. As it turns out Cucumber instantiates an instance of each step definition class, and therefore we end up with each step definition having different <code>WebDriver</code> instances.</p>
  
  <p>We thought about using Spring to inject an instance of the <code>WebDriver</code> in each step definition file, but I believe this would cause the same problem described above. </p>
  
  <p>I know that the singleton pattern can be used to achieve this, but ours seems like such a common problem and the singleton pattern feels like overkill. Is this actually the right way to approach it? Or am I missing something really obvious?</p>
  
  <p>Thank you in advance for your help!</p>