Pico 容器异常:org.picocontainer.injectors.AbstractInjector$UnsatisfiableDependenciesException:?

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

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

我的代码如下:

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

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

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

由于某种原因,在执行我的功能文件时,我似乎收到以下异常有什么想法吗?

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.access0(ConstructorInjector.java:51)
    at org.picocontainer.injectors.ConstructorInjector.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.resolveInstance(BasicComponentParameter.java:118)
    at org.picocontainer.parameters.ComponentParameter.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.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.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access[=14=]0(ParentRunner.java:58)
    at org.junit.runners.ParentRunner.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.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access[=14=]0(ParentRunner.java:58)
    at org.junit.runners.ParentRunner.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)

发生这种情况是因为您试图在没有放置 picocontainer 依赖项的情况下在 stepdefination 文件中创建构造函数。它是 cucumber

的依赖注入框架

要么删除构造函数,要么在 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> 标签