webdriver-test无法使用

eta*_*024 5 phpunit webdriver yii selenium-webdriver

在虚拟机(干净,新鲜的Ubuntu服务器11.04)上,我创建了一个测试网站,如创建您的第一个Yii应用程序中所述,现在我想使用webdriver-test创建简单的测试.

我在protected/tests/WebTestCase.php中设置了正确的TEST_BASE_URL并创建了protected/tests/functional/MySimpleTest.php

<?php
Yii::import( 'ext.webdriver-bindings.CWebDriverTestCase' );

class MySimpleTest extends CWebDriverTestCase {

    protected function setUp() {
        parent::setUp( '192.168.57.1', 4444, 'firefox' );
    }

    public function testMySite() {
        $this->get( TEST_BASE_URL );

        $qElem = $this->findElementBy( LocatorStrategy::linkText, 'Users' );
        $this->assertNotNull( $qElem, 'There is no "Users" link!' );

        $qElem->clickAndWait();

        $this->assertTrue( $this->isTextPresent( 'test1@example.com' ), 'The is no "test1@example.com" text on result page!' );
    }
}
Run Code Online (Sandbox Code Playgroud)

运行它看起来像这样:

etam@ubuntu:/var/www/test/protected/tests$ phpunit functional/MySimpleDbTest.php
PHPUnit 3.5.15 by Sebastian Bergmann.

E

Time: 5 seconds, Memory: 5.25Mb

There was 1 error:

1) MySimpleTest::testMySite
PHPUnit_Framework_Exception: setBrowserUrl() needs to be called before start().

/opt/yii-1.1.8.r3324/framework/test/CWebTestCase.php:61
/var/www/test/protected/extensions/webdriver-bindings/CWebDriverTestCase.php:156

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
Run Code Online (Sandbox Code Playgroud)

请注意,它抱怨PHPUnit_Extensions_SeleniumTestCase_Driver中的setBrowserUrl(),它与CWebDriverTestCase中的setBrowserUrl()不同.

我试图找出发生了什么,但这对我来说太复杂了.它看起来像新旧selenium API一起存在的问题,但我不确定.

我正在使用:

  • Ubuntu服务器11.04
  • yii 1.1.8.r3324
  • webdriver-test 1.1b
  • phpunit 3.5.15(修复如bugs.launchpad.net/ubuntu/+source/phpunit/+bug/701544中所述)

请帮忙!

mar*_*ake 0

您需要在parent::setup() 方法之后调用setBrowseUrl() 方法,因为selenium 需要此url 来解析测试用例上的相对路径。这样你就可以调用 open('full.url.com/someAction') 或直接调用 open('/someAction') ,两者都会进入同一页面。