Reputation: 3
I'm trying to create a a custom scenario in Behat / Mink using the javascript capabilities of Selenium but I've hit a peculiar snag. I've stripped everything back to the bare bones to lay the problem out as simply as possible but in summary when calling visit() in Selenium, some websites run fine but other (including my own) return the error "Error communicating with the remote browser. It may have died." in behat which terminates the scenario.
In detail:
My behat.yml file looks like this:
default:
paths:
features: features
bootstrap: %behat.paths.features%/bootstrap
extensions:
Behat\MinkExtension\Extension:
base_url: http://www.foo.bar
goutte: ~
selenium2:
browser: 'firefox'
In my FeatureContext.php file I have the following custom function:
public function iAmLoggedIn()
{
$session = $this->getSession();
$session->visit("http://www.foo.bar");
{
Now when I run the scenario in Behat that uses the custom function I get the following error:
PHP Fatal error: Uncaught exception 'WebDriver\Exception\UnknownError' with message 'Error communicating with the remote browser. It may have died.
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
Driver info: driver.version: EventFiringWebDriver' in /var/www/behat/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:157
Stack trace:
#0 /var/www/behat/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php(140): WebDriver\Exception::factory(13, 'Error communica...')
#1 /var/www/behat/vendor/instaclick/php-webdriver/lib/WebDriver/Session.php(151): WebDriver\AbstractWebDriver->curl('DELETE', '')
#2 /var/www/behat/vendor/behat/mink-selenium2-driver/src/Behat/Mink/Driver/Selenium2Driver.php(292): WebDriver\Session->close()
#3 /var/www/behat/vendor/behat/mink/src/Behat/Mink/Session.php(70): Behat\Mink\Driver\Selenium2Dri in /var/www/behat/vendor/behat/mink-selenium2-driver/src/Behat/Mink/Driver/Selenium2Driver.php on line 294
But here's the oddity: thinking that this may have been an issue with my website (www.foo.bar) I tried a different website by editing the line on the function:
$session->visit("http://www.bbc.co.uk");
This time no error and the scenario continues as normal. Good old BBC. To make sure I also tried Goole:
$session->visit("http://www.google.com");
But this time I get exactly the same error: 'Error communicating with the remote browser. It may have died.'. Weird. So I try a number of other websites, some work fine, others return this error. There doesn't seem to be any obvious similarity between those sites that kill Selenium, and those that don't. So what is Selenium saying?
Output from a site that returns the 'It may have died' error:
11:41:41.428 INFO - Executing: [new session: Capabilities [{platform=ANY, browserVersion=8, browserName=firefox, deviceType=tablet, selenium-version=2.31.0, name=Behat test, browser=firefox, deviceOrientation=portrait, max-duration=300, version=8}]])
11:41:41.430 INFO - Creating a new session for Capabilities [{platform=ANY, browserVersion=8, browserName=firefox, deviceType=tablet, selenium-version=2.31.0, name=Behat test, browser=firefox, deviceOrientation=portrait, max-duration=300, version=8}]
11:41:44.024 INFO - Done: [new session: Capabilities [{platform=ANY, browserVersion=8, browserName=firefox, deviceType=tablet, selenium-version=2.31.0, name=Behat test, browser=firefox, deviceOrientation=portrait, max-duration=300, version=8}]]
11:41:44.031 INFO - Executing: [get: http://www.foo.bar//])
11:41:50.478 INFO - Executing: [delete all cookies])
11:41:50.494 INFO - Executing: [delete session: cee7cfa5-bc53-4804-a9a4-f6b52b0f48df])
Output from a site that does not return the error:
11:19:19.930 INFO - Executing: [new session: Capabilities [{platform=ANY, browserVersion=8, browserName=firefox, deviceType=tablet, selenium-version=2.31.0, name=Behat test, browser=firefox, deviceOrientation=portrait, max-duration=300, version=8}]])
11:19:19.936 INFO - Creating a new session for Capabilities [{platform=ANY, browserVersion=8, browserName=firefox, deviceType=tablet, selenium-version=2.31.0, name=Behat test, browser=firefox, deviceOrientation=portrait, max-duration=300, version=8}]
11:19:24.607 INFO - Done: [new session: Capabilities [{platform=ANY, browserVersion=8, browserName=firefox, deviceType=tablet, selenium-version=2.31.0, name=Behat test, browser=firefox, deviceOrientation=portrait, max-duration=300, version=8}]]
11:19:24.614 INFO - Executing: [get: http://www.bbc.co.uk/])
11:19:43.454 INFO - Done: [get: http://www.bbc.co.uk/]
11:19:43.463 INFO - Executing: [delete all cookies])
11:19:46.263 INFO - Done: [delete all cookies]
11:19:49.935 INFO - Executing: [delete all cookies])
11:19:49.955 INFO - Done: [delete all cookies]
11:19:50.389 INFO - Executing: [delete session: a092aa77-ad26-4f6f-8fc1-f290b688d7fa])
11:19:50.488 INFO - Done: [delete session: a092aa77-ad26-4f6f-8fc1-f290b688d7fa]
No clue there apart from the fact that Selenium completes the 'get' of bbc.co.uk but not of foo.bar. So what about the access logs for foo.bar? They seem normal:
10.179.?.? - - [06/Jan/2015:10:52:57 +0000] "GET / HTTP/1.1" 401 486 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
10.179.?.? - tester [06/Jan/2015:10:52:57 +0000] "GET / HTTP/1.1" 200 33141 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
10.179.?.? - tester [06/Jan/2015:10:53:00 +0000] "GET /css/page_specific_css/index.css HTTP/1.1" 200 10234 "http://www.foo.bar/" "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
10.179..?.? - tester [06/Jan/2015:10:53:00 +0000] "GET /library/jquery-tools.min.js HTTP/1.1" 200 5920 "http://www.foo.bar/" "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
10.179.?.? being the IP of the CI server so it's communicating with the server fine and retrieving all the assets. So I'm not sure if this is a Selenium issue or a Behat / Mink issue but I'm at a loss. There doesn't seem to be any logical reason why some sites work and other's don't. Any help would be greatly appreciated.
Upvotes: 0
Views: 708
Reputation: 221
This issue occurs for me when my selenium lib and browser version are not compatible. In this case it is best to update both your browser and selenium lib to its latest version.
Upvotes: 0