我是Behat和Mink的新手,我正在尝试使用MinkContext扩展FeatureContext,但是当我这样做时,每一步都会抛出一个错误,指出MinkContext中定义的第一个函数也是在FeatureContext中定义的(它不是' T)。错误消息如下:
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
答案 0 :(得分:1)
似乎MinkContext被加载了两次:在FeatureContext和behat.yml中 如果从behat.yml中删除MinkContex,它应该可以工作。