Skip to content

Commit 2fd56ba

Browse files
committed
Exploring giorgiosironi#144: the Selenium1-WebDriver shared browser crashes at the open() command
1 parent a4b6421 commit 2fd56ba

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

PHPUnit/Extensions/SeleniumTestCase/Driver.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,26 @@ class PHPUnit_Extensions_SeleniumTestCase_Driver
145145
*/
146146
protected $verificationErrors = array();
147147

148+
/**
149+
* @var array
150+
*/
151+
private $webDriverCapabilities;
152+
148153
public function __construct()
149154
{
150155
if (empty(self::$autoGeneratedCommands)) {
151156
self::autoGenerateCommands();
152157
}
153158
}
154159

160+
/**
161+
* Only browserName is supported.
162+
*/
163+
public function setWebDriverCapabilities(array $capabilities)
164+
{
165+
$this->webDriverCapabilities = $capabilities;
166+
}
167+
155168
/**
156169
* @return string
157170
*/
@@ -163,6 +176,21 @@ public function start()
163176
);
164177
}
165178

179+
if ($this->webDriverCapabilities !== NULL) {
180+
181+
$seleniumServerUrl = PHPUnit_Extensions_Selenium2TestCase_URL::fromHostAndPort($this->host, $this->port);
182+
$driver = new PHPUnit_Extensions_Selenium2TestCase_Driver($seleniumServerUrl);
183+
$session = $driver->startSession($this->webDriverCapabilities['browserName'], new PHPUnit_Extensions_Selenium2TestCase_URL($this->browserUrl));
184+
$webDriverSessionId = $session->id();
185+
$this->sessionId = $this->getString(
186+
'getNewBrowserSession',
187+
array($this->browser, $this->browserUrl, '',
188+
"webdriver.remote.sessionid=$webDriverSessionId")
189+
);
190+
191+
$this->doCommand('setTimeout', array($this->seleniumTimeout * 1000));
192+
}
193+
166194
if (!isset($this->sessionId)) {
167195
$this->sessionId = $this->getString(
168196
'getNewBrowserSession',
@@ -918,10 +946,11 @@ public function __call($command, $arguments)
918946
*
919947
* @param string $command
920948
* @param array $arguments
949+
* @param array $namedArguments
921950
* @return string
922951
* @author Seth Casana <[email protected]>
923952
*/
924-
protected function doCommand($command, array $arguments = array())
953+
protected function doCommand($command, array $arguments = array(), array $namedArguments = array())
925954
{
926955
$url = sprintf(
927956
'http://%s:%s/selenium-server/driver/',
@@ -940,6 +969,9 @@ protected function doCommand($command, array $arguments = array())
940969
$postData .= sprintf('&%s=%s', $argNum, urlencode(trim($arguments[$i])));
941970
}
942971
}
972+
foreach ($namedArguments as $key => $value) {
973+
$postData .= sprintf('&%s=%s', $key, urlencode($value));
974+
}
943975

944976
if (isset($this->sessionId)) {
945977
$postData .= sprintf('&%s=%s', 'sessionId', $this->sessionId);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
class Tests_Selenium2TestCase_WebDriverBackedSeleniumTest extends PHPUnit_Extensions_SeleniumTestCase
3+
{
4+
public function setUp()
5+
{
6+
if (version_compare(phpversion(), '5.3.0', '<')) {
7+
$this->markTestSkipped('Functionality available only under PHP 5.3.');
8+
}
9+
$this->setHost(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST);
10+
$this->setPort((int)PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT);
11+
$this->setBrowser('*webdriver');
12+
if (!defined('PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL')) {
13+
$this->markTestSkipped("You must serve the selenium-1-tests folder from an HTTP server and configure the PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL constant accordingly.");
14+
}
15+
$this->setBrowserUrl(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_TESTS_URL);
16+
$this->setWebDriverCapabilities(array(
17+
'browserName' => PHPUNIT_TESTSUITE_EXTENSION_SELENIUM2_BROWSER
18+
));
19+
}
20+
21+
public function testAPageIsOpenedWithWebDriver()
22+
{
23+
$this->markTestIncomplete('Crashes the opened browser deterministically.');
24+
$this->open('html/test_open.html');
25+
$this->assertEquals('This is a test of the open command.', $this->getBodyText());
26+
}
27+
}

0 commit comments

Comments
 (0)