Selenium RC / PHPUnit测试总是超时?

时间:2011-10-12 13:14:54

标签: selenium phpunit

我真的很擅长测试,所以对我很轻松。我已经让Seleneium与Pear,PHPUnit和Sauce Labs类SauceOnDemandTestCase.php合作。我可以运行测试并做一个简单的就好了。但现在我正在进行更复杂的测试并继续接收超时消息。我在StackO上看到了错误,其他人也在用IE浏览器。现在我的测试是使用Firefox,所以我不知道为什么会这样。另一篇文章在这里:

PHPUnit_Framework_Exception: Could not connect to the Selenium RC server when I run with Hudson

我尝试将我的等待函数更改为waitForElement或waitForVisible但无效,但仍然失败并出现一个错误。这是我的XML日志文件输出,如果它对您有用:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="ExampleTest" file="C:\websites\saucelabs\ExampleTest.php" tests="1" assertions="0" failures="0" errors="1" time="44.717224">
    <testsuite name="ExampleTest: Testing Selenium 1 in PHP at Sauce (FF 7)" tests="1" assertions="0" failures="0" errors="1" time="44.717224">
      <testcase name="test_example" class="ExampleTest" file="C:\websites\saucelabs\ExampleTest.php" line="23" assertions="0" time="44.717224">
        <error type="PHPUnit_Framework_Exception">ExampleTest::test_example with browser firefox 7 Windows 2003
PHPUnit_Framework_Exception: 
Response from Selenium RC server for open(/Home).
Timed out after 30000ms.

Current Browser URL: http://www.vehicleportal.co.uk/Home
Sauce Labs Job: https://saucelabs.com/jobs/8b202faaa055e213233637610fcd4448


</error>
      </testcase>
    </testsuite>
  </testsuite>
</testsuites>

我的脚本类看起来像这样:

<?php

date_default_timezone_set('Europe/London');

require_once 'PHPUnit/Extensions/SeleniumTestCase/SauceOnDemandTestCase.php';
require_once 'Log.php';

class ExampleTest extends PHPUnit_Extensions_SeleniumTestCase_SauceOnDemandTestCase {
    public static $browsers = array(
          array(
            'name' => 'Testing Selenium 1 in PHP at Sauce (FF 7)',
            'browser' => 'firefox',
            'os' => 'Windows 2003',
            'browserVersion' => '7',
          )
    );

    function setUp() {
        $this->setBrowserUrl('http://www.vehicleportal.co.uk');

    }

    function test_example() {
        //$this->open('/');
        //$this->assertTitle('Cross browser testing with Selenium - Sauce Labs');

        //$file = Log::factory('file', 'out.log', 'TEST');
        //$file->log("info");

        $this->open("/Home");
        $this->click("hlLogin1");
        $this->waitForVisible('h1');
        $this->type("txtLoginEmailAddress", "user@volkswagen.co.uk");
        $this->type("txtLoginPassword", "password");
        $this->click("btnLogin");
        $this->waitForVisible('h1');
        $this->verifyText("id=hlVehicleLookup", "Vehicle Lookup");
        $this->click("css=img[alt=Home]");
        $this->waitForVisible('h1');
        $this->click("link=Logout");
        $this->waitForVisible('h1');
    }
}

为了给出一些背景知识,我必须在Selenium IDE或SauceLabs构建器中创建我的脚本然后转换它,以便从Selenium IDE中获取步骤。

我有第二个小问题,我想更好地理解。我一直在说:

“注意:未定义的索引:第149行的c:\ php \ PEAR \ PHPUnit \ Extensions \ SeleniumTestCase \ SauceOnDemandTestCase.php中的HOME”

该文件的第149行: $ yml_path = realpath($ _ SERVER ['HOME'])。 '/.sauce/ondemand.yml';

SauceLabs的类:https://github.com/saucelabs/phpunit-selenium-sauceondemand/blob/master/PHPUnit/Extensions/SeleniumTestCase/SauceOnDemandTestCase.php

我可以删除对此的引用,但为什么会出现? Afterall $ _SERVER ['home']不是$ _SERVER数组的PHP。

更新

我们有一个理论认为超时是由于SL没有使用真正的浏览器造成的。我完全删除了所有验证步骤,但仍然发生超时。

2 个答案:

答案 0 :(得分:1)

firefox窗口是否打开?例如,如果使用I.E配置它,您会得到相同的错误吗?

因为,这可能与Selenium配置为使用Firefox 3.6版本(距离今天的7.0.1很远)的问题有关,因此您可以更改它。 Here is a guide这将有助于您改变这种情况。

还有一件事,尝试在setUp()函数中添加以下行:

$this->setBrowser("*firefox");

希望这有帮助!让我发布。

答案 1 :(得分:1)

我认为这是因为尝试使用超时太小的测试来运行。我增加了超时,一切都很好。

除了一个浏览器外,所有浏览器都可以。报告的错误是:

“Selenium RC服务器对waitForPageToLoad(30000)的响应。在30000ms后超时”

我无法看到增加超时时间的重点,因为它适用于使用相同浏览器版本的Selenium Server,因此它必须与Sauce有关。最后我尝试将时间限制增加到90秒(90000)毫秒,完成了这项工作。我有一个理论认为,由于使用Sauce延长了测试时间,这必然导致脚本在这个浏览器上超时。无论如何,解决方案是按照错误消息的建议增加超时。

我在这里写到:

TestIgniter Blog Post

相关问题