Объркване между BehatContext и MinkContext

Опитвам се да направя BDD в моя проект Symfony 2.3 и изглежда, че се боря с някои несъответствия.

В зависимост от това дали използвам 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 protected]"":
    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 protected]"'.
    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

person milof    schedule 13.08.2013    source източник


Отговори (1)


Разширете RawMinkContext, ако имате нужда от достъп до Mink Session (за автоматизация на браузъра).

Не използвайте Goutte директно.

BehatContext е основен контекст, който би бил избор по подразбиране за повечето от вашите собствени контексти, когато не се нуждаете от Mink.

MinkContext е специализиран контекст, който ви дава достъп до сесията Mink (същото като RawMinkContext). Той обаче съдържа и някои основни дефиниции на стъпки. Ето защо никога не трябва да го разширявате, а по-скоро да го използвате като подконтекст. Ще можете да го разширите само веднъж, тъй като дефинициите на стъпките не могат да бъдат дублирани.

Въпросът е много подобен на другия ви въпрос (погледнете там за пример за използване на Mink): Какво не е наред с моя FeatureContext?

Използването на Behat не означава, че следвате BDD. За да научите повече за това, прочетете следните книги:

За да прочетете за инструментите:

person Jakub Zalas    schedule 14.08.2013