Reputation: 41
Here is my feature file Feature: As a visitor I should be able to load the home page
@javascript @program
Scenario: View first page
When I fill in the following:
| username | myusername |
| password | mypass |
And press "Login"
Then I should see "Dashboard"
Then I go to "/programs/list"
My composer.json is as following:
{
"require": {
"behat/mink-extension": "^2.2",
"behat/mink-goutte-driver": "^1.2",
"behat/mink-selenium2-driver": "^1.3"
}
}
my behat.yml file is as:
default:
extensions:
Behat\MinkExtension:
base_url: http://myURL.com
selenium2: ~
browser_name: 'chrome'
suites:
defaults:
contexts:
- FeatureContext
- Behat\MinkExtension\Context\MinkContext
My FeatureContext.php file is as
class FeatureContext extends MinkContext implements Context, 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()
{
$this->driver = new \Behat\Mink\Driver\Selenium2Driver('chrome');
$this->session = new \Behat\Mink\Session($this->driver);
$this->session->start();
}
public function iAmOnHomepage($arg1)
{
$this->getSession()->visit($this->locatePath('http://myURL.com'));
}
/**
* @When |I fill in :arg1 with :arg2
*/
public function iFillInWith($username, $password)
{
$MinkContext = new MinkContext;
$MinkContext -> assertFieldContains ("username" , $username);
$MinkContext -> assertFieldContains ("password" , $password);
$this->driver->close();
}
}
I get this following error:
FeatureContext::iAmOnHomepage()
Behat\MinkExtension\Context\MinkContext::iAmOnHomepage() And press
"Login" Step "/^(?:|I )am on (?:|the )homepage$/" is already defined
in FeatureContext::iAmOnHomepage()
Upvotes: 2
Views: 2226
Reputation: 4173
In your case, you are getting this error because you are loading MinkContext twice in FeatureContext and trough behat.yml.
If you extended FeatureContext with MinkContext then you don't have to declare MinkContext in behat.yml.
Removing the line Behat\MinkExtension\Context\MinkContext
from behat.yml should solve your issue.
Upvotes: 9
Reputation: 161
If this is your requirement 'As a visitor I should be able to load the home page', then the add following step as your first step in your scenario:
Given I am on homepage
Remove the function iAmOnHomepage()
from your FeatureContext
file since this is already a standard function available with Mink. This would create conflicts. Or change the name your function.
public function iFillInWith($username, $password)
{
$MinkContext = new MinkContext;
$MinkContext -> assertFieldContains ("username" , $username);
$MinkContext -> assertFieldContains ("password" , $password);
$this->driver->close();
}
I don't think you need the above steps. You are just asserting the fields here and not making use of this function anywhere in your feature file.
Please note - Gherkin statements are written in the form of Given, When and Then. You will also have to make your scenarios readable here.
Upvotes: 2
Reputation: 3051
Rename public function iAmOnHomepage($arg1)
info something, for example, public function IAmAtHomepage($arg1)
Or put annotation to iAmOnHomepage
/**
* @When I am on Homepage with :arg1
*/
The problem right now seems to be that auto-parsing of function name into condition conflicts with internal condition Behat\MinkExtension\Context\MinkContext::iAmOnHomepage()
Upvotes: 0