无法启用Behat3 MinkExtension

时间:2016-07-28 09:09:35

标签: php behat mink selenium-grid2

我想通过使用Behat,Mink和SeleniumGrid获取屏幕截图

但我得到了这个错误:

  

鉴于我去了   " mySite.org/private" #   FeatureContext ::访问()         尚未在Mink上下文类上设置Mink实例。你启用了Mink Extension吗? (RuntimeException的)       │       ╳Mink实例尚未在Mink上下文类中设置。你启用了Mink Extension吗? (RuntimeException的)       │       └─@ AfterStep#Feat

我的behat.yml:

default:
extensions:
    Behat\Symfony2Extension: ~
    Behat\MinkExtension:
        base_url: http://integration.fvs.dev.intern.etecture.de/private-clients
        browser_name: 'firefox'
        selenium2:
            wd_host: http://hub.selenium.intern.etecture.de:4444/wd/hub
            capabilities: { "browser": "firefox", "version": "14"}
        goutte: ~
        sessions:
            goutte:
                goutte: ~
            selenium2:
                selenium2: ~
            symfony2:
                symfony2: ~
suites:
    backend:
        type: symfony_bundle
        mink_session: selenium2
        contexts:
            - app\features\bootstrap\FeatureContext:
                screen_shot_path: app/screenshot

我的FeatureContext.php

class FeatureContext extends MinkContext
{
    private $screenShotPath;

    public function __construct()
    {
        $this->screenShotPath = "/app/screenshot";
    }

    /**
     * Take screen-shot when step fails. Works only with Selenium2Driver.
     *
     * @AfterStep
     * @param AfterStepScope $scope
     */
    public function takeScreenshotAfterFailedStep(AfterStepScope $scope)
    {
        if (99 === $scope->getTestResult()->getResultCode()) {
            $driver = $this->getSession()->getDriver();

            if (! $driver instanceof Selenium2Driver) {
                return;
            }

            if (! is_dir($this->screenShotPath)) {
                mkdir($this->screenShotPath, 0777, true);
            }

            $filename = sprintf(
                '%s_%s_%s.%s',
                $this->getMinkParameter('browser_name'),
                date('Ymd') . '-' . date('His'),
                uniqid('', true),
                'png'
            );

            $this->saveScreenshot($filename, $this->screenShotPath);
        }
    }

    /**
     * @Then /^I should see the css selector "([^"]*)"$/
     * @Then /^I should see the CSS selector "([^"]*)"$/
     */
    public function iShouldSeeTheCssSelector($css_selector) {
        $element = $this->getSession()->getPage()->find("css", $css_selector);
        if (empty($element)) {
            throw new \Exception(sprintf("The page '%s' does not contain the css selector '%s'", $this->getSession()->getCurrentUrl(), $css_selector));
        }
    }

    /**
     * @Then /^I should not see the css selector "([^"]*)"$/
     * @Then /^I should not see the CSS selector "([^"]*)"$/
     */
    public function iShouldNotSeeAElementWithCssSelector($css_selector) {
        $element = $this->getSession()->getPage()->find("css", $css_selector);

        if (empty($element)) {
            throw new \Exception(sprintf("The page '%s' contains the css selector '%s'", $this->getSession()->getCurrentUrl(), $css_selector));
        }
    }
}

有没有想法? THX

1 个答案:

答案 0 :(得分:1)

可能会查看您的示例,问题出在您的behat.yml配置文件中。 default是您个人资料的名称,extensions密钥是该个人资料的子级。因此,default个配置文件下方的每一行都应添加4个空格。

default:
    extensions:
        Behat\Symfony2Extension: ~
        Behat\MinkExtension:
        base_url: http://integration.fvs.dev.intern.etecture.de/private-clients
        browser_name: 'firefox'
        selenium2:
            wd_host: http://hub.selenium.intern.etecture.de:4444/wd/hub
            capabilities: { "browser": "firefox", "version": "14"}
        goutte: ~
        sessions:
            goutte:
                goutte: ~
            selenium2:
                selenium2: ~
            symfony2:
                symfony2: ~
    suites:
        backend:
            type: symfony_bundle
            mink_session: selenium2
            contexts:
                - app\features\bootstrap\FeatureContext:
                    screen_shot_path: app/screenshot