0
votes

I am trying to use cucumber framework with selenium and appium, but while executing cucumber feature, i am getting the following exception :

cucumber.runtime.CucumberException: org.picocontainer.injectors.AbstractInjector$UnsatisfiableDependenciesException: pages.HomePage has unsatisfied dependency 'interface org.openqa.selenium.WebDriver' for constructor 'public pages.HomePage(org.openqa.selenium.WebDriver)' from org.picocontainer.DefaultPicoContainer@3f91b517:1<|
    at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:69)
    at cucumber.api.testng.AbstractTestNGCucumberTests.feature(AbstractTestNGCucumberTests.java:21)
Caused by: org.picocontainer.injectors.AbstractInjector$UnsatisfiableDependenciesException: pages.HomePage has unsatisfied dependency 'interface org.openqa.selenium.WebDriver' for constructor 'public pages.HomePage(org.openqa.selenium.WebDriver)' from org.picocontainer.DefaultPicoContainer@3f91b517:1<|
    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.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
    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:40)
    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.model.CucumberFeature.run(CucumberFeature.java:165)
    at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:63)
    at cucumber.api.testng.AbstractTestNGCucumberTests.feature(AbstractTestNGCucumberTests.java:21)
    at ✽.Given I open the application(Appium.feature:6)

HomePage.java

package pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;

public class HomePage extends BasePage{


    public HomePage(WebDriver driver) {
        super(driver);
        // TODO Auto-generated constructor stub
    }

    By searchbutton = By.id("header-search-icon");
    By wishList = By.id("header-wishlist-icon");




    @Given("^I open the application$")
    public void clicksearchButton() {
        waitForVisibilityOf(searchbutton);
        driver.findElement(searchbutton).click();
    }
    @When("^I tap on Accessibility$")
        public void clickwishList() {
        driver.get("https://www.myntra.com/");
        waitForVisibilityOf(wishList);
        driver.findElement(wishList).click();
    }
}

Below is my 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>
    <groupId>TestVagrant</groupId>
    <artifactId>1</artifactId>
   <version>1.0-SNAPSHOT</version>   

    <build>
      <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <fork>true</fork>
                    <executable>C:\Program Files\Java\jdk1.8.0_66\bin\javac</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
    <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>

        <!-- Below Dependency for TestNG -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.2.5</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.10</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>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>1.2.5</version>
        <type>pom</type>
    </dependency>



        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>4.1.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Below is the run configuration for cucumber test:

@CucumberOptions(features={"src//test//java//feature"} ,glue={"pages"} ,plugin = {"pretty", "html:target/cucumber"} , tags ={"@web","@Test","@appium"} ) @Test public class RunTest extends AbstractTestNGCucumberTests{

}

1
refer my answer here and try to put scope as well in our dependency as per your maven life cycle .. stackoverflow.com/questions/51019602/…Shubham Jain
After adding scope as well, i am getting the same errorzzz

1 Answers

1
votes

Try below code it should work. Remove super(driver) inside constructor instead of that use below code

/*************************/
    private BasePage basePage;
            public HomePage(){
                    basePage = new BasePage(driver);
            }
/*************************/

Let me know if you need more info