title: Handling Single Sign On with Selenium WebDriver and TestNG
body: <p><strong>Conditions:</strong></p>
  
  <ul>
  <li>Different base urls for each test class.</li>
  <li>Same login credentials (sso) for each base url.</li>
  <li>Different data sets for each test class.</li>
  </ul>
  
  <p><strong>Problem:<br></strong>
  It passes <code>AMSValidation</code> but skips <code>SAPValidation</code>. It is saying <code>The FirefoxDriver cannot be used after quit() was called.</code>
  But upon running the tests per class, they pass.<br><br></p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>public abstract class Validation {
      // other variables
      public static WebDriver driver = new FirefoxDriver();
  
      public void doLogin() throws Exception {
          // something
      }
  
      public void validateDocuments(String portal, String navigation,
              String category, String title, String fileName) throws Exception {
          // driver is used here      
      }
  }
  
  public class AMSValidation extends Validation {
  
      @Parameters("baseUrl")
      @BeforeTest(alwaysRun = true)
      public void setUp(@Optional("https://website.com/ams/") String baseUrl)
              throws Exception {
  
          driver.manage().window().maximize();
          driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
          driver.get(baseUrl);
          doLogin();
      }
  
      @DataProvider
      public Object[][] getDataForAMS() throws Exception {
          // return test data for ams
      }
  
      @Test(dataProvider = "getDataForAMS")
      public void validateAMS(String portal, String navigation, String category,
              String title, String fileName) throws Exception {
          validateDocuments(portal, navigation, category, title, fileName);
      }
  
      @AfterTest(alwaysRun = true)
      public void tearDown() throws Exception {
          driver.quit();
      }
  }
  
  public class SAPValidation extends Validation {
  
      @Parameters("baseUrl")
      @BeforeTest(alwaysRun = true)
      public void setUp(@Optional("https://website.com/sap/") String baseUrl)
              throws Exception {
  
          driver.manage().window().maximize();
          driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
          driver.get(baseUrl);
          doLogin();
      }
  
      @DataProvider
      public Object[][] getDataForSAP() throws Exception {
          // return test data for sap
      }
  
      @Test(dataProvider = "getDataForSAP")
      public void validateSAP(String portal, String navigation, String category,
              String title, String fileName) throws Exception {
          validateDocuments(portal, navigation, category, title, fileName);
      }
  
      @AfterTest(alwaysRun = true)
      public void tearDown() throws Exception {
          driver.quit();
      }
  }
  </code></pre>
  
  <p><strong>testng.xml:</strong></p>
  
  <pre><code>&lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&gt;
  &lt;suite name="Validation Suite" verbose="2"&gt;
      &lt;test name="AMS Test"&gt;
          &lt;parameter name="baseUrl" value="https://website.com/ams/" /&gt;
          &lt;classes&gt;
              &lt;class name="com.website.tests.AMSValidation" /&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  
      &lt;test name="SAP Test"&gt;
          &lt;parameter name="baseUrl" value="https://website.com/sap/" /&gt;
          &lt;classes&gt;
              &lt;class name="com.website.tests.SAPValidation" /&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  &lt;/suite&gt;
  </code></pre>
  
  <p><strong>Log:</strong></p>
  
  <pre><code>PASSED: validateAMS("portal", "navigation", "category", "title", "filename")
  
  ===============================================
      AMS Test
      Tests run: 1, Failures: 0, Skips: 0
  ===============================================
  
  FAILED CONFIGURATION: @BeforeTest setUp("https://website.com/sap/")
  org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called.
  // rest of stack trace
  
  SKIPPED: validateSAP("portal", "navigation", "category", "title", "filename")
  
  ===============================================
      SAP Test
      Tests run: 1, Failures: 0, Skips: 1
      Configuration Failures: 1, Skips: 0
  ===============================================
  
  
  ===============================================
  Validation Suite
  Total tests run: 2, Failures: 0, Skips: 1
  Configuration Failures: 1, Skips: 0
  ===============================================
  </code></pre>