如何在Behat中启用Mink扩展

时间:2018-07-30 16:49:46

标签: php behat mink

我试图使用Mink进行简单的behat测试,但是当我运行behat命令时,出现错误:“未在Mink上下文类上设置Mink实例。是否启用了Mink扩展?(RuntimeException)”

这是我的behat.yml:

default:
    extensions:
        Behat\MinkExtension:
            base_url: "https://en.wikipedia.org"
            sessions: 
                default:
                    selenium2:
                        wd_host: http://localhost:4444/wd/hub

这是我的特色

Feature: search wikipedia
    In order to learn about BDD
    As a passionate developers
    I need to be able to search a general internet site

Scenario:
    Given I am in wikipedia
    When I search for "Behaviour driven development"
    Then the first heading should be "Behaviour-driven-development"

这是我的FeatureContext.php:

<?php

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\MinkExtension\Context\MinkContext; 
#use Behat\MinkContext\Context\RawMinkContext;

class FeatureContext extends MinkContext implements Context,   SnippetAcceptingContext
{

/**
 * @Given I am in wikipedia
 */
public function iAmInWikipedia()
{
    $this->visitPath("/");
}

/**
 * @When I search for :arg1
 */
public function iSearchFor($arg1)
{
    throw new PendingException();
}

/**
 * @Then the first heading should be :arg1
 */
public function theFirstHeadingShouldBe($arg1)
{
    throw new PendingException();
}
}

1 个答案:

答案 0 :(得分:0)

您还需要将您的上下文添加到behat.yml默认上下文中。

extensions级别之前,添加:

suites:
 default:
  contexts:
    - FeatureContext