Project doesn't recognize cucumber-picocontainer dependency

14,052

Solution 1

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.

Solution 2

info.cukes artifact is now move to io.cucumber. Every dependency related to cucumber should have same version number.

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

Solution 3

Adding the following dependency worked for me,

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

Solution 4

Add below dependency to your pom.xml

<dependency>   
    <groupId>org.picocontainer</groupId>  
    <artifactId>picocontainer</artifactId>
    <version>2.14.3</version>
</dependency>
Share:
14,052
Nicolas G. Duvivier
Author by

Nicolas G. Duvivier

Test automation ninja (in training)

Updated on June 27, 2022

Comments

  • Nicolas G. Duvivier
    Nicolas G. Duvivier almost 2 years

    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 :

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

    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.

    • himawan_r
      himawan_r almost 6 years
      i got a similar issue, did you by any chance found the way to resolve this?
    • Nicolas G. Duvivier
      Nicolas G. Duvivier almost 6 years
      @himawan_r No, my problem wasn't solved at the time. I changed a lot of things since then. And I'm not using picocontainer anymore
    • himawan_r
      himawan_r almost 6 years
      i followed Vacha Dave solution by making all info cukes version the same, it works for me :)
  • Nicolas G. Duvivier
    Nicolas G. Duvivier over 8 years
    Thanks for your answer. I will try it but I think I've already tried that. I'll keep you aware of the result.
  • Bruce
    Bruce over 7 years
    this is not the answer to the question. you should ask new if you does not find the answer in the community.
  • himawan_r
    himawan_r almost 6 years
    thanks @VachaDave, just tried your answer and it did the trick. this should be an accepted answer.
  • Nicolas G. Duvivier
    Nicolas G. Duvivier almost 6 years
    I can't really mark it as an accepted answer. As you can see in the sample of my pom.xml, my version of all the cucumber dependencies are managed by a single parameter --> hence, the same version
  • himawan_r
    himawan_r almost 6 years
    @NicolasG.Duvivier allright np, just wanted to let others that might find this issue to try this. the issue might be varies tough
  • Nicolas G. Duvivier
    Nicolas G. Duvivier about 5 years
    @himawan_r As it solved similar issues for others, and I don't even have access to this code anymore. I accepted your answer
  • R0b1n
    R0b1n over 2 years
    @NicolasG.Duvivier I have faced the same problem as you, This answer does not solve that problem. I don't think this should be the accepted answer.