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();
}
}