title: Maintain and re-use existing webdriver browser instance - java
body: <p>Basically every time I run my java code from eclipse, webdriver launches a new ie browser and executes my tests successfully for the most part. However, I have a lot of tests to run, and it's a pain that webdriver starts up a new browser session every time. I need a way to re-use a previously opened browser; so webdriver would open ie the first time, then the second time, i run my eclipse program, I want it to simply pick up the previous browser instance and continue to run my tests on that same instance. That way, I am NOT starting up a new browser session every time I run my program. <br /><br />
  Say you have 100 tests to run in eclipse, you hit that run button and they all run, then at about the 87th test you get an error. You then go back to eclipse, fix that error, but then you have to re-run all 100 test again from scratch. <br /><br />
  It would be nice to fix the error on that 87th test and then resume the execution from that 87th test as opposed to re-executing all tests from scratch, i.e from test 0 all the way to 100. 
  Hopefully, I am clear enough to get some help from you guys, thanks btw. 
  <br /><br />
  Here's my attempt below at trying to maintain and re-use a webdriver internet explorer browser instance: <br /><br /></p>
  
  <pre><code>public class demo extends RemoteWebDriver { 
  
      public static WebDriver driver;
      public Selenium selenium;
      public WebDriverWait wait;
      public String propertyFile;
      String getSessionId;
  
  
      public demo() { // constructor
  
  
          DesiredCapabilities ieCapabilities = DesiredCapabilities
                  .internetExplorer();
          ieCapabilities
                  .setCapability(
                          InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                          true);
          driver = new InternetExplorerDriver(ieCapabilities);
  
  
          this.saveSessionIdToSomeStorage(getSessionId);
          this.startSession(ieCapabilities);
          driver.manage().window().maximize();
      }
  
      @Override
        protected void startSession(Capabilities desiredCapabilities) {
          String sid = getPreviousSessionIdFromSomeStorage();
          if (sid != null) {
            setSessionId(sid);
            try {
              getCurrentUrl();
            } catch (WebDriverException e) {
              // session is not valid
              sid = null;
            }
          }
          if (sid == null) {
            super.startSession(desiredCapabilities);
            saveSessionIdToSomeStorage(getSessionId().toString());
          }
        }
  
      private void saveSessionIdToSomeStorage(String session) {
          session=((RemoteWebDriver) driver).getSessionId().toString();
      }
  
      private String getPreviousSessionIdFromSomeStorage() {
          return getSessionId;
      }
  }
  </code></pre>
  
  <p><br />
  My hope here was that by overriding the startSession() method from remoteWebdriver, it would somehow check that I already had an instance of webdriver browser opened in i.e and it would instead use that instance as opposed to re-creating a new instance everytime I hit that "run" button in eclipse. <br /><br />
  I can also see that because I am creating a "new driver instance" from my constructor, since constructor always execute first, it creates that new driver instance automatically, so I might need to alter that somehow, but don't know how.<br /><br /></p>
  
  <p>I am a newbie on both stackoverflow and with selenium webdriver and hope someone here can help. <br /></p>
  
  <p>Thanks!</p>