user2376425
user2376425

Reputation: 85

java null pointer exception in test suite

I am stuck at a situation. Here i have created one testsuite with two test cases in it. First test case is executed properly. In second test case, it throws error of java.lang.NullPointerException at Webdriver driver

Test Case:

 public class second{
    private WebDriver driver;

    @Test
    public void sample() throws Exception
    {
           System.out.println("tab bar");
           driver.findElement(By.id("tabs"));
           //My code
        }
}

Upvotes: 0

Views: 1065

Answers (3)

Ittiel
Ittiel

Reputation: 1224

WebDriver is an interface and cannot be initialized, you should use the implementation like: WebDriver driver = new FirefoxDriver();

Upvotes: 0

Ruchira Gayan Ranaweera
Ruchira Gayan Ranaweera

Reputation: 35557

 private WebDriver driver; // initialize this

Upvotes: 1

nano_nano
nano_nano

Reputation: 12523

WebDriver driver;

is not initiated. What do you expect? The exception is absolutly correct. You can try the following code to avoid the exception:

driver= new WebDriver();
driver.findElement(By.id("tabs"));

Upvotes: 1

Related Questions