Executing a Feature file using Cucumber and Selenium using Web driver commands

I was trying to login to www.facebook.com using CUCUMBER via selenium web driver commands

My Feature file is as below

Feature: Proof of concept that my framework works

Scenario: My first test
Given I navigated to the Facebook website
When I provided login details
Then Click Submit button

I have written the Step defintions like as below for the methods Given.When and Then from the Deature file

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class StepDefintion {

WebDriver driver=null;

@Given(“^I navigated to the Facebook website$”)
public void I_navigated_to_the_Facebook_website() throws Throwable {
WebDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.navigate().to(“https://www.facebook.com/?_rdr=p”);
Thread.sleep(2000);

}

@When(“^I provided login details$”)
public void I_provided_login_details() throws Throwable {
driver.findElement(By.xpath(“.//*[@id=’u_0_b’]”)).sendKeys(“Kavitha”);
driver.findElement(By.xpath(“.//*[@id=’u_0_d’]”)).sendKeys(“Ganji”);
driver.findElement(By.xpath(“.//*[@id=’u_0_f’]”)).sendKeys(“kavitha@q-free.com”);
driver.findElement(By.xpath(“.//*[@id=’u_0_i’]”)).sendKeys(“kavitha@q-free.com”);
driver.findElement(By.xpath(“.//*[@id=’u_0_k’]”)).sendKeys(“kavi123”);
Thread.sleep(2000);

}

@Then(“^Click Submit button$”)
public void Click_Submit_button() throws Throwable {
driver.findElement(By.xpath(“.//*[@id=’u_0_s’]”)).click();
Thread.sleep(2000);

}

}

But unfortunately Iam not able to execute the second method using @When method. There is nothing wrong in providing the login details in the @ When method.  When I executed the Feature file the @When method is skipped and didnt execute all the other methods.  The below is the error message that was displayed in the Console

Feature: Proof of concept that my framework works

Scenario: My first test # C:/JAVA Programs/kavitha/Cucumber/src/Cucumberfeauture/Myfeature.feature:3
Given I navigated to the Facebook website # StepDefintion.navigatedFacebook()
When I provided login details # StepDefintion.provideddetails()
java.lang.NullPointerException
at Cucumber.StepDefintion.provideddetails(StepDefintion.java:27)
at ?.When I provided login details(C:/JAVA Programs/kavitha/Cucumber/src/Cucumberfeauture/Myfeature.feature:5)

Then Click Submit button # StepDefintion.Submitbutton()

1 Scenarios (1 failed)
3 Steps (1 failed, 1 skipped, 1 passed)
0m23.507s

java.lang.NullPointerException
at Cucumber.StepDefintion.provideddetails(StepDefintion.java:27)
at ?.When I provided login details(C:/JAVA Programs/kavitha/Cucumber/src/Cucumberfeauture/Myfeature.feature:5)

Train Asked on September 7, 2015 in Selenium WebDriver.

I don’t think we will be able to run the code using the above info provided.
Please if you can provide the complete set up , I may help you with root cause. can you do that from your end 🙂

on September 7, 2015.
Add Comment
  • 1 Answer(s)

    RE: Executing a Feature file using Cucumber and Selenium using Web driver commands

    RE: Executing a Feature file using Cucumber and Selenium using Web driver commands

    Please find out attached screenshots that gives you an idea of what I am explaining. I installed Cucumber jar files and configured by setting the build path. In the screenshots a feature file was written in simple steps and a step definition file implements the same methods of a feature file by looking at the annotations Given,When and Then

    Train Answered on September 7, 2015.

    I understood what You want to achieve Can you please paste your Complete POM xml down here . Thanks 🙂

    on September 8, 2015.

    And what Contents in Cucumber runner too if possible 🙂

    on September 8, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.