0

I am having difficulties in setting Behat framework correctly. The test runs fine, however the step definitions are not being picked up from the FeatureContext file. Have tried out answers from other questions with no luck. The behat.yml file is currently stored in the root of the project:

 default:
 paths:
    features: 'bin/features'
    bootstrap: 'bin/features/bootstrap'
 context:
    class:      'FeatureContext'
 extensions:
     Behat\MinkExtension\Extension:
         goutte: ~
         selenium2: ~

In the root of the project I have a bin folder which contains the standard behat files: behat.bat, webunit.bat etc. Within the bin folder I have the features folder which contains the file search.feature:

Feature: Search
In order to find a word
As a website user
I need to be able to search for a word

@javascript
Scenario: Searching for a word that does exist
Given I am on "http://drupalcamp.mx/search/"
When I fill in "Escriba las palabras clave" with "behat, mink"
And I press "Buscar"
Then I should see "Behavior Driven Development"
And I follow "Behavior Driven Development"
And I wait for 5 seconds 

Within the features folder I there is a bootstrap folder which contains the file "FeatureContext"

    namespace features;
    use Behat\Behat\Context\ClosuredContextInterface,
        Behat\Behat\Context\TranslatedContextInterface,
        Behat\Behat\Context\BehatContext,
        Behat\Behat\Exception\PendingException;
    use Behat\Gherkin\Node\PyStringNode,
        Behat\Gherkin\Node\TableNode;
    use Behat\MinkExtension\Context\MinkContext;

    /**
    * Features context.
    */
    class FeatureContext extends MinkContext
    {
    /**
    * Initializes context.
    * Every scenario gets it's own context object.
    *
    * @param array $parameters context parameters (set them up through behat.yml)
    */
    public function __construct(array $parameters)
    {
        // Initialize your context here

    }
    /**
    * @Given /^I wait for (\d+) seconds$/
    */
    public function iWaitForSeconds($seconds)
    {
         $this->getSession()->wait($seconds*1000);
    }

When I run "behat" from the root directory of the project in CL, it fires the test in the browser, passes all but fails to recognise the step definition, it states "You can implement step definitions for undefined steps with these snippets:" which then it gives an example.

Tommy02
  • 41
  • 1
  • 5

1 Answers1

0

You need to configure the autoloader to load classes from your custom bootstrap folder.

If you're using composer, here's an example of how it could be done:

"autoload": {
    "psr-0": { "": ["src/", "bin/features/bootstrap/"]}
}

Note: bin folder is a really odd location to put your features or context files.

Related question with an answer: Behat + Symfony, Custom definitions are not loaded (actually, might be a duplicate).

Community
  • 1
  • 1
Jakub Zalas
  • 35,761
  • 9
  • 93
  • 125