title: How to stop tests in selenium using webdriver (JavaScript)?
body: <p>I am running two tests using selenium webdriver in nodejs. I want first test to stop and then run the second one. But issues is that driver.close throws exception.</p>
  
  <pre><code>var webdriver = require('selenium-webdriver'),
      By = webdriver.By,
      until = webdriver.until;
  
  var driver = new webdriver.Builder()
      .forBrowser('chrome')
      .build();
  
  driver.get('https://www.website.com/');
  
  var values = [{email:'correctuser@website.com',password:'correct'},{email:'wronguser@website.com',password:'wrong'}];
  
  
  testCase(values[0].email,values[0].password);
  
  // driver.close throws exception
  driver.close();
  
  testCase(values[1].email,values[1].password);
  
   function testCase(email,password){
    driver.wait(until.urlIs('https://www.website.com/'))
    driver.findElement(By.id('inputEmail')).clear();
    driver.findElement(By.id('inputEmail')).sendKeys(email);
    driver.findElement(By.id('inputPassword')).clear();
    driver.findElement(By.id('inputPassword')).sendKeys(password);
    driver.findElement(By.tagName('button')).click().then(()=&gt;{
      driver.wait(until.elementLocated(By.className('alert-danger'))).then(() =&gt;{
        console.log('Failed login case - success');
      }).catch((e)=&gt;{
        console.log(e);
      });
      driver.wait(until.urlIs('https://www.website.com/home')).then(() =&gt; {
        console.log('Successful login case - success');
      }).catch((e)=&gt;{
        console.log(e);
      });
    });
  
  }
  </code></pre>
  
  <p>Error Message :</p>
  
  <pre><code>(node:1296) UnhandledPromiseRejectionWarning: NoSuchSessionError: invalid session id
    (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Mac OS X 10.13.6 x86_64)
  </code></pre>
  
  <p>Expected Result should be :</p>
  
  <pre><code>- Successful login case - success
  - Failed login case - success
  </code></pre>