Project不承认cuc-picocontainer依赖

时间:2015-11-30 12:49:07

标签: java maven selenium cucumber picocontainer

我目前正在研究一个带有cucumber,JUnit和Selenium的java测试框架。我已经在这样的项目上工作了,但是我遇到了这个问题。

我正在尝试创建一个Singleton的Context类。我想使用cucumber-picocontainer在每个步骤定义类中都可以访问此类。我在我的pom.xml中添加了依赖项,但每次我尝试执行我的测试时,我都有一个例外:“NewLoginSteps没有空的构造函数。如果你需要DI,请在类路径上放置cucumber-picocontainer” 。我试图手动导入罐子,但它没有帮助。

以下是我的配置示例:

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

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来做同样的事情并且它正在工作。

6 个答案:

答案 0 :(得分:5)

我遇到了类似的问题。

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

答案 1 :(得分:1)

将以下依赖项添加到您的pom.xml

<dependency>   
    <groupId>org.picocontainer</groupId>  
    <artifactId>picocontainer</artifactId>
    <version>2.14.3</version>
</dependency>

答案 2 :(得分:0)

不包括

<dependency>   
    <groupId>info.cukes</groupId>  
    <artifactId>cucumber-java</artifactId>
    <version>1.2.2</version>
    <scope>test</scope>
</dependency>

除了黄瓜 - junit和黄瓜 - picocontainer。

这是我项目的问题。

答案 3 :(得分:0)

添加以下依赖项对我有用,

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>

答案 4 :(得分:0)

对我来说,即使在pom.xml中提供了相同版本的所有Cucumber- *,问题仍然存在。我下载了所有依赖项jar并添加到“依赖项”选项卡下的“模块设置”中。现在工作正常。

答案 5 :(得分:0)

info.cukes工件现在移至io.cucumber。与黄瓜相关的每个依赖项都应具有相同的版本号。

<properties>
    <io.cucumber.version>4.7.2</io.cucumber.version>
</properties>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${io.cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${io.cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- Using PicoContainer to share state between steps in a scenario -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>${io.cucumber.version}</version>
        <scope>test</scope>
    </dependency>