title: Selenium WebDriver NullPointerException while grabbing url
body: <p>I have found multiple answers to this issue but none that seem to help me here. When ever i run my test, I get a NullPointerException. I image it is a simple fix but I can't find it. </p>
  
  <p>Here is my set up class: </p>
  
  <pre><code>import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.firefox.FirefoxDriver;
  import org.testng.annotations.AfterClass;
  import org.testng.annotations.BeforeClass;
  import org.testng.annotations.Parameters;
  
  import java.util.Arrays;
  import java.util.concurrent.TimeUnit;
  
  import static org.junit.Assert.fail;
  
  public class TestSetUp {
  
  private WebDriver driver;
  
  protected StringBuffer verificationErrors = new StringBuffer();
  
  public WebDriver getDriver() {
      return driver;
  }
  
  private void setDriver(String type, String url) {
  
      switch (type) {
          case Config.FIREFOX_DRIVER:
              System.out.println("Setting drivers for Firefox...");
              driver = initFireFoxDriver(url);
              break;
          default:
              System.out.print("invalid browser type");
      }
  }
  
  private static WebDriver initFireFoxDriver(String url) {
      System.out.println("Launching Firefox browser...");
      WebDriver driver = new FirefoxDriver();
      driver.manage().window().maximize();
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      driver.navigate().to(url);
      return driver;
  }
  
  @BeforeClass
  @Parameters({"type","url"})
  public void initializeTestBaseSetup(String type, String url) {
      try {
          setDriver(type, url);
      } catch (Exception e) {
          System.out.println("Error....." + Arrays.toString(e.getStackTrace()));
      }
  }
  
  @AfterClass
  public void tearDown() {
      driver.quit();
      String verificationErrorString = verificationErrors.toString();
      if (!"".equals(verificationErrorString)) {
          fail(verificationErrorString);
      }
  }
  }
  </code></pre>
  
  <p>This is my LoginPage class where the error is being thrown:</p>
  
  <pre><code>import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  
  public class LoginPage {
  
  private WebDriver driver;
  
  public LoginPage(WebDriver driver) {
      this.driver = driver;
  }
  
  private String getLoginTitle() {
      return driver.getTitle();
  }
  
  public boolean verifyURL() {
  
      return driver.getCurrentUrl().contains("login");
  }
  
  public boolean verifyLoginTitle() {
      return getLoginTitle().contains(Config.TITLE + " - Log In");
  }
  
  public boolean verifySignInError() {
      enterUsername("test");
      enterPassword("pass");
      clickLogin();
      return getErrorMessage().contains("Incorrect Username or Password");
  }
  
  public boolean verifyForgotPassword() {
      return driver.findElement(Config.FORGOT_PASS_NODE).isDisplayed();
  }
  
  public boolean verifyLicencing() {
      Config.changeSetting("multi_license", 1, driver);
  
      return driver.findElement(Config.LIC_KEY_NODE).isDisplayed();
  }
  
  public boolean verifyCreateAccount() {
      Config.changeSetting("user_reg", 0, driver);
  
      if(driver.findElement(Config.CREATE_ACCOUNT_NODE).isDisplayed()) {
          return false;
      }
      else {
          Config.changeSetting("user_reg", 1, driver);
      }
  
      return driver.findElement(Config.CREATE_ACCOUNT_NODE).isDisplayed();
  }
  
  public HomePage signIn(String username, String password) {
      enterUsername(username);
      enterPassword(password);
      clickLogin();
  
      return new HomePage(driver);
  }
  
  public void enterUsername(String username) {
      WebElement identity = driver.findElement(Config.IDENTITY_NODE);
      if(identity.isDisplayed())
          identity.sendKeys(username);
  }
  
  public void enterPassword(String password) {
      WebElement pass = driver.findElement(Config.CREDENTIAL_NODE);
      if(pass.isDisplayed())
          pass.sendKeys(password);
  }
  
  public void clickLogin() {
      WebElement loginBtn = driver.findElement(Config.SUBMIT_NODE);
      if(loginBtn.isDisplayed())
          loginBtn.click();
  }
  
  public String getErrorMessage() {
      String errorMessage = null;
      WebElement errorMsg = driver.findElement(Config.DANGER_NODE);
      if(errorMsg.isDisplayed())
          errorMessage = errorMsg.getText();
      return errorMessage;
  }
  
  }
  </code></pre>
  
  <p>And finally my test case:</p>
  
  <pre><code>import org.junit.Assert;
  import org.junit.Before;
  import org.testng.annotations.Test;
  import org.openqa.selenium.WebDriver;
  
  public class LoginPageTest extends TestSetUp {
  
  private WebDriver driver;
  
  @Before
  public void setUp() {
      driver = getDriver();
  }
  
  @Test
  public void verifyLoginInFunction() {
      System.out.println("Log In functionality being tested...");
  
      LoginPage loginPage = new LoginPage(driver);
  
      try {
          Assert.assertTrue("The url is incorrect", loginPage.verifyURL());
      } catch (Error e) {
          verificationErrors.append(e.toString());
      }
  
      try {
          Assert.assertTrue("Title did not match", loginPage.verifyLoginTitle());
      } catch (Error e) {
          verificationErrors.append(e.toString());
      }
  
      try {
          Assert.assertTrue("Error message did not match", loginPage.verifySignInError());
      } catch (Error e) {
          verificationErrors.append(e.toString());
      }
  
      try {
          Assert.assertTrue("\'Forgot Password?\' link is missing", loginPage.verifyForgotPassword());
      } catch (Error e) {
          verificationErrors.append(e.toString());
      }
  
      try {
          Assert.assertTrue("Create Account setting not working", loginPage.verifyCreateAccount());
      } catch (Error e) {
          verificationErrors.append(e.toString());
      }
  
      try {
          Assert.assertTrue("Additional Licence Key setting not working", loginPage.verifyLicencing());
      } catch (Error e) {
          verificationErrors.append(e.toString());
      }
  
      HomePage homePage = loginPage.signIn(Config.STUDENT, Config.STUDENTPASS);
  
      try {
          Assert.assertTrue("Login did not work", homePage.verifyURL());
      } catch (Error e) {
          verificationErrors.append(e.toString());
      }
  }
  }
  </code></pre>
  
  <p>I have been trying and just do not know what is causing the issue. </p>