Cucumber framework-while running as junit it is showing "java.lang.NullPointerException" error

754 views
Skip to first unread message

Mohit Sharma

unread,
May 11, 2019, 7:12:40 AM5/11/19
to Selenium Users
While running as junit it is showing "java.lang.NullPointerException" error message in @Then step. Please help me to rectify this problem.


Error message


May 11, 2019 4:37:27 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[31mF [0m [36m- [0m [36m- [0m
[31mFailed scenarios: [0m
[31msrc/test/java/featureFile/simpleformdemo.feature:3 [0m# Test the single input field

1 Scenarios ( [31m1 failed [0m)
3 Steps ( [31m1 failed [0m, [36m2 skipped [0m)
0m18.472s

java.lang.NullPointerException
at stepDefination.simpledemoform.user_should_land_to_simple_for_demo_page(simpledemoform.java:26)
at ✽.User should land to Simple for Demo page(file:src/test/java/featureFile/simpleformdemo.feature:5)




Feature File

Feature: Test Simple for Demo page

Scenario: Test the single input field

Given User should land to Simple for Demo page
When User should able to fill the text box
Then User should able to click on the Show Message button



Test Runner file

package cucumberoptions;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;




@RunWith(Cucumber.class)
@CucumberOptions(
features="src/test/java/featureFile",
glue="stepDefination")

public class testrunner {

}




Page factory file

package Cucumberfinal.Pagefactory;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class simplefordemo_PF {
  
  
@FindBy(xpath="//input[@placeholder='Please enter your Message']")
WebElement singletextfield;
@FindBy(xpath="//button[@onclick='showInput()']")
WebElement showmessagebutton;
public WebElement singletext_field() {
return singletextfield;
}
public WebElement showmessage_button() {
return showmessagebutton;
}

}




StepDefination file


package stepDefination;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import Cucumberfinal.Pagefactory.simplefordemo_PF;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class simpledemoform {

WebDriver driver;
simplefordemo_PF sfd=new simplefordemo_PF();
@Given("^User should land to Simple for Demo page$")
    public void user_should_land_to_simple_for_demo_page() throws Throwable {
System.setProperty("webdriver.chrome.driver", "C:\\Mohit\\Software\\Java Software\\chromedriver_win32 (55)\\chromedriver.exe");
driver =new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
    }

    @When("^User should able to fill the text box$")
    public void user_should_able_to_fill_the_text_box() throws Throwable {
        sfd.singletext_field().sendKeys("Mohit Sharma");
    }

    @Then("^User should able to click on the Show Message button$")
    public void user_should_able_to_click_on_the_show_message_button() throws Throwable {
        sfd.showmessage_button().click();
    }


}

George Dinwiddie

unread,
May 11, 2019, 1:50:56 PM5/11/19
to seleniu...@googlegroups.com
Which is line 26 of simpledemoform.java?
> --
> You received this message because you are subscribed to the Google
> Groups "Selenium Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to selenium-user...@googlegroups.com
> <mailto:selenium-user...@googlegroups.com>.
> To post to this group, send email to seleniu...@googlegroups.com
> <mailto:seleniu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/selenium-users/56d79799-e7a7-4ce9-8295-d0ad829f793b%40googlegroups.com
> <https://groups.google.com/d/msgid/selenium-users/56d79799-e7a7-4ce9-8295-d0ad829f793b%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach
----------------------------------------------------------------------

Mohit Sharma

unread,
May 12, 2019, 12:33:25 AM5/12/19
to Selenium Users
I am attaching the screenshot for your reference
cucumber.jpg

⇜Krishnan Mahadevan⇝

unread,
May 12, 2019, 12:45:39 AM5/12/19
to Selenium Users
Your stack trace and your codebase doesnt seem to match.

I would suggest that you setup breakpoints to learn and understand what is causing the NPE.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


> To post to this group, send email to seleniu...@googlegroups.com
> <mailto:seleniu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/selenium-users/56d79799-e7a7-4ce9-8295-d0ad829f793b%40googlegroups.com
> <https://groups.google.com/d/msgid/selenium-users/56d79799-e7a7-4ce9-8295-d0ad829f793b%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
  ----------------------------------------------------------------------
   * George Dinwiddie *                      http://blog.gdinwiddie.com
   Software Development                    http://www.idiacomputing.com
   Consultant and Coach
  ----------------------------------------------------------------------

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ed1787ab-5f58-43bb-ae0a-55db56e3c800%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages