Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have following jar files added to my project :

  1. gherkin 2.12
  2. cucumber-junit 1.2.5
  3. cucumber-java 1.2.5
  4. cucumber core 1.2.5
  5. cucumber jvm-deps 1.0.5
  6. cobetura 2.1.1
  7. mockito all 1.9.1
  8. cucumber-reporting 3.13

I am getting an error when I try to run test runner class:

 cucumber.runtime.CucumberException: Failed to instantiate class stepDefinition.Test_steps

Test Runner Class:

package CucumberTest;

import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "Feature"
        ,glue={"stepDefinition"}
        )

public class TestRunner {


}

Test_steps Class

package stepDefinition;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import PageObject.LoginVariables;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;


public class Test_steps {

    private static WebDriver driver = null;
    WebDriverWait wait = new WebDriverWait(driver, 60);

    @Given("^User is on Homepage$")
    public void user_is_on_Homepage() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        driver = new ChromeDriver();
        System.setProperty("webdriver.chrome.driver", "C:\Selenium\chromedriver.exe");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://test.salesforce.com");

        throw new PendingException();
    }

    @When("^User Enters userId and Password$")
    public void user_Enters_userId_and_Password() throws Throwable {
        // Write code here that turns the phrase above into concrete actions

        wait.until(ExpectedConditions
                .visibilityOfElementLocated(By.xpath(LoginVariables.login_xpath)))
                .sendKeys("username@mail.com");

        wait.until(ExpectedConditions
                .visibilityOfElementLocated(By.xpath(LoginVariables.password_xpath)))
                .sendKeys("password");

        wait.until(ExpectedConditions
                .visibilityOfElementLocated(By.xpath(LoginVariables.login_xpath))).click();

        throw new PendingException();
    }

    @Then("^User is able to login sucessfully in salesorce$")
    public void user_is_able_to_login_sucessfully_in_salesorce() throws Throwable {
        // Write code here that turns the phrase above into concrete actions

        System.out.println("User Login Sucessful");
        throw new PendingException();
    }

}

Folder Structure: Folder Structure

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
379 views
Welcome To Ask or Share your Answers For Others

1 Answer

The issue is on the second line of the code below since the "driver" object is null when the "wait" is initialized and that causes a NullPointerException.

private static WebDriver driver = null;
WebDriverWait wait = new WebDriverWait(driver, 60);

You should initialize the "driver" on a Before hook or initialize the "wait" after the "driver" has been initialized.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...