我在 windows7 上使用 behat ..今天是我奋斗的第四天......我写了一个功能
#homepage.feature
Feature: To test the Home page loads successfully.
Scenario:
Given I am in a session
When I request the page "index.php"
Then I should get some content
和定义的步骤
/**
* @Given /^I am in a session$/
*/
public function iAmInASession() {
$driver = new \Behat\Mink\Driver\Selenium2Driver(
'firefox', 'base_url'
);
global $session;
$session = new \Behat\Mink\Session($driver);
// start session:
$session->start();
}
/**
* @When /^I request the page "([^"]*)"$/
*/
public function iRequestThePage($page)
{
global $session;
$session->visit($page);
}
/**
* @Then /^I should get some content$/
*/
public function iShouldGetSomeContent()
{
global $session;
if( $session->getPage()->getContent() )
echo $session->getPage()->getContent();
else
throw new Exception("The page couln't load successfully!");
}
它还向我展示了 147 个未定义的场景和 878 个未定义的默认步骤,而一些步骤是在 FeatureContext.php 中定义的
请帮忙!!!
最佳答案
对不起,我犯了几个错误....我没有创建功能目录,而是将我的功能添加到 vendor\behat\behat\features 目录并将步骤定义添加到 vendor\behat\behat\features\bootstrap\FeatureContext.php
为了让它工作,我必须通过键入在项目的根目录中创建功能目录 vendor\behat\behat\bin\behat -- 在命令提示符下初始化
所有功能都应该放在这个目录中,步骤应该在 root\features\bootstrap\FeatureContext.php 中
此外,uri 应该是 $session->visit() 中的 'http://'.localhost/Project/.$page
希望这对某人有帮助!
关于php - behat undefined step 虽然它应该被定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17606862/