I cannot instantiate my teststeps in cucumber class step_definitions.LoginSteps doesn't have an empty constructor

I get an error when I run my feature test.Does this have to do with the webdriver constructor in the login page? I can't figure out why I"m getting this error:

cucumber.runtime.CucumberException: class step_definitions.LoginSteps doesn't have an empty constructor. If you need DI, put cucumber-picocontainer on the classpath...

I have picocontainter in my pom info.cukes cucumber-picocontainer 1.2.4

public class LoginSteps  {
private final LoginPage login;
SharedDriver driver;
public LoginSteps(LoginPage login, SharedDriver driver) {
    this.login=login;
    this.driver=driver;
}
@Given("^the Pctice Login page is loaded$")
public void the_Poactice_Login_is_loaded ()throws Throwable {
   driver.getDriver().get("....ogin/");
}


@When("^The logins into the account$")
public void the_logins_into_the_account() throws Throwable {

    login.login(false);

  }

Here is my login page

    public class LoginPage extends BaseClass {
  private final By username = By.id("userName");
   private final By password= By.id("password");
   private final By submit= By.id("submit_0");

    public LoginPage(WebDriver driver){
     super(driver);
    }


   public HomePage login(Boolean newuser) throws InterruptedException {
    DataFactory log= new DataFactory();
    if (newuser) {
        Thread.sleep(5000);
        driver.findElement(username).click();
        driver.findElement(username).sendKeys(log.getFirstName());
        driver.findElement(password).sendKeys(log.getFirstName());
    } else {
        driver.findElement(username).click();

    }

    return new HomePage(driver);
}}

Answers


I do not put constructors in my step-definition classes.

LandingPageSteps.java

package practice.steps;

import practice.pages.LandingPage;
import cucumber.api.java.en.When;

public class LandingPageSteps extends DriverFactory{

    @When("^she chooses to sign up$")
    public void she_chooses_to_sign_up() throws Throwable {
        new LandingPage(driver).she_chooses_to_sign_up();
    }
}

DriverFactory.java

package practice.steps;

import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import practice.util.PropertyReader;

public class DriverFactory {

    protected static WebDriver driver;

    public DriverFactory() {
        initialize();
    }

    public void initialize() {
        if (driver == null)
            createNewDriverInstance();
    }

    private void createNewDriverInstance() {
        PropertyReader propReader = new PropertyReader();
        String browser = propReader.readProperty("browser");
        if (browser.equalsIgnoreCase("firefox")){
            driver = new FirefoxDriver();
        } else if (browser.equalsIgnoreCase("chrome")) {
            System.setProperty("webdriver.chrome.driver", "c:/SeleniumWebdrivers/chromedriver.exe");
            driver = new ChromeDriver();
        } else {
            System.out.println(propReader.propertyNotValidMsg("browser", browser));
        }
        Assert.assertNotNull("Driver failed initialization", driver);
    }

    public WebDriver getDriver() {
        return driver;
    }

    public void destroyDriver() {
        driver.quit();
        driver = null;
    }
}

Note that the superclass does have a constructor. I was evaluating this free eBook by working through it. Maybe if you work through it yourself you would realize a more coherent approach. I found it to be pretty solid (I put my hooks in a separate file from the step definitions but it is a matter of taste). }


Need Your Help

MonoRail - How to render view in another area

castle-monorail

I'm using MonoRail and want to render the same view from two separate areas. I looked at all of the RenderView overloads and none of them have an area parameter, which seems odd to me. As a workaro...

Virtualenv: Sourcing bin/activate does not work; no feedback given

python ubuntu virtualenv

Been wrestling with this for a couple of hours. I installed virtualenv using easy_install. Then I did a