title: retryAnalyzer : "NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()" is thrown even new session has been re-created
body: <p>I am using TestNG version 6.9.10 and Selenium 3.8.1 with Java 1.8</p>
  
  <p>I use retryAnalyzer to keep restart my @Test if exception is thrown during the @Test. 
  Everytime exception is thrown somewhere in the middle of my @Test</p>
  
  <ol>
  <li>I catch it</li>
  <li>Write it to the log files</li>
  <li>Call <code>driver.quit()</code> </li>
  <li>And then re-throw it</li>
  <li>RetryAnalyzer will then stop the remaining codes and restart from the very beginning of my <code>@Test</code></li>
  <li>At the beginning of my <code>@Test</code> , I always check whether the browser is still open. If yes, just go the URL I want to test. If not, open a new Chrome driver and go to the test URL. </li>
  <li>At this step, a new Chrome browser will get started and the test URL will be displayed. </li>
  <li>But after that, I will not be able to execute the test (e.g. executing <code>driver.findElements()</code> ) , it will throw me exception <code>org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?</code>   even though I have recreated a new driver session (after destroying it). </li>
  </ol>
  
  <p>After destroying the driver session by using driver.quit() , can we recreate a new driver session by <code>WebDriver driver = new ChromeDriver();</code>  ?  or it is not the right way to recreate a new driver session? </p>
  
  <p>Here is my codes:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class myTest {
  
    private WebDriver driver;
  
    //This codes in BeforeTest below will initiate a new chrome driver session 
    @BeforeTest
    public void initiate() {
      System.setProperty("webdriver.chrome.driver", driverpathchrome);
      DesiredCapabilities caps = DesiredCapabilities.chrome();
      LoggingPreferences logPrefs = new LoggingPreferences();
      logPrefs.enable(LogType.BROWSER, Level.ALL);
      caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
      driver = new ChromeDriver(caps);
  
      driver.manage().window().maximize();
      driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
      driver.get("www.test.com");
      log.info("Chrome browser launched. Going to " + "www.test.com");
    }
  
  
    private boolean isBrowserOpen() {
      try {
        driver.getTitle();
        return true;
      } catch (Exception e) {
        return false;
      }
    }
  
    public boolean amISeeingLoginScreenNow() {
      if (driver.findElements(By.cssSelector(".login-box.smaller")).size() != 0) {
        return true;
      } else {
        return false;
      }
    }
  
    //This is the test methods
    @Test(retryAnalyzer = myTest.RetryAnalyzer.class)
    private void loginToTestURL() throws Exception {
  
      //This will check if the current browser session is still open. If not, then create a new driver session
      if (this.isBrowserOpen() == false) {
        Thread.sleep(3000);
  
        // Initiating new Browser 
        this.initiate();
      } else {
        driver.get("www.test.com");
      }
  
  
      this.method_will_not_throw_exception() {
        //some codes that will work OK
      }
  
  
      try {
        this.method_will_throw_exception() {
          //some codes that will throw exception
          this.amISeeingLoginScreenNow(); //In the 2nd try , at this stage, Selenium will get grumpy
        }
      } catch (Exception e) {
        //put exception in the log files then re-throw the exception
        //retryAnalyzer will get the exception and then start the test from the start of @Test
        driver.quit();
        throw new AssertionError();
      }
  
    }
  }
  </code></pre>
  
  <p>When exception is thrown, retryAnalyzer will start from @Test . I always re-create a new driver session by calling the <code>this.initiate();</code>  After that, a new browser session is started and go to test URL. So far so good. </p>
  
  <p>But when executing further codes such as <code>driver.findElements()</code> Selenium complains and give me </p>
  
  <pre><code>org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
  Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
  System info: host: 'DEV2015003', ip: '10.0.1.164', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
  Driver info: driver.version: RemoteWebDriver
      at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:131) ~[selenium-remote-driver-3.8.1.jar:?]
      at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) ~[selenium-remote-driver-3.8.1.jar:?]
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601) ~[selenium-remote-driver-3.8.1.jar:?]
      at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:398) ~[selenium-remote-driver-3.8.1.jar:?]
      at org.openqa.selenium.remote.RemoteWebDriver.findElementsByCssSelector(RemoteWebDriver.java:469) ~[selenium-remote-driver-3.8.1.jar:?]
      at org.openqa.selenium.By$ByCssSelector.findElements(By.java:441) ~[selenium-api-3.8.1.jar:?]
      at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:359) ~[selenium-remote-driver-3.8.1.jar:?]
      at myTest.myMainTest.amISeeingLoginScreenNow(SSDSearchPage.java:4219) ~[bin/:?]
  </code></pre>
  
  <p>I wonder why Selenium complains that Session ID is null. I have recreated a new session at the very beginning of my <code>@Test</code>. A new browser session appears and go to my test URL. That means a new driver session has been created successfully. But when executing <code>driver.findElements()</code> Selenium gets upset. 
  Any suggestions or pointers maybe?  </p>
  
  <p>If I didn't call driver.quit();  it will be OK. No problem. 
  But I want to restart the browser and get a new session everytime retryAnalyzer retries the test. 
  Thank You very much. </p>