0

I'm new with Cucumber... I've been getting a NullPointer Exception when I try to run my code. The java version works fine though... Could someone please tell me where I'm going wrong?

public class Stepdefs {

protected WebDriver driver;

 @Before
    public void setup() {
     DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);

 System.setProperty("webdriver.gecko.driver","/Users/sajupt/Documents/geckodriver");
        WebDriver driver;
        driver = new FirefoxDriver();
        driver.get("localhost");
 }

      @After
        public void after() {
            driver.quit();
        }

@Given("^I am on the Preconditions Page$")
public void i_am_on_the_preconditions_page() {
}


@When("^I click on the continue button$")
public void I_click_on_the_continue_button() { 
    driver.findElement(By.xpath(".//*[@id='root']/div/div/div/section/div[2]/div/section/form/section[2]/div[2]/div/div/button")).click();
    WebElement continueButton = driver.findElement(By.className("RadioButton__button--2mnYd"));
  continueButton.click();

This is the error Trace

[31mWhen [0m[31mI click on the continue button[0m           [90m# 
Stepdefs.I_click_on_the_continue_button()[0m
  [31mjava.lang.NullPointerException
    at 
skeleton.Stepdefs.I_click_on_the_continue_button(Stepdefs.java:71)
    at ✽.When I click on the continue button(skeleton/belly.feature:5)
  [0m
[36mThen [0m[36mI should go to the registered owner page[0m [90m# 
Stepdefs.i_should_go_to_the_registered_owner_page()[0m

[31mFailed scenarios:[0m [31mskeleton/belly.feature:3 [0m# Scenario: Accessing the Quotes page

1 Scenarios ([31m1 failed[0m) 3 Steps ([31m1 failed[0m, [36m1 skipped[0m, [32m1 passed[0m) 0m6.000s

java.lang.NullPointerException
at skeleton.Stepdefs.I_click_on_the_continue_button(Stepdefs.java:71)
at ✽.When I click on the continue button(skeleton/belly.feature:5)



java.lang.NullPointerException
at skeleton.Stepdefs.I_click_on_the_continue_button(Stepdefs.java:71)
at ✽.When I click on the continue button(skeleton/belly.feature:5)

Here is the feature file

Feature: Getting a Quote

Scenario: Accessing the Quotes Feature Given I am on the Preconditions Page When I click on the continue button Then I should go to the registered owner page When I click on the continue button Then I should go to the Enter HSN TSN page Then I should go to Select make page When I select a make and click continue Then I should go the Select model page When I select a model and click continue Then I should go the select fuel page When I select the fuel and click on continue Then I should go to the select Engine page When I select the Engine and click on continue Then I should go to the Registration page. When I enter the year and click on continue Then I should go to the Date of Birth page.

Saju
  • 1
  • 1
  • 1
  • can you share your feature file to give a context on what you are trying to achieve. take a look at this article just in case: https://softwareautomata.wordpress.com/2017/07/25/cucumber-setup-testng-selenium/ – Ashish Deshmukh Aug 11 '17 at 16:40
  • I would suggest you look into line 71 of Stepdefs Java and check which object there is null. Then you change something about that. And hint: NPEs are absolute basic. If you don't know how to deal with them - then chances are that thinking about BDD and cucumber are overburdening you as of now. Rather step back and spend some time learning Java basics. – GhostCat Aug 14 '17 at 09:19
  • Thanks for ur advice. I figured out where the issue was. – Saju Aug 15 '17 at 06:51

0 Answers0