javamavenseleniumcucumberpicocontainer

Project doesn't recognize cucumber-picocontainer dependency


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.

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.

Here is a sample of my configuration :

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();
    }
    ....
}

a step definition class :

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

}

my superSepts class :

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

}

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.


Solution

  • I faced similiar issue.

    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.