2011-09-27 97 views
5

在虚拟机(干净,新鲜的Ubuntu服务器11.04)上,我创建了一个测试网站,如Creating Your First Yii Application中所述,现在我想使用webdriver-test创建简单测试。网络驱动程序测试不可用

我设置适当的TEST_BASE_URL在保护/测试/ WebTestCase.php和创建保护/测试/功能/ 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('[email protected]'), 'The is no "[email protected]" text on result page!'); 
    } 
} 

运行它看起来像这样:

[email protected]:/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. 

注意它正在抱怨来自PHPUnit_Extensions_SeleniumTestCase_Driver的setBrowserUrl(),它与CWebDriverTestCase中的不一样。

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

我使用:

  • Ubuntu的服务器11.04
  • YII 1.1.8.r3324
  • webdriver的测试1.1B
  • 如bugs.launchpad描述的PHPUnit 3.5.15(修复.net/ubuntu/+ source/phpunit/+ bug/701544)

请帮忙!

+0

我也有这个问题。 setBrowserUrl方法设置$ baseUrl属性而不是$ browserUrl属性。 – jcfollower

回答

0

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