title: Cucumber-jvm shared Driver example
body: <p>Do somebody have a sharedDriver example with cucumber-jvm? SharedDriver has implemented as described by Ashlak, but how can I instantiate the driver and share between steps, page objects?</p>
  
  <p>Shared driver class:</p>
  
  <pre><code>public class SharedDriver extends EventFiringWebDriver {
      private static final WebDriver REAL_DRIVER = WebDriverFactory.create();
  
      private static final Thread CLOSE_THREAD = new Thread() {
          @Override
          public void run() {
              REAL_DRIVER.quit();
          }
      };
  
      static {
          Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
      }
  
      public SharedDriver() {
          super(REAL_DRIVER);
      }
  
      @Override
      public void quit() {
          if (Thread.currentThread() != CLOSE_THREAD) {
              throw new UnsupportedOperationException("You shouldn't quit this WebDriver. It's shared and will quit when the JVM exits.");
          }
          super.quit();
      }
  
      @Before
      public void deleteAllCookies() {
          manage().deleteAllCookies();
      }
  
      @After
      public void embedScreenshot(Scenario scenario) {
          try {
              byte[] screenshot = getScreenshotAs(OutputType.BYTES);
              scenario.embed(screenshot, "image/png");
          } catch (WebDriverException somePlatformsDontSupportScreenshots) {
              System.err.println(somePlatformsDontSupportScreenshots.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>If I have a LoginPage, Registration page with steps class, how should I use this sharedDriver?</p>
  
  <p>Thanks!</p>