Wednesday, 3 July 2013

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:
  1. import org.openqa.selenium.WebDriver;  
  2. import org.openqa.selenium.firefox.FirefoxDriver;  
  3. import org.openqa.selenium.firefox.FirefoxProfile;  
  4. import org.testng.annotations.BeforeTest;  
  5. import org.testng.annotations.Test;  
  6.   
  7. public class AutoComplete {  
  8.    
  9.  WebDriver driver;  
  10.    
  11.  @BeforeTest  
  12.  public void start(){  
  13.  WebDriver driver = new FirefoxDriver();  
  14.  }  
  15.    
  16.  @Test  
  17.  public void AutoComplete()  
  18.  {  
  19.  driver.get("http://mythoughts.co.in/");  
  20.  driver.manage().window().maximize();  
  21.  }  
  22.   
  23. }  
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.
  1. import org.openqa.selenium.WebDriver;  
  2. import org.openqa.selenium.firefox.FirefoxDriver;  
  3. import org.openqa.selenium.firefox.FirefoxProfile;  
  4. import org.testng.annotations.BeforeTest;  
  5. import org.testng.annotations.Test;  
  6.   
  7. public class AutoComplete {  
  8.    
  9.  WebDriver driver;  
  10.    
  11.  @BeforeTest  
  12.  public void start(){  
  13.  driver = new FirefoxDriver();  
  14.  }  
  15.    
  16.  @Test  
  17.  public void AutoComplete()  
  18.  {  
  19.  driver.get("http://mythoughts.co.in/");  
  20.  driver.manage().window().maximize();  
  21.  }  
  22.   
  23. }  

No comments:

Post a Comment

Angular JS Protractor Installation process - Tutorial Part 1

                     Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...