title: Getting exception : selenium.NoSuchSessionException: Session ID is null. here i have used Localthread<webdriver> for parallel execution
body: <p>**Got below exception :
  org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()? Here i have used LocalThread for parallel test execution ,but while running multiple test within a class in one thread(not parallel execution)
  First test cases ran successfully and second and third got failed  **</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Console Output:
  
  [TestNG] Running:
    C:\Users\Afsar\AppData\Local\Temp\testng-eclipse--442788521\testng-customsuite.xml
  
  ****** In Before Method init method *********
  Driver instanceis created and  set current local thread
  Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 41879
  Only local connections are allowed.
  log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
  log4j:WARN Please initialize the log4j system properly.
  log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  Oct 22, 2017 5:03:12 PM org.openqa.selenium.remote.ProtocolHandshake createSession
  INFO: Detected dialect: OSS
  Set current thread method is called ..
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  *********Running first Test Case *********
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  **** Executing Logine Action *********
  URL is sent succesfully..
  Clicked on the Sign -on button 
  User name Entered 
  Password entered 
  Sign -in clicked 
  ****** Executing Register Action *********
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  Register button is found 
  PASSED : First test case : Login Successful..
  ****** In After Method tear down *********
  Removing driver instance from current thread and closing all sesions
  driver.quite called 
  ****** In Before Method init method *********
  Driver instanceis created and  set current local thread
  Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 47720
  Only local connections are allowed.
  Oct 22, 2017 5:03:39 PM org.openqa.selenium.remote.ProtocolHandshake createSession
  INFO: Detected dialect: OSS
  Set current thread method is called ..
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  *********Running second Test Case *********
  **** Executing Logine Action *********
  URL is sent succesfully..
  ****** In After Method tear down *********
  Removing driver instance from current thread and closing all sesions
  driver.quite called 
  ****** In Before Method init method *********
  Driver instanceis created and  set current local thread
  Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 25049
  Only local connections are allowed.
  Oct 22, 2017 5:03:45 PM org.openqa.selenium.remote.ProtocolHandshake createSession
  INFO: Detected dialect: OSS
  Set current thread method is called ..
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  Get curent thread method is called ..
  Current thread id :1 thread name is :main
  *********Running third  Test Case *********
  **** Executing Logine Action *********
  URL is sent succesfully..
  ****** In After Method tear down *********
  Removing driver instance from current thread and closing all sesions
  driver.quite called 
  Current thread removed and clearcurrentDriver() called.. ..
  PASSED: LoginFunctionality
          This is first test same as first 
  FAILED: LoginFunctionality1
          This is second test same as first 
  org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
  Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
  System info: host: 'AFSAR-PC', ip: '192.168.0.100', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
  Driver info: driver.version: RemoteWebDriver
   at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:131)
   at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
   at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
   at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:356)
   at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:410)
   at org.openqa.selenium.By$ByLinkText.findElement(By.java:246)
   at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
   at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
   at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
   at com.sun.proxy.$Proxy9.click(Unknown Source)
   at com.afsar.framework.pageobjects.MercuryToursHomePage.clickRegister(MercuryToursHomePage.java:58)
   at com.afsar.framework.actions.MercuryHomePage_Action.Login_Action(MercuryHomePage_Action.java:13)
   at com.afsar.framework.tests.LoginTest.LoginFunctionality1(LoginTest.java:56)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
   at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
   at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
   at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
   at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
   at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
   at org.testng.TestRunner.privateRun(TestRunner.java:767)
   at org.testng.TestRunner.run(TestRunner.java:617)
   at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
   at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
   at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
   at org.testng.SuiteRunner.run(SuiteRunner.java:240)
   at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
   at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
   at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
   at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
   at org.testng.TestNG.run(TestNG.java:1031)
   at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
   at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
   at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
  
  FAILED: LoginFunctionality2
          This is third test same as first 
  org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
  Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
  System info: host: 'AFSAR-PC', ip: '192.168.0.100', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
  Driver info: driver.version: RemoteWebDriver
   at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:131)
   at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
   at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
   at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:356)
   at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:410)
   at org.openqa.selenium.By$ByLinkText.findElement(By.java:246)
   at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
   at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
   at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
   at com.sun.proxy.$Proxy9.click(Unknown Source)
   at com.afsar.framework.pageobjects.MercuryToursHomePage.clickRegister(MercuryToursHomePage.java:58)
   at com.afsar.framework.actions.MercuryHomePage_Action.Login_Action(MercuryHomePage_Action.java:13)
   at com.afsar.framework.tests.LoginTest.LoginFunctionality2(LoginTest.java:67)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
   at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
   at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
   at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
   at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
   at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
   at org.testng.TestRunner.privateRun(TestRunner.java:767)
   at org.testng.TestRunner.run(TestRunner.java:617)
   at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
   at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
   at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
   at org.testng.SuiteRunner.run(SuiteRunner.java:240)
   at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
   at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
   at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
   at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
   at org.testng.TestNG.run(TestNG.java:1031)
   at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
   at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
   at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
  
  
  ===============================================
      Default test
      Tests run: 3, Failures: 2, Skips: 0
  ===============================================
  
  
  ===============================================
  Default suite
  Total tests run: 3, Failures: 2, Skips: 0
  ===============================================
  
  [TestNG] Time taken by org.testng.reporters.XMLReporter@49e4cb85: 407 ms
  [TestNG] Time taken by org.testng.reporters.EmailableReporter@5594a1b5: 75 ms
  [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@6e8dacdf: 19 ms
  [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1134affc: 373 ms
  [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 27 ms
  [TestNG] Time taken by org.testng.reporters.jq.Main@2f7c7260: 118 ms</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Login Test :
  
  public class LoginTest{
  
   private  WebDriver driver;
   @BeforeMethod
   @Parameters("BROWSER")
   public void init(@Optional("Chrome")String BROWSER) throws Exception{
    System.out.println("****** In Before Method init method *********");
    System.out.println("Driver instanceis created and  set current local thread");
    //Opening desired Browser driver instance
    driver=DriverFactory.OpenBrowser(BROWSER);
    //Setting Current driver with threadLocal
    Driver.setCurrentDriver(driver);
    Driver.getCurrentDriver().manage().window().maximize();
    Driver.getCurrentDriver().manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    //This is Baseclass constructor (Initializaton)
    new BaseClass(Driver.getCurrentDriver());
   }
   
   @Test(description="This is first test same as first ")
   public void LoginFunctionality() throws Exception{
    
    System.out.println("*********Running first Test Case *********");
    MercuryHomePage_Action.Login_Action();
    MercuryHomePage_Action.Register_Action();
    
    System.out.println("PASSED : First test case : Login Successful..");
    
   }
   
   @Test(description="This is second test same as first ")
   public void LoginFunctionality1() throws Exception{
    
    System.out.println("*********Running second Test Case *********");
    MercuryHomePage_Action.Login_Action();
    MercuryHomePage_Action.Register_Action();
    
    System.out.println("PASSED : second test case : Login Successful..");
    
   }
   
   @Test(description="This is third test same as first ")
   public void LoginFunctionality2() throws Exception{
    
    System.out.println("*********Running third  Test Case *********");
    MercuryHomePage_Action.Login_Action();
    MercuryHomePage_Action.Register_Action();
    
    System.out.println("PASSED : third test case : Login Successful..");
   }
   
   @AfterMethod
   public void teardown(){
    
    System.out.println("****** In After Method tear down *********");
    System.out.println("Removing driver instance from current thread and closing all sesions");
    //Driver.getCurrentDriver().quit();
    Driver.QuitDriver();
   }
   
   @AfterTest
   public void aftertest(){
    Driver.clearCurrentDriver();
   }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Driver Factory Class:
  public class DriverFactory {
  
   //private static WebDriver driver;
  
   //@Parameters("BROWSER")
   public static WebDriver OpenBrowser(String BROWSER) throws Exception{
     WebDriver driver=null;
    try{
     if(BROWSER.equals("Mozilla")){
      driver = new FirefoxDriver();
      Log.info("New driver instantiated");
      driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
      Log.info("Implicit wait applied on the driver for 10 seconds");
      //driver.get(Constant.URL);
      Log.info("Web application launched successfully");
     }else if(BROWSER.equalsIgnoreCase("Chrome")){
      System.setProperty("webdriver.chrome.driver", "C:\\Users\\Afsar\\git\\HybridFramework_POM\\HybridFramework\\Drivers\\chromedriver.exe");
      driver = new ChromeDriver();
      Log.info("New driver instantiated");
      driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
      Log.info("Implicit wait applied on the driver for 10 seconds");
      //driver.get(Constant.URL);
      Log.info("Web application launched successfully");
     }
    }catch (Exception e){
     Log.error("Class Utils | Method OpenBrowser | Exception desc : "+e.getMessage());
    }
    return driver;
   }
    
    </code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Driver class:
  
  private static  ThreadLocal&lt;WebDriver&gt; CURRENT_DRIVER = new ThreadLocal&lt;&gt;();
  
   public static WebDriver getCurrentDriver() {
    System.out.println("Get curent thread method is called .."); 
    Long callingThreadID = new Long(Thread.currentThread().getId());
    System.out.println("Current thread id :"+callingThreadID +" thread name is :"+Thread.currentThread().getName());
    return CURRENT_DRIVER.get();
   }
  
   public static void setCurrentDriver(WebDriver driver) {
    System.out.println("Set current thread method is called ..");
    CURRENT_DRIVER.set(driver);
   }
  
   public static void clearCurrentDriver() {
    
    System.out.println("Current thread removed and clearcurrentDriver() called.. ..");
    if (CURRENT_DRIVER.get() != null) {
     CURRENT_DRIVER.get().quit();
     CURRENT_DRIVER.remove();
          }
    
    CURRENT_DRIVER.remove();
   }
   
   public static void QuitDriver() {
    
    System.out.println("driver.quite called ");
    if (CURRENT_DRIVER.get() != null) {
     CURRENT_DRIVER.get().quit();
     //CURRENT_DRIVER.remove();
          }
    
    //CURRENT_DRIVER.remove();
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>*Please help me in this scenario ,you can find this project in the GitHub repository :
  <a href="https://github.com/afsarali273/HybridFramework_POM" rel="nofollow noreferrer">https://github.com/afsarali273/HybridFramework_POM</a> *</p>