我在正确设置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文件夹中,我有一个包含文件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 在特性文件夹I中有一个引导文件夹,其中包含"FeatureContext“文件。
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“时,它会在浏览器中触发测试,通过所有测试,但无法识别步骤定义,它声明”您可以用这些代码段实现未定义步骤的步骤定义:“然后给出一个示例。
发布于 2013-12-25 00:17:12
您需要将自动加载程序配置为从自定义引导文件夹加载类。
如果您使用的是composer,下面是一个如何实现的示例:
"autoload": {
"psr-0": { "": ["src/", "bin/features/bootstrap/"]}
}注释: bin文件夹是放置特性或上下文文件的一个非常奇怪的位置。
有答案的相关问题:Behat + Symfony, Custom definitions are not loaded (实际上,可能是重复的)。
https://stackoverflow.com/questions/20764588
复制相似问题