I am trying to make BDD in my Symfony 2.3 project and it seems to be struggling with some inconsistencies.
Depending on whether I use BehatContext or MinkContext as the base class for the FeatureContext class, I get different results.
If I use:
class FeatureContext extends BehatContext
everything is fine. however, if I use:
class FeatureContext extends MinkContext
I get errors that make it look like MinkContext no longer likes my regular expression, which the system itself generates. Could you help me understand:
FFFFFFF (::) failed steps (::) 01. Ambiguous match of "I am on homepage": to `/^I am on homepage$/` from Main\ReferralCaptureBundle\Features\Context\FeatureContext::iAmOnHomepage() to `/^(?:|I )am on (?:|the )homepage$/` from Behat\MinkExtension\Context\MinkContext::iAmOnHomepage() In step `Given I am on homepage'. From scenario `Successful registration when user provides all the required info'. # src/Main/ReferralCaptureBundle/Features/registration.feature:12 Of feature `registration'. # src/Main/ReferralCaptureBundle/Features/registration.feature 02. Ambiguous match of "I follow "sign up"": to `/^I follow "([^"]*)"$/` from Main\ReferralCaptureBundle\Features\Context\FeatureContext::iFollow() to `/^(?:|I )follow "(?P<link>(?:[^"]|\\")*)"$/` from Behat\MinkExtension\Context\MinkContext::clickLink() In step `And I follow "sign up"'. From scenario `Successful registration when user provides all the required info'. # src/Main/ReferralCaptureBundle/Features/registration.feature:12 Of feature `registration'. # src/Main/ReferralCaptureBundle/Features/registration.feature 03. Ambiguous match of "I fill in "username" with " email@email.com "": to `/^I fill in "([^"]*)" with "([^"]*)"$/` from Main\ReferralCaptureBundle\Features\Context\FeatureContext::iFillInWith() to `/^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/` from Behat\MinkExtension\Context\MinkContext::fillField() In step `When I fill in "username" with " email@email.com "'. From scenario `Successful registration when user provides all the required info'. # src/Main/ReferralCaptureBundle/Features/registration.feature:12 Of feature `registration'. # src/Main/ReferralCaptureBundle/Features/registration.feature 04. Ambiguous match of "I fill in "password" with "password123"": to `/^I fill in "([^"]*)" with "([^"]*)"$/` from Main\ReferralCaptureBundle\Features\Context\FeatureContext::iFillInWith() to `/^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/` from Behat\MinkExtension\Context\MinkContext::fillField() In step `And I fill in "password" with "password123"'. From scenario `Successful registration when user provides all the required info'. # src/Main/ReferralCaptureBundle/Features/registration.feature:12 Of feature `registration'. # src/Main/ReferralCaptureBundle/Features/registration.feature 05. Ambiguous match of "I press "register"": to `/^I press "([^"]*)"$/` from Main\ReferralCaptureBundle\Features\Context\FeatureContext::iPress() to `/^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/` from Behat\MinkExtension\Context\MinkContext::pressButton() In step `And I press "register"'. From scenario `Successful registration when user provides all the required info'. # src/Main/ReferralCaptureBundle/Features/registration.feature:12 Of feature `registration'. # src/Main/ReferralCaptureBundle/Features/registration.feature 06. Ambiguous match of "I should see "You have successfully registered"": to `/^I should see "([^"]*)"$/` from Main\ReferralCaptureBundle\Features\Context\FeatureContext::iShouldSee() to `/^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/` from Behat\MinkExtension\Context\MinkContext::assertPageContainsText() In step `Then I should see "You have successfully registered"'. From scenario `Successful registration when user provides all the required info'. # src/Main/ReferralCaptureBundle/Features/registration.feature:12 Of feature `registration'. # src/Main/ReferralCaptureBundle/Features/registration.feature 07. Ambiguous match of "I should be on homepage": to `/^I should be on homepage$/` from Main\ReferralCaptureBundle\Features\Context\FeatureContext::iShouldBeOnHomepage() to `/^(?:|I )should be on (?:|the )homepage$/` from Behat\MinkExtension\Context\MinkContext::assertHomepage() In step `And I should be on homepage'. From scenario `Successful registration when user provides all the required info'. # src/Main/ReferralCaptureBundle/Features/registration.feature:12 Of feature `registration'. # src/Main/ReferralCaptureBundle/Features/registration.feature 1 scenario (1 failed) 7 steps (7 failed)
FeatureContext.php
<?php namespace Main\ReferralCaptureBundle\Features\Context; use Main\ReferralCaptureBundle\Features\Context\FeatureContext; use Symfony\Component\HttpKernel\KernelInterface; use Behat\Symfony2Extension\Context\KernelAwareInterface; use Behat\MinkExtension\Context\MinkContext; use Behat\MinkExtension\Context\RawMinkContext; use Behat\Behat\Context\BehatContext, Behat\Behat\Exception\PendingException; use Behat\Gherkin\Node\PyStringNode, Behat\Gherkin\Node\TableNode; use Goutte\Client; // // Require 3rd-party libraries here: // require_once 'PHPUnit/Autoload.php'; require_once 'PHPUnit/Framework/Assert/Functions.php'; // /** * Feature context. */ class FeatureContext extends RawMinkContext //WHAT TO USE HERE!!!!!! implements KernelAwareInterface { private $kernel; private $parameters; /** * Initializes context with parameters from behat.yml. * * @param array $parameters */ public function __construct(array $parameters) { $this->parameters = $parameters; // $this->useContext('mink', new MinkContext); } /** * Sets HttpKernel instance. * This method will be automatically called by Symfony2Extension ContextInitializer. * * @param KernelInterface $kernel */ public function setKernel(KernelInterface $kernel) { $this->kernel = $kernel; } // // Place your definition and hook methods here: // // /** // * @Given /^I have done something with "([^"]*)"$/ // */ // public function iHaveDoneSomethingWith($argument) // { // $container = $this->kernel->getContainer(); // $container->get('some_service')->doSomethingWith($argument); // } // // // // /** * @Given /^I am on homepage$/ */ public function iAmOnHomepage() { $client = new Client(); $crawler = $client->request('GET', 'http://local.referral.com/'); $link = $crawler->selectLink('I am a Physician')->link(); if (!count($link)>0) { throw new Exception("Home Page Not Loaded:\n"); } } /** * @Given /^I follow "([^"]*)"$/ */ public function iFollow($arg1) { throw new PendingException(); } /** * @When /^I fill in "([^"]*)" with "([^"]*)"$/ */ public function iFillInWith($arg1, $arg2) { throw new PendingException(); } /** * @Given /^I press "([^"]*)"$/ */ public function iPress($arg1) { throw new PendingException(); } /** * @Then /^I should see "([^"]*)"$/ */ public function iShouldSee($arg1) { throw new PendingException(); } /** * @Given /^I should be on homepage$/ */ public function iShouldBeOnHomepage() { throw new PendingException(); } }
behat.yml
default: formatter: name: progress extensions: Behat\Symfony2Extension\Extension: mink_driver: true kernel: env: test debug: true Behat\MinkExtension\Extension: goutte: ~ base_url: 'http://local.mysite.com' default_session: symfony2
milof source share