php - behat undefined step 虽然它应该被定义

标签 php windows selenium-webdriver behat mink

我在 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/

相关文章:

php - 通过foreach循环插入多个表单域的数据

php - 为什么我的嵌套查询使 SQL Server 速度减慢这么多?

c# - 可从 C# 中使用的基准库

angularjs - 有什么方法可以优化/加速使用 Protractor 将数据发送到 UI 的速度吗?

python - 无法使用 selenium webdriver 单击网页中的链接

php - PHP 中是否可以中断文件上传(使用 APC)?

php - 将 SELECT 查询的结果打印为 PHP 中的预格式化文本?

javascript - NPM 环境变量在 Windows 中不起作用?

java - 在 Java 1.4 中访问 Windows 系统变量

selenium - 使用Robot框架的未处理错误 “Cannot find context with specified id”