我在正确设置Behat框架时遇到了困难。测试运行正常,但是没有从FeatureContext文件中获取步骤定义。从没有运气的其他问题尝试过答案。 behat.yml文件当前存储在项目的根目录中:
default:
paths:
features: 'bin/features'
bootstrap: 'bin/features/bootstrap'
context:
class: 'FeatureContext'
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2: ~
在项目的根目录中,我有一个bin文件夹,其中包含标准的behat文件:behat.bat,webunit.bat等。在bin文件夹中,我有features文件夹,其中包含文件search.feature:
Feature: Search
In order to find a word
As a website user
I need to be able to search for a word
@javascript
Scenario: Searching for a word that does exist
Given I am on "http://drupalcamp.mx/search/"
When I fill in "Escriba las palabras clave" with "behat, mink"
And I press "Buscar"
Then I should see "Behavior Driven Development"
And I follow "Behavior Driven Development"
And I wait for 5 seconds
在features文件夹中,我有一个包含文件“FeatureContext”
的bootstrap文件夹 namespace features;
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
/**
* Features context.
*/
class FeatureContext extends MinkContext
{
/**
* Initializes context.
* Every scenario gets it's own context object.
*
* @param array $parameters context parameters (set them up through behat.yml)
*/
public function __construct(array $parameters)
{
// Initialize your context here
}
/**
* @Given /^I wait for (\d+) seconds$/
*/
public function iWaitForSeconds($seconds)
{
$this->getSession()->wait($seconds*1000);
}
当我在CL中从项目的根目录运行“behat”时,它会在浏览器中触发测试,传递所有但未能识别步骤定义,它指出“您可以使用这些步骤定义未定义的步骤片段:“然后它给出了一个例子。
答案 0 :(得分:0)
您需要配置自动加载器以从自定义引导程序文件夹加载类。
如果你正在使用作曲家,这里有一个如何做到的例子:
"autoload": {
"psr-0": { "": ["src/", "bin/features/bootstrap/"]}
}
注意: bin 文件夹是放置功能或上下文文件的奇怪位置。
相关问题的回答:Behat + Symfony, Custom definitions are not loaded(实际上,可能是重复的)。