title: Selenium "no such session" error on TestNG testing.xml
body: <p>I am trying to run a simple test with crossbrowsers using testing.xml of TestNG. Script runs fine on the first run which is Chrome. But gives "no such session" error on the firefox test beginning. </p>
  
  <p>I simplified the codes to make it easy to read. I hope it helps.</p>
  
  <p>Here's my TestNG testing.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&gt;
  &lt;suite name="DefaultSuite" thread-count="1" parallel="tests"&gt;
      &lt;test name="ChromeTest"&gt;
          &lt;parameter name="browser" value="Chrome" /&gt;
          &lt;classes&gt;
              &lt;class name="loginTest"&gt;
              &lt;/class&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  
      &lt;test name="FirefoxTest"&gt;
          &lt;parameter name="browser" value="Firefox" /&gt;
          &lt;classes&gt;
              &lt;class name="loginTest"&gt;
              &lt;/class&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  &lt;/suite&gt;
  </code></pre>
  
  <p>And here's my code </p>
  
  <pre class="lang-java prettyprint-override"><code>public class loginTest {
      private static WebDriver driver;
  
      @BeforeTest
      @Parameters("browser")
      public void testSetup(String browser) throws Exception {
          //Check if parameter passed from TestNG is 'firefox'
          if(browser.equalsIgnoreCase("firefox")){
              driver = webBrowsers.browserAl("Firefox");
          }
          //Check if parameter passed as 'chrome'
          else if(browser.equalsIgnoreCase("chrome")){
              driver = webBrowsers.browserAl("Chrome");
          }
          else{
              //If no browser passed throw exception
              throw new Exception("Browser is not correct");
          }
      }
  
      @Test(priority=0)
      public void LoginTest(){
          driver.get("http://www.hurriyet.com.tr/");
      }
  
      @AfterTest
      public void kapat() {
          webBrowsers.closeDriver();
      }
  }
  </code></pre>
  
  <p>and finally my webBrowsers.class</p>
  
  <pre class="lang-java prettyprint-override"><code>public class webBrowsers {
      private static WebDriver driver = null;
      private static String browserName;
  
      public static WebDriver browserAl(String browserName) {
  
          if (browserName.equals("Firefox")) {
              if (driver == null) {
                  System.setProperty("webdriver.gecko.driver","./drivers/geckodriver.exe");
                  driver = new FirefoxDriver();
              }
          } else if (browserName.equals("Edge")) {
              if (driver == null) {
                  System.setProperty("webdriver.edge.driver", "./drivers/MicrosoftWebDriver.exe");
                  driver = new EdgeDriver();
              }
          } else if (browserName.equals("Chrome")) {
              if (driver == null) {
                  System.setProperty("webdriver.chrome.driver","./drivers/chromedriver.exe");
                  driver = new ChromeDriver();
              }
          }
          driver.manage().window().maximize();
          driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
          driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
          return driver;
      }
  
      public static void closeDriver() {
          driver.close();
      }
  }
  </code></pre>