0

I have a cucumber and fluentlenium project that doesn't start when i run the CucumberRunner. It just skips all the tests .I tried to find a solution on internet but didn't figured out the problem so far. A little bit of help would be nice.

This is are my steps:

public class LoginPageSteps extends BaseTest {

public LoginPageSteps() throws Exception {
    super();
}

@Page
LoginPage loginPage;


@Given("^I am on login page$")
public void goToLoginPage(){
    goTo(loginPage);
}

@When("^I enter username as '(.*?)'$")
public void enterUsername(String username) {
    waitAndFill(loginPage.username, username);
}

@And("^I enter password as '(.*?)'$")
public void enterPassword(String password)  {

    waitAndFill(loginPage.password, password);
    waitUntilCliclableAndClick(loginPage.loginButton);

}

@Then("^Login should be succesfull$")
public void checkLoginStatus()  {
    assertTrue(getDriver().getCurrentUrl().contains("login_attempt=1"));

}
}

This is my BaseTest.class :

  public class BaseTest extends FluentCucumberTest {

@Page
AccountPage accountPage;


@Before
public void before(Scenario scenario) {
    super.before(scenario);
}

@After
public void after(Scenario scenario) {
    super.after(scenario);
}

@Override
public WebDriver newWebDriver() {

    System.setProperty("webdriver.gecko.driver", "../cucumber-test/src/test/resources/geckodriver.exe");
    FirefoxDriver driver = new FirefoxDriver();

    return driver;
}

public void waitUntilCliclableAndClick(FluentWebElement element) {
    await().atMost(5, TimeUnit.SECONDS).until(element).clickable();
    element.click();
}

public void waitAndFill(FluentWebElement element, String data) {
    await().atMost(5, TimeUnit.SECONDS).until(element).displayed();
    element.fill().with(data);
}



}

And this is my feature file :

   Feature: valid-login 

Scenario: 
   Given I am on login page 
   When I enter username as "myusername"
   And I enter password as "mypassword" 
   Then Login should be succesfull 

And this is the runner :

@RunWith(Cucumber.class) 
@CucumberOptions(features={"src/test/resources/features"})
public class CucumberRunner {

}
T.Frincu
  • 43
  • 7

2 Answers2

1

Your Cucumber runner is called CucumberRunner

This may be an issue if you build using Maven. The testrunner in Maven, Surefire, searches for classes named XXXXTest or TestXXXX. Your runner class will not be found.

Try to rename your Cucumber runner to CucumberRunnerTest and see if it solves the problem.

Thomas Sundberg
  • 4,098
  • 3
  • 18
  • 25
0

Found this example project which might be helpful to you.

Although I've cloned / ran this example project, the cucumber version was old and needed an update.

Here's what I've done to make the project work:

Updated fluentlenium-cucumber, fluentlenium-assertj to 3.3.0, cucumber-core, cucumber-junit, cucumber-java, cucumber-picocontainer to 1.2.5 as well as junit and htmlunit-driver to the latest versions in pom.xml.

Step file looks like this:

import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import org.fluentlenium.adapter.cucumber.FluentCucumberTest;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.concurrent.TimeUnit;

public class BasicStep extends FluentCucumberTest {

    @Before
    public void before(Scenario scenario) {

    }

    @Override
    public WebDriver newWebDriver() {
        System.setProperty("webdriver.gecko.driver", "path/to/geckodriver");
        WebDriver driver = new FirefoxDriver();
        return driver;
    }

    @Given("I open Google")
    public void iOpenGoogle() {
        this.initFluent(new newWebDriver());
        goTo("http://google.com");

        await().atMost(5, TimeUnit.SECONDS);
        assertThat(window().title()).contains("Google");
    }

    @After
    public void after(Scenario scenario){
        super.after(scenario);
    }
  }

And the test file:

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/toto")

public class BasicTest {

}

New test result:

enter image description here

Hope you get it working!

Daniel Fintinariu
  • 2,733
  • 1
  • 14
  • 16
  • What version of cucumber have you used ? – T.Frincu Jul 27 '17 at 13:59
  • Seems to be am old version of cucumber from the example project. Will investigate / update the example project and come back to you. – Daniel Fintinariu Jul 27 '17 at 15:12
  • I tried your scenario and it works but in my case it doesnt because i can't call getDriver() in @Before because it is null at the runtime. I want to override newWebDriver() method and set the driver there instead of the Before because i only want to run one time. Calling in Before will initialize the driver again when my other tests are run. – T.Frincu Jul 28 '17 at 11:28
  • 1
    @T.Frincu, you can leave the `before` empty and in the first step just add `this.initFluent(newWebDriver());`. I managed to make this work in the Example project (updated the answer) – Daniel Fintinariu Jul 28 '17 at 14:18