In module/37/12013 I see NullPointerException in my code | Selenium Forum
M
Monal Posted on 23/10/2020

https://www.qtpselenium.com/selenium-training/module/37/12013

I followed your lecture till the begining of the above mention module 37 video Part-3 of "BUILDING FRAMEWORK WITH CUCUMBER"

IN my GenericStep2.java { class

Using this code:

@And("^I navigate to (.*)$")

public void navigate(String url) {

      System.out.println("Navigating to "+con.name);

}

Gives me output:(Which works fine)

Opening Browser A

Mozilla

Navigating to A

Typing in field . Data ashishthakur1983

Typing in field . Data password

Clicking on submit button

Opening Browser A

Mozilla

Navigating to A

 

2 Scenarios ([32m2 passed[0m)

7 Steps ([32m7 passed[0m)

0m0.055s

BUT WHEN I ADD BELOW Code in GenericSteps2

@And("^I navigate to (.*)$")

public void navigate(String url) {

       System.out.println("Navigating to "+con.name);

       con.navigate(url);

}

Gives me NullPointer Error please see Screen shot

But in you lecture as I followed I did not saw any errors can you please explain how can I resolve this issue? How can adding

con.navigate(url); throws the NullPointerException?

-Monal


M
Monal Replied on 23/10/2020

Instructor,

              Please close this issue since I have found my error after some time I forgot to block the navigate() code like so

public void navigate(String url) {

//driver.get(url);

}

instead I had that unblock and therefore I was seeing the Null pointer exception. I guess I must have missed that in the video but found out later.

Thank you,

Monal