My Thoughts: Null point exception while running webdriver script

Monday, November 12

Null point exception while running webdriver script


Sometimes simple mistakes will take lot of time in debugging . I can bet on it :P
Today while runing a sample script I got errors like below :

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

Here is the script with syntax error:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class AutoComplete {
 
 WebDriver driver;
 
 @BeforeTest
 public void start(){
 WebDriver driver = new FirefoxDriver();
 }
 
 @Test
 public void AutoComplete()
 {
 driver.get("http://mythoughts.co.in/");
 driver.manage().window().maximize();
 }

}


I just overlooked the above script and thought everything is fine. But the issue got fixed when I remove the "WebDriver" statement from the line 13 and script ran successfully.

Here is the script which ran successfully.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class AutoComplete {
 
 WebDriver driver;
 
 @BeforeTest
 public void start(){
 driver = new FirefoxDriver();
 }
 
 @Test
 public void AutoComplete()
 {
 driver.get("http://mythoughts.co.in/");
 driver.manage().window().maximize();
 }

}


No comments:

Post a Comment