Symfony BehatContext和MinkContext之间的混淆

Symfony BehatContext和MinkContext之间的混淆,symfony,behat,mink,goutte,Symfony,Behat,Mink,Goutte,我试图在我的Symfony 2.3项目中进行BDD,但似乎遇到了一些不一致之处 根据我是使用BehatContext还是MinkContext作为FeatureContext类的基类,我会得到不同的结果 如果我使用: class FeatureContext extends BehatContext 一切都很好。但是,如果我使用: class FeatureContext extends MinkContext 我得到了一些错误,这使得MinkContext看起来不再喜欢系统自己生成的正则

我试图在我的Symfony 2.3项目中进行BDD,但似乎遇到了一些不一致之处

根据我是使用BehatContext还是MinkContext作为FeatureContext类的基类,我会得到不同的结果

如果我使用:

class FeatureContext extends BehatContext 
一切都很好。但是,如果我使用:

class FeatureContext extends MinkContext
我得到了一些错误,这使得MinkContext看起来不再喜欢系统自己生成的正则表达式。你能帮我理解一下吗

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)

如果需要访问Mink会话(用于浏览器自动化),请扩展
RawMinkContext

不要直接使用痛风

BehatContext
是一个基本上下文,当您不需要貂皮时,它将是您自己的大多数上下文的默认选择

MinkContext
是一个专门的上下文,允许您访问Mink会话(与
RawMinkContext
相同)。但是,它还包含一些基本步骤定义。这就是为什么您永远不应该扩展它,而应该将它用作子上下文。您只能扩展它一次,因为步骤定义不能重复

这个问题与您的另一个问题非常相似(请看那里的水貂用法示例):

使用Behat并不意味着您正在遵循BDD。要了解更多信息,请阅读以下书籍:

要了解这些工具,请执行以下操作:

  • 水貂:
  • MinkExtension:
  • MinkContext类:
  • RawMinkContextClass:
<?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();
    }


}
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