项目无法识别黄瓜-picocontainer依赖性 [英] Project doesn't recognize cucumber-picocontainer dependency

查看:161
本文介绍了项目无法识别黄瓜-picocontainer依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently working on a java test framework with cucumber, JUnit and Selenium. I've already worked on projects like that, but I'm experiencing an issue on this one.

我正在尝试创建一个单例的Context类.我想使用Cucumber-picocontainer在每个步骤定义类中都可以访问此类.我在pom.xml中添加了依赖项,但是每次尝试执行测试时,都会有一个异常消息:"NewLoginSteps没有空的构造函数.如果您需要DI,请在类路径上放置cumulum-picocontainer" .我试图手动导入罐子,但这没有帮助.

I'm trying to create a Context class that is a Singleton. I want to use cucumber-picocontainer to have this class accessible in every step definition class. I added the dependencies in my pom.xml, but every time I try to execute my tests, I have an exception that says : "NewLoginSteps doesn't have an empty constructor. If you need DI, put cucumber-picocontainer on the classpath". I tried to import the jars manually, but it didn't help.

这是我的配置示例:

  • pom.xml

  • 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>

TestContext.java:

TestContext.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课:

my superSepts class :

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

}

您是否知道我做错了什么?我已经使用picocontainer来做同样的事情,并且正在工作.

Do you have an idea about what I've done wrong ? I've already used picocontainer in order to do the same thing and it was working.

推荐答案

我遇到了类似的问题.

问题出在信息库的版本中..您需要在pom.xml中具有所有cumber- *的相同版本. 那为我解决了这个问题.

The problem was in the version of the info cukes..You need to have the same version of all cucumber-* in your pom.xml. That solved the issue for me.

这篇关于项目无法识别黄瓜-picocontainer依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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