java - 项目无法识别 cucumber-picocontainer 依赖项

标签 java maven selenium cucumber picocontainer

我目前正在使用 Cucumber、JUnit 和 Selenium 开发一个 Java 测试框架。我已经从事过类似的项目,但我在这个项目上遇到了问题。

我正在尝试创建一个作为单例的 Context 类。我想使用 cucumber-picocontainer 在每个步骤定义类中访问此类。我在我的 pom.xml 中添加了依赖项,但每次我尝试执行我的测试时,我都会遇到一个异常:“NewLoginSteps 没有空构造函数。如果你需要 DI,请将 cucumber-picocontainer 放在类路径中” .我尝试手动导入 jars,但没有帮助。

这是我的配置示例:

  • pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
    
        <properties>
            <cucumber.version>1.2.4</cucumber.version>
            <selenium-java.version>2.39.0</selenium-java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>${cucumber.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-picocontainer</artifactId>
                <version>${cucumber.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-junit</artifactId>
                <version>${cucumber.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
                <scope>test</scope>
            </dependency>
    </project>
    

测试上下文.java :

public class TestContext {
    private static Map<String, String> siteLocations = new HashMap<String, String>();
    private static boolean initialized = false;
    private static boolean firstInitDone = false;
    private static WebDriver driver;
    private static boolean testsToRun = false;
    private static AutomatedTestMode modeAsEnum;

    @Before
    public void setUp(Scenario scenario) {
        initialize();
        Log.startTestCase(scenario.getName());
        afterAll();
    }
    ....
}

步骤定义类:

public class NewLoginSteps extends NewSuperSteps {

    public NewLoginSteps(TestContext context){
        super(context);
    }


    @When("^I log in nova as \"([^\"]*)\" user with \"([^\"]*)\" \"([^\"]*)\"$")
    public void newLogin(String instance, String username, String password){
        Assert.assertEquals(true, false);

    }

    @Then("^The user is connected$")
    public void The_user_is_connected(){
        throw new PendingException();
    }

}

我的 superSepts 类:

public class NewSuperSteps {
    protected TestContext context;
    public NewSuperSteps(TestContext context){
        this.context=context;
    }

}

你知道我做错了什么吗?我已经使用 picocontainer 来做同样的事情并且它正在工作。

最佳答案

我遇到了类似的问题。

问题出在 info cukes 的版本中。您需要在 pom.xml 中使用相同版本的所有 cucumber-*。 这为我解决了这个问题。

关于java - 项目无法识别 cucumber-picocontainer 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33999071/

相关文章:

java - Spring中的转换服务

java - JBoss maven插件: deployment fails,依赖项未找到

maven - Gradle compileGroovy java.lang.ExceptionInInitializerError

java - 无法解析项目org.deeplearning4j:dl4j-examples:jar:1.0.0-beta6 Java的依赖项

windows - Windows 命令行中的 Jasmine

javascript - 在 Python 中更改来自 Selenium 的元素列表

java - 在 Android 应用程序的 MapView 中添加指南针校准选项

java - 实体与值对象

selenium - 尝试使用 Headless Firefox 运行 Selenium 时出现 "connection refused"

ruby - `selenium-webdriver` ruby​​ gem 无法与 Ubuntu 14.04 上的 chromedriver 连接