I've setup my first Behat project, but I'm having troubles defining contexts other than FeatureContext. It gets created (I checked with a die in __construct), but the steps don't get called.
Here my folder structure:
|-root
|-bin
|-features
|-FeatureContext.php
|-PageLoaderContext.php
|-page_loading.feature
My package.json
{
"require": {
"behat/behat": "3.0.5",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*",
"behat/mink-zombie-driver": "*",
"symfony/http-kernel": "*"
},
"minimum-stability": "dev",
"config": {
"bin-dir": "bin"
}
}
Here's my behat.yaml
default:
suites:
default:
contexts:
- PageLoaderContext
And my feature
Feature: Tutte le pagine del sito caricano senza errori
Per poter usare il sito
Come utente
Ho bisogno che tutte le pagine carichino senza errori
Scenario Outline: Controlla il caricamento senza errori di pagine significative
Given I'm on "<url>"
When La pagina finisce di caricare
Then Dovrei ottenere uno status code HTTP pari a "<code>"
And Il "<selector>" della pagina dovrebbe contenere "<value>"
Examples:
| url | code | selector | value |
| ? | 200 | head title | Spagro |
PageLoaderContext.php
<?php
use Behat\Behat\Exception\PendingException;
class PageLoaderContext implements \Behat\Behat\Context\Context
{
/**
* @Given /^Carico la pagina "([^"]*)"$/
*/
public function caricoLaPagina($arg1)
{
throw new PendingException();
}
/**
* @When /^La pagina finisce di caricare$/
*/
public function laPaginaFinisceDiCaricare()
{
throw new PendingException();
}
/**
* @Then /^Dovrei ottenere uno status code HTTP pari a "([^"]*)"$/
*/
public function dovreiOttenereUnoStatusCodeHttpPariA($arg1)
{
throw new PendingException();
}
/**
* @Given /^Il "([^"]*)" della pagina dovrebbe contenere "([^"]*)"$/
*/
public function ilDellaPaginaDovrebbeContenere($arg1, $arg2)
{
throw new PendingException();
}
}
Like I said, if I implement the steps in FeatureContext, all is fine, but this won't work.
Try to change your behat.yml
to
default:
suites:
pageLoaderSuite:
paths:
- %paths.base%/features
contexts:
- Path\To\Your\Context
However I can see that you don't have namespaced PageLoaderContextClass
I tried making suites work, but Behat seems to ignore them. So I had to use profiles in place on suites and it worked.
*behat.yaml*
page_loading:
paths:
features: features\bootstrap\page_loading
bootstrap: %behat.paths.features%
context:
class: PageLoaderContext
Now, for each feature, I create a folder in bootstrap with the .feature files and the context class.