title: org.testng.TestNGException: An error occurred while instantiating class tests.LoginTests. Check to make sure it can be instantiated
body: <p>I've seen this issue here but after reviewing some of the issues I'm just getting confused. I'm trying to setup so that the driver can be passed into tests are they're made. It was throwing a null pointer exception after it opened the browser but then I added this:</p>
  <pre><code>public LoginTests(WebDriver driver) {
  
          this.driver = driver ;
          PageFactory.initElements(driver, this);
      }
  </code></pre>
  <p>which has been met with the current issue</p>
  <p>org.testng.TestNGException:
  An error occurred while instantiating class tests.LoginTests. Check to make sure it can be instantiated
  at org.testng.internal.InstanceCreator.createInstanceUsingObjectFactory(InstanceCreator.java:134)
  at org.testng.internal.InstanceCreator.createInstance(InstanceCreator.java:79)
  at org.testng.internal.objects.SimpleObjectDispenser.dispense(SimpleObjectDispenser.java:25)
  at org.testng.internal.objects.GuiceBasedObjectDispenser.dispense(GuiceBasedObjectDispenser.java:30)
  at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:112)
  at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:165)
  at org.testng.TestClass.getInstances(TestClass.java:122)
  at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:102)
  at org.testng.TestClass.init(TestClass.java:94)
  at org.testng.TestClass.(TestClass.java:59)
  at org.testng.TestRunner.initMethods(TestRunner.java:463)
  at org.testng.TestRunner.init(TestRunner.java:339)
  at org.testng.TestRunner.init(TestRunner.java:292)
  at org.testng.TestRunner.(TestRunner.java:223)
  at org.testng.remote.support.RemoteTestNG6_12$1.newTestRunner(RemoteTestNG6_12.java:33)
  at org.testng.remote.support.RemoteTestNG6_12$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_12.java:66)
  at org.testng.ITestRunnerFactory.newTestRunner(ITestRunnerFactory.java:55)
  at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:659)
  at org.testng.SuiteRunner.init(SuiteRunner.java:173)
  at org.testng.SuiteRunner.(SuiteRunner.java:107)
  at org.testng.TestNG.createSuiteRunner(TestNG.java:1300)
  at org.testng.TestNG.createSuiteRunners(TestNG.java:1276)
  at org.testng.TestNG.runSuitesLocally(TestNG.java:1125)
  at org.testng.TestNG.runSuites(TestNG.java:1063)
  at org.testng.TestNG.run(TestNG.java:1031)
  at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
  at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
  at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)</p>
  <p>BaseClass</p>
  <pre><code>package pages;
  
  import java.util.concurrent.TimeUnit;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;
  import org.openqa.selenium.edge.EdgeDriver;
  import org.openqa.selenium.firefox.FirefoxDriver;
  import org.testng.Reporter;
  import org.testng.annotations.BeforeMethod;
  import org.testng.annotations.BeforeTest;
  import org.testng.annotations.Parameters;
  import org.testng.annotations.Test;
  
  public class BaseClass {
      
      protected static WebDriver driver;
  
          /**
           * This function will execute before each Test tag in testng.xml
           * @param browser
           * @throws Exception
           */
          @BeforeTest
          @Parameters(&quot;browser&quot;)
          public void setup(String browserName) {
              Reporter.log(&quot;********* Browser Session Starter *********&quot;);
              if(browserName.equalsIgnoreCase(&quot;firefox&quot;)){
              //create firefox instance
                  System.setProperty(&quot;webdriver.gecko.driver&quot;, &quot;/usr/local/bin/geckodriver&quot;);
                  driver = new FirefoxDriver();
              }
              //Check if parameter passed as 'chrome'
              else if(browserName.equalsIgnoreCase(&quot;chrome&quot;)){
                  //set path to chromedriver.exe
                  System.setProperty(&quot;webdriver.chrome.driver&quot;,&quot;/usr/local/bin/chromedriver&quot;);
                  //create chrome instance
                  driver = new ChromeDriver();
              }
              //Check if parameter passed as 'Edge'
                      else if(browserName.equalsIgnoreCase(&quot;edge&quot;)){
                          //set path to Edge.exe
                          System.setProperty(&quot;webdriver.edge.driver&quot;,&quot;/usr/local/bin/msedgedriver&quot;);
                          //create Edge instance
                          driver = new EdgeDriver();
                      }
              
              driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
              driver.manage().window().maximize();
              //driver.close();
              
          }
          
  }
  </code></pre>
  <p>Test I'm trying to get working</p>
  <pre><code>package tests;
  
  
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.support.PageFactory;
  import org.testng.annotations.Parameters;
  import org.testng.annotations.Test;
  
  import pages.BaseClass;
  import pages.LoginPage;
  
  public class LoginTests extends BaseClass{
      
      public LoginTests(WebDriver driver) {
  
          this.driver = driver ;
          PageFactory.initElements(driver, this);
      }
      
      LoginPage login = new LoginPage();
  //  @Test
  //  public void testLoginMethod() throws Exception {
  //      login.driverInit(&quot;chrome&quot;);
  //      
  //      
  //  }
      @Test
      @Parameters (&quot;browser&quot;)
      public void testTestNG() throws Exception {
      
          login.loginURL();
          
      }
      
  }
  
  </code></pre>
  <p>LoginPage if needed:</p>
  <pre><code>package pages;
  
  import java.util.concurrent.TimeUnit;
  
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;
  import org.openqa.selenium.edge.EdgeDriver;
  import org.openqa.selenium.firefox.FirefoxDriver;
  import org.testng.Reporter;
  
  
  public class LoginPage extends BaseClass{
      public static WebDriver driver;
      
      public void loginURL() {
          driver.get(&quot;www.google.com&quot;);
          
      
      }
  
  }
  </code></pre>
  <p>POM:</p>
  <pre><code>
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;RemoteLock&lt;/groupId&gt;
    &lt;artifactId&gt;framework&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    
  &lt;dependencies&gt;
  
  &lt;dependency&gt;
    &lt;groupId&gt;org.testng&lt;/groupId&gt;
    &lt;artifactId&gt;testng&lt;/artifactId&gt;
    &lt;version&gt;6.8&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  
  &lt;!-- https://mvnrepository.com/artifact/log4j/log4j --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;log4j&lt;/groupId&gt;
      &lt;artifactId&gt;log4j&lt;/artifactId&gt;
      &lt;version&gt;1.2.17&lt;/version&gt;
  &lt;/dependency&gt;
  
   
  
  
  &lt;/dependencies&gt;
  
  &lt;/project&gt;
  
  </code></pre>