behat - 当我尝试使用MinkContext扩展Behat FeatureContext时出现“已定义步骤”错误

标签 behat mink

我是Behat和Mink的新手,我想用MinkContext扩展FeatureContext,但是当我这样做时,每一步都会引发一个错误,指出在MinkContext中定义的第一个函数也在FeatureContext中定义(不是)。错误消息如下:

Step "/^(?:|I )am on (?:|the )homepage$/" 
is already defined in FeatureContext::iAmOnHomepage()

如果我从类中删除第一个函数,则每个步骤都会引发相同的错误,但是现在它引用了MinkContext类中的第二个函数:
Step "/^(?:|I )am on "(?P<page>[^"]+)"$/" 
is already defined in FeatureContext::visit()

使用RawMinkContext扩展FeatureContext可以正常工作。

是什么原因造成的?

----编辑(其他信息)------------

我正在使用Behat 3。

这是我当前的整个FeatureContext.php,仍然出现错误。我搜索了包含我的Behat安装的整个文件夹,但只能找到其中一个实例
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends MinkContext implements SnippetAcceptingContext
{
    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct()
    {
        date_default_timezone_set("US/Eastern");
    }



}

这是我的behat.yml文件:
# behat.yml
default:
    extensions:
        Behat\MinkExtension:
            goutte: ~
            selenium2: ~
            base_url: https://harvest.cals.ncsu.edu/
    suites:
        default:
            contexts:
            - FeatureContext
            - Behat\MinkExtension\Context\MinkContext

这是MinkContext.php的顶部:
命名空间Behat \ MinkExtension \ Context;
use Behat\Behat\Context\TranslatableContext;
use Behat\Gherkin\Node\TableNode;

/**
 * Mink context for Behat BDD tool.
 * Provides Mink integration and base step definitions.
 *
 * @author Konstantin Kudryashov <ever.zet@gmail.com>
 */
class MinkContext extends RawMinkContext implements TranslatableContext
{
    /**
     * Opens homepage
     * Example: Given I am on "/"
     * Example: When I go to "/"
     * Example: And I go to "/"
     *
     * @Given /^(?:|I )am on (?:|the )homepage$/
     * @When /^(?:|I )go to (?:|the )homepage$/
     */
    public function iAmOnHomepage()
    {
        $this->visitPath('/');
    }
...

---编辑2:工作版本------------

FeatureContext.php:
    <?php

    use Behat\Behat\Context\Context;
    use Behat\Behat\Context\SnippetAcceptingContext;
    use Behat\Gherkin\Node\PyStringNode;
    use Behat\Gherkin\Node\TableNode;
    use Behat\MinkExtension\Context\MinkContext;
    use Behat\Mink\WebAssert;

    /**
     * Defines application features from the specific context.
     */
    class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
    {
    ...

behat.yml(现在带有Selenium标签到enable Chrome)
# behat.yml
default:
    extensions:
        Behat\MinkExtension:
            goutte: ~
            selenium2: 
                wd_host: "http://127.0.0.1:4444/wd/hub"
                # chrome
                capabilities: { "browserName": "chrome", "browser": "chrome", "version":  "25", 'chrome': {'switches':['--no-sandbox']}}
            base_url: https://harvest.cals.ncsu.edu/
            browser_name: chrome
    suites:
        default:
            contexts:
            - FeatureContext

最佳答案

似乎MinkContext已加载两次:在FeatureContext和behat.yml中
如果从behat.yml中删除MinkContex,它应该可以工作。

关于behat - 当我尝试使用MinkContext扩展Behat FeatureContext时出现“已定义步骤”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38133811/

相关文章:

facebook - 在 Behat Mink 中的场景之间重置 session 。怎么禁用?

php - 尝试在 Mac 上设置 Selenium + Behat

symfony - symfony2.4 中的 Behat 3(学说访问)

javascript - 如何正确评估从 Behat 到 Selenium 的 javascript 代码?

selenium - Behat/水貂/ Selenium : intercepting AJAX calls possible?

php - 无法在虚拟机中运行 codeception - 无法找到和加载 Mink

behat - 如何使用 xdebug 调试 Behat 功能?

php - 是否可以使用 Behat + Mink 测试 CSS 样式表?

symfony - 使用 Behat 3、Doctrine 2 和 Symfony 2 测试数据库隔离

php - 如何更改 codeception phpbrowser/mink 超时