本文介绍了Pico容器异常:org.picocontainer.injectors.AbstractInjector $ UnsatisfiableDependenciesException :?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎收到了一个pico容器异常:org.picocontainer.injectors.AbstractInjector $ UnsatisfiableDependenciesException。

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

我的代码如下:

表示网站特定页面的页面对象:

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

步骤类:

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

由于执行我的功能文件时的某些原因,我似乎收到以下例外提示吗? / p>

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)


推荐答案

之所以发生这种情况,是因为您试图在stepdefination文件中创建构造函数而没有放置picocontainer依赖性。它是黄瓜的依赖注入框架

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

要么删除构造函数,要么在POM中添加以下依赖项

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>

您可以删除< scope> test< / scope> 标签,如果不想限制依赖项的可传递性

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

这篇关于Pico容器异常:org.picocontainer.injectors.AbstractInjector $ UnsatisfiableDependenciesException :?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 03:18