Struggling to get Mink working with Behat

China☆狼群 提交于 2019-12-21 04:08:06

问题


I've been following this guide (and installed everything through composer): http://docs.behat.org/cookbook/behat_and_mink.html and am attempting to get Behat + Mink working but everytime I try and run bin/behat I get the following error:

PHP Fatal error:  Call to a member function getSession() on a non-object in vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 80

That line of code is:

return $this->getMink()->getSession($name);

So for some reason the mink attribute is empty but I've no idea why.

My .feature file is exactly the same as the one in the guide, the FeatureContext class is also from the guide:

use Behat\Behat\Context\ClosuredContextInterface,
    Behat\Behat\Context\TranslatedContextInterface,
    Behat\Behat\Context\BehatContext,
    Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
    Behat\Gherkin\Node\TableNode;     

use Behat\MinkExtension\Context\MinkContext;

/**
 * Features context.
 */
class FeatureContext extends MinkContext 
{

}

and my vendor/behat/mink/behat.yml file contains:

context:
  extensions:
    Behat\MinkExtension\Extension:
      base_url:  'http://en.wikipedia.org/'
      goutte:    ~
      selenium2: ~

I've also tried making my class extend BehatContext and then call useContext but that gives me the same error. Behat itself seems to work it's just anything with Mink produces that fatal error and I've no idea how to fix it.


回答1:


This is because you should copy vendor/behat/behat/behat.yml.dist file to your/project/root/behat.yml, rather than editing the file in the vendor dir and add extesions to the default section.

And here's what it looks like:

default:
  extensions:
    Behat\MinkExtension\Extension:
      base_url: http://lunch-time/app_dev.php
      goutte: ~
      selenium2: ~

  paths:
    features:  features
    bootstrap: features/bootstrap

annotations:
  paths:
    features: features/annotations

closures:
  paths:
    features: features/closures



回答2:


I was facing a similar issue. We need to tell Symfony to initialize the object.

Mine got fixed after adding under the default > suites > my_suite.

contexts: [Behat\MinkExtension\Context\MinkContext]

Here is how my new behat.yml looks like.

default:
    suites:
        my_suite:
            type: symfony_bundle
            bundle: AcmeProjectManagerBundle
            contexts: [Behat\MinkExtension\Context\MinkContext]
extensions:
    Behat\Symfony2Extension: ~
    Behat\MinkExtension:
        base_url: http://en.wikipedia.org
        goutte: ~
        selenium2: ~
        sessions:
            default:
                symfony2: ~


来源:https://stackoverflow.com/questions/10918475/struggling-to-get-mink-working-with-behat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!