我最近为一个相当复杂的项目编写了很多 selenium 1 测试。它们都是用 php 编写的,可以在 selenium-server 1.0.7 上顺利运行。
显然,使用 firefox 5(和今天发布的 6)selenium 服务器 1.0.7 不再工作了。我试过了,但服务器只是打开空白窗口。
现在我正试图让这些测试在硒网格上运行。我设法使用grid v1获得了一个集线器和几个远程控制,但它们只打开空白窗口,就像旧服务器一样。所以我想我需要升级到 grid v2。
出于某种原因,我可以让客户端连接到集线器,但如果我尝试对集线器运行测试,它似乎根本无法连接(“PHPUnit_Framework_Exception:无法连接到 Selenium RC 服务器”)。我尝试在 selenium 独立服务器 2.4.0 上运行它们,这似乎确实有效。
我在一个论坛上读到,selenium grid 2 不能与 phpunit 一起工作(还没有?)。
如何让我的测试在网格上运行?phpunit 连接服务器缺少什么?我很感激任何帮助!
我按如下方式设置集线器:
java -jar selenium-server-standalone-2.4.0.jar -role hub
还有两个奴隶:
java -jar selenium-server-standalone-2.4.0.jar -role rc -hub http://127.0.0.1:4444/grid/register -port 5555
java -jar selenium-server-standalone-2.4.0.jar -role webdriver -hub http://127.0.0.1:4444/grid/register -port 5556
到目前为止,一切似乎都在工作,因为我在网格控制台(http://localhost:4444/grid/console)中看到了两个节点。
所以这是我在代码中所做的所有初始化:
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class Grid_Test extends PHPUnit_Extensions_SeleniumTestCase
{
public $captureScreenshotOnFailure = false;
public static $browsers = array(
'FFLinux' => array(
'name' => 'Firefox on Linux',
'browser' => '*firefox',
'host' => '127.0.0.1',
'port' => 4444,
'timeout' => 30000
));
public function setUp()
{
$this->setBrowserUrl('http://www.google.com');
}
public function testGridWorking()
{
$this->open('/');
$this->assertTrue(false);
}
}
此代码仍然适用于独立服务器 2.4.0。正如预期的那样,它在最后一行失败。
异常似乎是在 PHPUnit/Extentions/SeleniumTestCase/Driver.php 中抛出的。似乎有问题。
protected function doCommand($command, array $arguments = array())
{
$url = sprintf(
'http://%s:%s/selenium-server/driver/?cmd=%s',
$this->host,
$this->port,
urlencode($command)
);
[...]
$handle = @fopen($url, 'r', FALSE, $context);
if (!$handle) {
throw new PHPUnit_Framework_Exception(
'Could not connect to the Selenium RC server.'
);
}
[...]
}
当我在浏览器中请求http://localhost:4444/selenium-driver/driver时,我得到:
HTTP ERROR: 500
org.openqa.grid.internal.GridException: Session not available - []
RequestURI=/selenium-server/driver
知道如何解决这个问题吗?我是否需要更改该网址?