facebook/php-webdriver — Issue #20: "UnhandledWebDriverError: Connection reset" with FF but not IE
Author: mstone42
Created: 2012-01-12 19:15:02+00:00
State: open

I am getting the "**UnhandledWebDriverError: Connection reset**" error during the call to "$web_driver->session();".
I can execute the exact same code with IE8, and everything works fine, but when using Firefox 7, it throws the error.
I've seen the various issues posted here regarding this & similar errors, but none of them seem to actually have an answer. I'm not a Java programmer, so I'm hoping someone can tell me definitively if this is a WebDriver issue or a Selenium issue, and how to fix it.

Any help would be greatly appreciated.

So, here are my particulars, note that everything is running on the local machine:

* Windows XP, SP3
* Java jre-6u30
* Selenium 2.16.1
* PHP 5.3.9
* PHPUnit 3.6.7
* WebDriver commit#3771050
* Firefox 7
* Internet Explorer 8

May not be relevant, but I also have Apache 2.2.21 running locally as well. I have tried stopping Apache, but test results are the same.

Here's what I am doing to test:
1. Change the value of BROWSER' in the xml config file to 'internet explorer'
2. Run the test: *phpunit -c config.xml'
2.a. Test complete successfully
3. Change the value of BROWSER' in the xml config file to 'firefox'
4. Run the test: *phpunit -c config.xml'
4.a. The error is thrown even before the FF browser window opens, and (not surprisingly) the default text "This is the initial start page for the WebDriver server." never displays once the window does open. Yes, I've tried putting "sleep()" commands all over the place to no good effect.

***
The PHP test script
PHP constants are derived from xml config passed into *phpunit -c config.xml*

require_once '__init__.php';

class LoginTest extends PHPUnit_Framework_TestCase {
protected $_session;

public function setUp() {
parent::setUp();
$web_driver = new WebDriver();
$this->_session = $web_driver->session(BROWSER);
}

public function tearDown() {
// commented out 'cuz session object is not created with FF
//	$this->_session->close();
unset($this->_session);
parent::tearDown();
}

public function test_login() {
$this->_session->open(BROWSER_URL.'login.html?LogOut=1');

$this->_session->element('id','login_username')->value(split_keys(ADMIN_USER));
$this->_session->element('id','login_passwd')->value(split_keys(ADMIN_PASSWORD));
$this->_session->element('id','btn_Login')->click();

$this->assertSame(
BROWSER_URL.'Admin/index.html',
$this->_session->url()
);

$this->_session->element('link text','Logout')->click();
}
}

// http://edvanbeinum.com/using-selenium-2-phpunit-to-automate-browser-testing
function split_keys($toSend){
$payload = array("value" => preg_split("//u", $toSend, -1, PREG_SPLIT_NO_EMPTY));
return $payload;
}

***
PHPUnit config file

<phpunit
colors="false" verbose="true"
stopOnFailure="false">
<php>
<includePath>.
<const name="BROWSER" value="firefox" />
<!-- const name="BROWSER" value="internet explorer" / -->
<const name="BROWSER_URL" value="http://internal.website.com/" />
<const name="ADMIN_USER" value="demo" />
<const name="ADMIN_PASSWORD" value="demopasswd" />
<const name="_DEBUG" value="true" />
</php>
<testsuites>
<testsuite name="Functional Acceptance">
<file>testcases/admin/simple.php
</testsuite>
</testsuites>
</phpunit>

***
Initial output when firing up the Selenium server:

$ java -jar "${JAVA_HOME}/lib/selenium-server-standalone-2.16.1.jar" &
Jan 12, 2012 10:10:21 AM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
10:10:21.821 INFO - Java: Sun Microsystems Inc. 20.5-b03
10:10:21.821 INFO - OS: Windows XP 5.1 x86
10:10:21.837 INFO - v2.16.1, with Core v2.16.1. Built from revision 15405
10:10:22.040 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
10:10:22.040 INFO - Version Jetty/5.1.x
10:10:22.040 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
10:10:22.055 INFO - Started HttpContext[/selenium-server,/selenium-server]
10:10:22.055 INFO - Started HttpContext[/,/]
10:10:22.149 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@1d1acd3
10:10:22.149 INFO - Started HttpContext[/wd,/wd]
10:10:22.149 WARN - Failed to start: SocketListener0@0.0.0.0:4444
Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or some other service is.
at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:464)
at org.openqa.selenium.server.SeleniumServer.boot(SeleniumServer.java:282)
at org.openqa.selenium.server.SeleniumServer.main(SeleniumServer.java:245)
at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:54)

***
Here is the Selenium/Java output when BROWSER='internet explorer'.
As documented in anther ticket, the 'NullPointerException' is a known issue with Selenium, but I've left it here for completeness.

10:27:32.084 INFO - Executing: [new session: {browserName=internet explorer}] at URL: /session)
10:27:33.271 INFO - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
10:27:33.271 INFO - Retrying request
10:27:33.287 INFO - Done: /session
10:27:33.287 INFO - Executing: org.openqa.selenium.remote.server.handler.GetSessionCapabilities@19b4748 at URL: /session/1326383786810)
10:27:33.287 INFO - Done: /session/1326383786810
10:27:33.287 INFO - WebDriver remote server: Fatal, unhandled exception: /session/1326383786810: java.util.concurrent.ExecutionException: java.lang.NullPointerException
10:27:33.287 WARN - EXCEPTION
javax.servlet.ServletException: java.util.concurrent.ExecutionException: java.lang.NullPointerException
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:580)
at org.openqa.selenium.remote.server.DriverServlet.doGet(DriverServlet.java:518)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:499)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:677)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:139)
at org.openqa.selenium.remote.server.handler.WebDriverHandler.execute(WebDriverHandler.java:90)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:226)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:576)
... 16 more
Caused by: java.lang.NullPointerException
at org.openqa.selenium.remote.server.renderer.ForwardResult.render(ForwardResult.java:39)
at org.openqa.selenium.remote.server.rest.ResultConfig$1.call(ResultConfig.java:221)
at org.openqa.selenium.remote.server.rest.ResultConfig$1.call(ResultConfig.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
10:27:33.303 WARN - /wd/hub/session/1326383786810:
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:139)
at org.openqa.selenium.remote.server.handler.WebDriverHandler.execute(WebDriverHandler.java:90)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:226)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:576)
at org.openqa.selenium.remote.server.DriverServlet.doGet(DriverServlet.java:518)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:499)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:677)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: java.lang.NullPointerException
at org.openqa.selenium.remote.server.renderer.ForwardResult.render(ForwardResult.java:39)
at org.openqa.selenium.remote.server.rest.ResultConfig$1.call(ResultConfig.java:221)
at org.openqa.selenium.remote.server.rest.ResultConfig$1.call(ResultConfig.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
10:27:33.334 INFO - Executing: [get: http://internal.website.com/login.html?LogOut=1] at URL: /session/1326383786810/url)
10:27:35.865 INFO - Done: /session/1326383786810/url
10:27:35.865 INFO - Executing: [find element: By.id: login_username] at URL: /session/1326383786810/element)
10:27:35.959 INFO - Done: /session/1326383786810/element
10:27:35.975 INFO - Executing: [send keys: 0 org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement@8bb337a8, [a, d, m, i, n]] at URL: /session/1326383786810/element/0/value)
10:27:36.178 INFO - Done: /session/1326383786810/element/0/value
10:27:36.178 INFO - Executing: [find element: By.id: login_passwd] at URL: /session/1326383786810/element)
10:27:36.287 INFO - Done: /session/1326383786810/element
10:27:36.287 INFO - Executing: [send keys: 1 org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement@276b7dea, [a, d, m, i, n, p, w]] at URL: /session/1326383786810/element/1/value)
10:27:36.584 INFO - Done: /session/1326383786810/element/1/value
10:27:36.584 INFO - Executing: [find element: By.id: btn_Login] at URL: /session/1326383786810/element)
10:27:36.678 INFO - Done: /session/1326383786810/element
10:27:36.678 INFO - Executing: [click: 2 org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement@4557ba2d] at URL: /session/1326383786810/element/2/click)
10:27:37.069 INFO - Done: /session/1326383786810/element/2/click
10:27:42.069 INFO - Executing: [get current url] at URL: /session/1326383786810/url)
10:27:42.101 INFO - Done: /session/1326383786810/url
10:27:42.116 INFO - Executing: [find element: By.linkText: Logout] at URL: /session/1326383786810/element)
10:27:42.226 INFO - Done: /session/1326383786810/element
10:27:42.241 INFO - Executing: [click: 3 org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement@edbbaed] at URL: /session/1326383786810/element/3/click)
10:27:44.929 INFO - Done: /session/1326383786810/element/3/click

And the Selenium/Java output when BROWSER='firefox'.
Is it a coincidence that the NullPointerException is **NOT** thrown when using Firefox?!?

10:30:23.498 INFO - Executing: [new session: {browserName=firefox}] at URL: /session)
10:30:30.593 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.16.1', revision: '15405', time: '2012-01-05 12:23:11'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_30'
Driver info: driver.version: unknown
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:139)
at org.openqa.selenium.remote.server.DefaultSession.(DefaultSession.java:108)
at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:86)
at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:87)
at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:62)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:196)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:576)
at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:527)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:499)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:677)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.16.1', revision: '15405', time: '2012-01-05 12:23:11'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_30'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:73)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:57)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:177)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:63)
... 8 more
Caused by: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.16.1', revision: '15405', time: '2012-01-05 12:23:11'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_30'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:432)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:135)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:94)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:136)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:86)
... 13 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:149)
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:110)
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:264)
at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:219)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:298)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:403)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:382)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:122)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:412)
... 17 more
10:30:30.640 WARN - Exception: Connection reset