Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

Getting NullPointer Exception running test using Selenium Webdriver

Solved 1 Answers 325 Views
0 1
I am running test using Selenium Webdriver in Java Language. My code is -:

public WebDriver driver;
    public String url="";
    public void setup() throws InterruptedException {
        System.setProperty("", "C://Selenium driver//chromedriver.exe");
           WebDriver driver = new ChromeDriver();
           driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     public void teardown() {
     public void vertifyTitle(){
         String title = driver.getTitle();
         Assert.assertEquals(title, "Google");

I am getting the following error message

FAILED: vertifyTitle
    at commonTests.MainTests.vertifyTitle(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.testng.internal.MethodInvocationHelper.invokeMethod(
    at org.testng.internal.Invoker.invokeMethod(
    at org.testng.internal.Invoker.invokeTestMethod(
    at org.testng.internal.Invoker.invokeTestMethods(
    at org.testng.internal.TestMethodWorker.invokeTestMethods(
    at org.testng.TestRunner.privateRun(
    at org.testng.SuiteRunner.runTest(
    at org.testng.SuiteRunner.runSequentially(
    at org.testng.SuiteRunner.privateRun(
    at org.testng.SuiteRunnerWorker.runSuite(
    at org.testng.TestNG.runSuitesSequentially(
    at org.testng.TestNG.runSuitesLocally(
    at org.testng.TestNG.runSuites(
    at org.testng.remote.RemoteTestNG.initAndRun(
    at org.testng.remote.RemoteTestNG.main(

1 Answer

Best answer

You are declaring and defining new driver instance at function level for the first function.

        WebDriver driver = new ChromeDriver();

It looks like you have another driver declared at class level. So you should use that. So your code should be as below.

         this.driver = new ChromeDriver();

Hope that helps!

answered by (151 points)
selected by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.