【问题标题】:Yii PHPUnit With SeleniumYii PHPUnit 与 Selenium
【发布时间】:2014-10-24 16:22:15
【问题描述】:

我在使用 Yii、PHPUnit 和 Selenium 启动自动化测试时遇到了一些问题 我已经设置了 Selenium 和 PHPUnit 并且当我运行 phpunit 时。我收到此错误:

    Warning: include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such 
file or directory in path_to/framework/YiiBase.php on line 427

    Warning: include(): Failed opening 'PHPUnit_Extensions_Story_TestCase.php' for inclusion 
(include_path='.:') in path_to/framework/YiiBase.php on line 427
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: The path to the driver executable    
must be set by the phantomjs.binary.path capability/system property/PATH variable; for more 
information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded 
from http://phantomjs.org/download.html

我在后台运行 Selenium RC。我在测试文件夹中也有 PHPunit 文件夹,带有 Story 和 selenium 扩展。

我的代码看起来像这样

define('TEST_BASE_URL','http://some_local_url/');
class WebTestCase extends PHPUnit_Extensions_Selenium2TestCase
{
    /**
     * Sets up before each test method runs.
     * This mainly sets the base URL for the test application.
     */
    protected function setUp()
    {
        parent::setUp();

        $this->setHost('localhost');

        $this->setPort(4444);
        $this->setBrowserUrl(TEST_BASE_URL);
    }
}

class SiteTest extends WebTestCase
{
    public function testIndex()
    {
        $this->open('');
        $this->assertTextPresent('Welcome');
    }
}

【问题讨论】:

  • 能否包含您的index-test.phpsome_local_url 的输入脚本?
  • 我需要 index-test.php 吗?可能是问题?!里面应该放什么?

标签: php unit-testing selenium yii phpunit


【解决方案1】:

事实证明,Selenium 服务器需要 phantomjs(显然感谢队长)才能正常运行。我只是将服务器 .jar 文件放在与 phantomjs 二进制文件相同的文件夹中,之后测试运行正常。

【讨论】:

    【解决方案2】:

    您似乎没有在测试输入脚本(默认为index-test.php)中正确配置框架的路径。您还应该在此处设置配置文件。如果没有这个,您的测试将使用与您的应用程序相同的设置(数据库、会话)运行。

    这是演示博客index-test.php 的内容:https://github.com/yiisoft/yii/blob/master/demos/blog/index-test.php

    <?php
    /**
     * This is the bootstrap file for test application.
     * This file should be removed when the application is deployed for production.
     */
    
    // change the following paths if necessary
    $yii=dirname(__FILE__).'/../../framework/yii.php';
    $config=dirname(__FILE__).'/protected/config/test.php';
    
    // remove the following line when in production mode
    // defined('YII_DEBUG') or define('YII_DEBUG',true);
    
    require_once($yii);
    Yii::createWebApplication($config)->run();
    

    【讨论】:

    • 我这样做了,但仍然没有运气,得到相同的错误:s 我的配置中应该有什么?
    猜你喜欢
    • 1970-01-01
    • 2013-01-05
    • 2014-01-07
    • 2017-05-07
    • 2012-07-23
    • 2013-12-19
    • 2023-03-14
    • 2012-08-21
    • 2014-11-30
    相关资源
    最近更新 更多