I'm new to Behat and Mink, and I'm trying to extend FeatureContext with MinkContext, but when I do, every step throws an error stating that the first function defined in MinkContext is also defined in FeatureContext (it isn't). The error message is as follows:
Step "/^(?:|I )am on (?:|the )homepage$/"
is already defined in FeatureContext::iAmOnHomepage()
If I remove the first function from the class, every step throws the same error, but now it refers to the second function in the MinkContext class:
Step "/^(?:|I )am on "(?P<page>[^"]+)"$/"
is already defined in FeatureContext::visit()
Extending FeatureContext with RawMinkContext works fine.
What could be causing this?
---- EDIT (additional info) ------------
I'm using Behat 3.
This is my entire current FeatureContext.php, and I'm still getting the error. I searched the entire folder containing my Behat install, and I could only find one instance of the
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends MinkContext implements SnippetAcceptingContext
{
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct()
{
date_default_timezone_set("US/Eastern");
}
}
This is my behat.yml file:
# behat.yml
default:
extensions:
Behat\MinkExtension:
goutte: ~
selenium2: ~
base_url: https://harvest.cals.ncsu.edu/
suites:
default:
contexts:
- FeatureContext
- Behat\MinkExtension\Context\MinkContext
This is the top portion of MinkContext.php: namespace Behat\MinkExtension\Context;
use Behat\Behat\Context\TranslatableContext;
use Behat\Gherkin\Node\TableNode;
/**
* Mink context for Behat BDD tool.
* Provides Mink integration and base step definitions.
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class MinkContext extends RawMinkContext implements TranslatableContext
{
/**
* Opens homepage
* Example: Given I am on "/"
* Example: When I go to "/"
* Example: And I go to "/"
*
* @Given /^(?:|I )am on (?:|the )homepage$/
* @When /^(?:|I )go to (?:|the )homepage$/
*/
public function iAmOnHomepage()
{
$this->visitPath('/');
}
...
--- EDIT 2: Working versions ------------
FeatureContext.php:
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Mink\WebAssert;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
...
behat.yml (now with Selenium tags to enable Chrome)
# behat.yml
default:
extensions:
Behat\MinkExtension:
goutte: ~
selenium2:
wd_host: "http://127.0.0.1:4444/wd/hub"
# chrome
capabilities: { "browserName": "chrome", "browser": "chrome", "version": "25", 'chrome': {'switches':['--no-sandbox']}}
base_url: https://harvest.cals.ncsu.edu/
browser_name: chrome
suites:
default:
contexts:
- FeatureContext
Seems that MinkContext is loaded twice: in FeatureContext and in behat.yml If you remove MinkContex from behat.yml it should work.