【发布时间】:2011-08-16 10:56:45
【问题描述】:
我最近为一个相当复杂的项目编写了很多 selenium 1 测试。它们都是用php编写的,在selenium-server 1.0.7上运行流畅。
很明显,使用 firefox 5(和今天发布的 6)selenium 服务器 1.0.7 不再工作了。我试过了,但服务器只是打开空白窗口。
现在我正试图让这些测试在 selenium 网格上运行。我设法使用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
知道如何解决这个问题吗?我是否需要更改该网址?
【问题讨论】:
-
您能发布您的初始化代码,即进行设置的代码吗??
标签: phpunit selenium-grid