我是Behat和Mink的新手,我試圖用MinkContext擴展FeatureContext,但是當我這樣做時,每一步都會拋出一個錯誤,指出在MinkContext中定義的第一個函數也在FeatureContext中定義(不是)。該錯誤消息是如下:當我嘗試使用MinkContext擴展Behat 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可以正常工作。
這可能是什麼原因造成的?
---- EDIT(附加信息)------------
我使用貝哈特3.
這是我整個當前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;
/**
* 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 <[email protected]>
*/
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(現在硒標籤到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。你使用哪種版本的Behat。使用您刪除的方法從FeatureContext發佈一些代碼片段。 – lauda
它確實看起來像被加載了兩次,但我無法在任何地方找到第二個副本,所以它肯定是MinkContext.php以某種方式被調用兩次。 – Rebecca
也許你在使用behat.yml中的MinkContext,刪除它,它應該工作。 behat.yml應該只包含你的本地上下文 – lauda