I am trying to run a cucumber test to open a browser, go to a webpage, and do some clicking. But I keep getting a java.lang.NullPointerException. I am running out of ideas on what this could be and how to sort it. Can anyone help me out?

public class LoginSteps {
     WebDriver driver;

    @Before()
    public void setup(){
        System.setProperty("webdriver.chrome.driver", "C:\\Workstuff\\webdrivers\\chromedriver.exe");
        this.driver = new ChromeDriver();
        this.driver.manage().window().maximize();
        this.driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
    }
    @Given("^User goes to webdriveruniversity$")
    public void user_goes_to_webdriveruniversity() throws Throwable {
        driver.navigate().to("http://webdriveruniversity.com/");
    }

```java.lang.NullPointerException
at Cucumber.features.steps.LoginSteps.user_goes_to_webdriveruniversity(LoginSteps.java:29)
  at ✽.Given User goes to webdriveruniversity(C:/Users/homez/Cucumber/src/test/java/Cucumber/features/ContactUs.feature:5)
Skipped step

1 Answers

0
Community On

Found my issue by accident instead of importing import cucumber.api.java.Before; I did import org.junit.Before;