无法实例化测试步骤类 [英] Cannot instantiate test steps class

查看:298
本文介绍了无法实例化测试步骤类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中添加了以下jar文件:

I have following jar files added to my project :


  1. gherkin 2.12

  2. 黄瓜- junit 1.2.5

  3. 黄瓜java 1.2.5

  4. 黄瓜核心1.2.5

  5. 黄瓜jvm -deps 1.0.5

  6. cobetura 2.1.1

  7. mockito全部1.9.1

  8. 黄瓜报告3.13

  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

测试运行程序类

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类

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:

推荐答案

问题出在下面代码的第二行,因为初始化 wait时 driver对象为null,这会导致NullPointerException。

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

您应在Before钩子上初始化驱动程序,或在 driver之后初始化 wait 已初始化。

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

这篇关于无法实例化测试步骤类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆