Pico container exception: org.picocontainer.injectors.AbstractInjector$UnsatisfiableDependenciesException:?

强颜欢笑 提交于 2019-12-10 18:06:39

问题


I seem to be getting a pico container exception: org.picocontainer.injectors.AbstractInjector$UnsatisfiableDependenciesException.

My code is as follows:

Page Object representing a specific page of a website:

     public class GooglePage {
        private WebDriver driver;

        private String stringLocator = "edffsfds";

        @FindBy(how = How.XPATH,using = "//div[@id='header']/ul[1]/li[11]/a")
        public WebElement logout;

          public GooglePage(WebDriver driver) {
              this.driver = driver;
              PageFactory.initElements(driver, this);
          }

        public WebElement getLogout() {
            return logout;
        }

        public void setLogout(WebElement logout) {
            this.logout = logout;
        }

        public String getExampleStringLocator() {
            return stringLocator;
        }
    }

Steps class:

    import CucumberNewExcel.transformer.pageObjects.GooglePage;
    import cucumber.api.java.en.Given;
    import cucumber.api.java.en.When;

    public class GoogleSteps {
        private GooglePage googlePage;

        public GoogleSteps(GooglePage googlePage) {
            this.googlePage = googlePage;
        }   

        @Given("^I access \"([^\"]*)\"$")
        public void i_access(String arg1) throws Throwable {
            //System.out.println("Hello: " + googlePage.getExampleStringLocator());
        }

        @When("^I click on the signin button$")
        public void i_click_on_the_signin_button() throws Throwable {
            //System.out.println("Hello: " + googlePage.getExampleStringLocator());
        }
    }

POM Dependencies:

<dependencies>
            <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.11.0</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <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-jvm</artifactId>
                <version>1.2.5</version>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-junit</artifactId>
                <version>1.2.5</version>
                <scope>test</scope>
            </dependency>


            <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-core</artifactId>
                <version>1.2.5</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-html -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-html</artifactId>
                <version>0.2.3</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>1.2.5</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-jvm-deps -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-jvm-deps</artifactId>
                <version>1.0.5</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>gherkin</artifactId>
                <version>2.12.2</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
            <dependency>
                <groupId>org.hamcrest</groupId>
                <artifactId>hamcrest-all</artifactId>
                <version>1.3</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-picocontainer -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-picocontainer</artifactId>
                <version>1.2.5</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-testng</artifactId>
                <version>1.2.5</version>
            </dependency>

            <!-- Extent Reports -->
            <dependency>
                <groupId>com.aventstack</groupId>
                <artifactId>extentreports</artifactId>
                <version>3.0.5</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
            <dependency>
                <groupId>org.freemarker</groupId>
                <artifactId>freemarker</artifactId>
                <version>2.3.26-incubating</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
            <dependency>
                <groupId>net.masterthought</groupId>
                <artifactId>cucumber-reporting</artifactId>
                <version>3.6.0</version>
            </dependency>
            <dependency>
                <groupId>com.vimalselvam</groupId>
                <artifactId>cucumber-extentsreport</artifactId>
                <version>2.0.4</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-jvm-deps -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-jvm-deps</artifactId>
                <version>1.0.5</version>
            </dependency>
        </dependencies>

For some reason when executing my feature file, I seem to be receiving the following exception any ideas?

org.picocontainer.injectors.AbstractInjector$UnsatisfiableDependenciesException: CucumberNewExcel.transformer.pageObjects.GooglePage has unsatisfied dependency 'interface org.openqa.selenium.WebDriver' for constructor 'public CucumberNewExcel.transformer.pageObjects.GooglePage(org.openqa.selenium.WebDriver)' from org.picocontainer.DefaultPicoContainer@2f67a4d3:2<|
    at org.picocontainer.injectors.ConstructorInjector.getGreediestSatisfiableConstructor(ConstructorInjector.java:191)
    at org.picocontainer.injectors.ConstructorInjector.getGreediestSatisfiableConstructor(ConstructorInjector.java:110)
    at org.picocontainer.injectors.ConstructorInjector.access$100(ConstructorInjector.java:51)
    at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:331)
    at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
    at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
    at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
    at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
    at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
    at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
    at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
    at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
    at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
    at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
    at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
    at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
    at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
    at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
    at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)
    at cucumber.runtime.java.picocontainer.PicoFactory.getInstance(PicoFactory.java:37)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:300)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:95)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:38)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
    at ✽.Given I access "wwww.google.com"(google.feature:4)

回答1:


This happening because you are trying to create constructors in stepdefination file without putting picocontainer dependency. Its an dependency injection framework for cucumber

Either remove the constructor or add below dependency in POM

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-picocontainer -->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
</dependency>

You can remove <scope>test</scope> tag if do not want to limit the transitivity of a dependency



来源:https://stackoverflow.com/questions/51019602/pico-container-exception-org-picocontainer-injectors-abstractinjectorunsatisfi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!