1

I am trying to build a Cucumber BDD framework with multiple step definition files. I am still trying to understand how to use picocontainer to run the step definition files. My problem is that once I have added the picocontainer jar into a project's build path, when executing the test runner it is unable to find any scenarios or steps.

Console

enter image description here

Java project build path

enter image description here

My project contains:

• A feature file
• 2 step definition files
• 1 test runner
• Utilities package with a webdriver initializer method

My feature file has the following steps:

enter image description here

The first 2 gherkin steps are glued to methods in following step definition class:

package stepDefinitions;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import cucumber.api.java.en.Given;

public class SD_HomePage {
    WebDriver driver;

    @Given ("^the user is on the websites homepages$")
    public void user_is_on_the_websites_homepage() {
        driver = utilities.WebDriverInitializer.openWebdriver("Chrome");
        driver.get("https://www.forExample.com/");
    }

    @Given("^then clicks on AboutUs title$")
    public void then_clicks_on_AboutUs_title() throws Throwable {
        driver.findElement(By.xpath("//a[@href='/en/about-us'][1]")).click();

    }

}

The third gherkin step is glued to this separate step def class:

package stepDefinitions;

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

import cucumber.api.java.en.When;

public class SD_AboutUsPage {
    WebDriver driver;

    @When("^the user clicks on Contact widget$")
    public void the_user_clicks_on_Contact_widget() throws Throwable {
        driver.findElement(By.xpath("//span[@class='icon-envelope listCta__img'][1]")).click();
    }
}

When executing the test from the test runner no scenarios or steps will be found by the runner:

package testRunners;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features = "Features", glue = "stepDefinitions")
public class TestRun_NewsletterForm {

}

Console results from the Testrunner

enter image description here

However, when I remove the picocontainer the scenario and steps will be found. This will leave me with the original problem of not being able to make use of a shared state Webdriver.

Test Run after picocontainer jar is removed

enter image description here

I am aware that in this project I have not yet set up a class that will contain the shared state Webdriver, and constructors on the step definition pages. I have another project that has that is affected by this same issue but I felt that it would make this issue more complicated if I used that example.

Wilson Vargas
  • 2,841
  • 1
  • 19
  • 28
  • I resolved this issue by replacing picocontainer jar version from 1.2.5 to version 1.1.5. I have followed quite a few different tutorials online and they have used 1.2.5 or 1.2.4 (neither of which work for me). Has anybody heard of any known issues with 1.2.5 that could be the cause of this? I am going to continue building my framework using 1.1.5 but I am concerned that using this outdated version could cause problems further down the line, and I would prefer to user a more recent version. – Paul Murphy Nov 11 '17 at 19:09
  • Is the Features folder outside the src directory? Try moving the features folder inside the src folder and use features value in cucumberoptions as "/src/Features". – Grasshopper Nov 11 '17 at 20:27
  • Hello Grasshopper. Thanks for replying. I have tried moving the Features folder into the src folder and tried to run the test using picocontainer 1.2.5 (and 1.2.4) and the test still fails to find the scenario file. However, when reverting to pico 1.1.5 this works just as well as having the Feature folder outside of the src folder (I actually prefer it in the src folder so I think I will keep it there). I noticed that when trying to create a folder within the src folder, it became a package. Should this be expected? – Paul Murphy Nov 11 '17 at 20:51
  • It ahould remain a folder. Did i add it from eclipse? – Grasshopper Nov 12 '17 at 04:32
  • I tried it two different ways. The first method was just copying the original Features folder and then pasting it into the src folder. This resulted in the features folder becoming a package folder containing the feature file. The second method I right-clicked on the src folder then selected 'New > Folder'. After naming the folder it was created automatically as a package. – Paul Murphy Nov 12 '17 at 11:25

0 Answers0