drupal-vm icon indicating copy to clipboard operation
drupal-vm copied to clipboard

Issue with chromedriver when running Behat tests 1404 box version 1.1.7

Open devert opened this issue 9 years ago • 64 comments

Synopsis / Proposed Solutions

  • It looks like sometime in the Chrome 56 release cycle, the version that's installed on Ubuntu 14.04 has broken the ability to use Selenium + chromedriver for Behat tests.
  • One fix is to switch to the ubuntu1604 or centos7 (or any other newer OS version base box).
  • Another fix is to switch to PhantomJS instead of chromedriver (see here if you're using Acquia BLT)
  • Another fix is to switch to Firefox + geckodriver + xvfb
  • Another fix is to use a Docker container (e.g. https://github.com/SeleniumHQ/docker-selenium) to run Selenium tests (instead of setting them to run inside the VM using the selenium installed_extra).

Basically, the bug seems to be upstream in either Google Chrome for Ubuntu 14.04, or in Chromedriver, as we've collectively spent a few dozen hours debugging everything (even trying Selenium 3.x and other exotic things), and nobody has figured out why the exact same configuration randomly stopped working in Ubuntu 14.04 sometime around the beginning of February.

Original Issue Description

Issue Type

  • Bug Report / Support Request

Your Environment

Vagrant 1.8.7
VirtualBox 5.1.8r111374
ansible 2.2.0.0
  config file =
  configured module search path = Default w/o overrides

Your OS

  • macOS (10.10.5)

Full console output

https://gist.github.com/devert/e1f393ebb143fb8f5a6327fb2d267c42

Summary

After updating from 1.1.6 to the latest box geerlingguy/ubuntu1404 (virtualbox, 1.1.7) and reprovisioning the machine, I am now receiving an error when trying to run Behat tests. I wasn't recieving errors with chromedriver before.

devert avatar Feb 02 '17 23:02 devert

Just for quicker reference:

  @javascript
  Scenario: Load a page with Javascript # features/Examples.feature:9
    Given I am on "/"                   # Drupal\DrupalExtension\Context\MinkContext::visit()
      Could not open connection: chrome not reachable
        (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.13.0-32-generic x86_64) (WARNING: The server did not provide any stacktrace in

formation)
      Command duration or timeout: 114.38 seconds
      Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
      System info: host: 'local', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.7.0_121'
      Driver info: org.openqa.selenium.chrome.ChromeDriver (Behat\Mink\Exception\DriverException)
    Then I should see the text "Log in" # Drupal\DrupalExtension\Context\MinkContext::assertTextVisible()

--- Failed scenarios:

    features/Examples.feature:9

1 scenario (1 failed)

2 steps (1 failed, 1 skipped)
1m57.65s (31.22Mb)
  [foreach] /var/www/opa/vendor/acquia/blt/phing/tasks/tests.xml:89:8: /var/www/opa/vendor/acquia/blt/phing/tasks/tests.xml:104:1: Behat exited with code 1

BUILD FAILED/var/www/opa/vendor/acquia/blt/phing/tasks/tests.xml:30:31: Execution of the target buildfile failed. Aborting.
; 2 minutes  6.89 seconds

Specifically:

Could not open connection: chrome not reachable

Can you restart your VM (vagrant reload) and try again? Sometimes chromedriver just seems to lock up, go away, or go into ghost mode...

geerlingguy avatar Feb 03 '17 17:02 geerlingguy

@geerlingguy Tried to do a vagrant reload. Slightly different error output this time, but ultimately still due to being unable to establish a connection to Chrome.

blt > tests:selenium:kill:
     [echo] Killing any selenium processes that are already running.
     [echo] Launching Selenium standalone server.
     [echo] Selenium2 logs are being written to /var/www/opa/reports/selenium2.log.
     [echo] Waiting 15 seconds for Selenium standalone server (http://127.0.0.1:4444) to become available.
Possible malformed URL: http://127.0.0.1:4444/wd/hub
Possible malformed URL: http://127.0.0.1:4444/wd/hub
Possible malformed URL: http://127.0.0.1:4444/wd/hub
Possible malformed URL: http://127.0.0.1:4444/wd/hub
blt > tests:behat:execute:
     [exec] /var/www/opa/tests/behat/features/Examples.feature
@example

Feature: Web drivers
  In order to verify that web drivers are working
  As a user
  I should be able to load the homepage
With and without Javascript

  @javascript
  Scenario: Load a page with Javascript # features/Examples.feature:9
Starting ChromeDriver 2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320) on port 25721
Only local connections are allowed.
    Given I am on "/"                   # Drupal\DrupalExtension\Context\MinkContext::visit()
      Could not open connection: unknown error: Chrome failed to start: exited abnormally
        (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.13.0-32-generic x86_64) (WARNING: The server did not provide any stacktrace information)
      Command duration or timeout: 60.18 seconds
      Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
      System info: host: 'local', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.7
.0_121'

      Driver info: org.openqa.selenium.chrome.ChromeDriver (Behat\Mink\Exception\DriverException)
    Then I should see the text "Log in"

devert avatar Feb 03 '17 17:02 devert

I haven't encountered this issue in a while, but I'll try to run some of my other site's tests in the VM soon to see what's going on. It sounds like a Chrome/chromedriver issue in 14.04, since I don't think I've seen the error in 16.04 lately.

geerlingguy avatar Feb 03 '17 18:02 geerlingguy

Linking https://github.com/geerlingguy/drupal-vm/issues/1122 - could this be related?

geerlingguy avatar Feb 06 '17 21:02 geerlingguy

I am also getting this error Could not open connection: chrome not reachable. My host machine is Mac OSX 10.12.2, and VM is Ubuntu 16.04. I have selenium and Java enabled under installed_extras. When I execute behat --profile=chrome I get this error:

    Given I am an anonymous user                                              # Drupal\DrupalExtension\Context\DrupalContext::assertAnonymousUser()
      Could not open connection: chrome not reachable
        (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 4.4.0-31-generic x86_64) (WARNING: The server did not provide any stacktrace information)
      Command duration or timeout: 114.36 seconds
      Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
      System info: host: 'drupalvm', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-31-generic', java.version: '1.8.0_121'
      Driver info: org.openqa.selenium.chrome.ChromeDriver (Behat\Mink\Exception\DriverException)

This is my behat.yml:

default:
  autoload:
    '': %paths.base%/tests/features/bootstrap
  suites:
    listjs_views:
      contexts:
        - ListjsContext
        - ListjsThemeContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\DrushContext
      paths:
        - %paths.base%/tests/features/listjs_theme.feature
  extensions:
    Behat\MinkExtension:
      goutte: ~
      selenium2: ~
      browser_name: 'phantomjs'
      base_url: "http://listjs.drupalvm.dev/"
    Drupal\DrupalExtension:
      blackbox: ~
      region_map:
        theme_list_wrapper: '.mykittens'
      api_driver: 'drupal'
      drush_driver: 'drush'
      drush:
        root: "/var/www/drupalvm/listjs"
      drupal:
        drupal_root: "/var/www/drupalvm/listjs"
chrome:
  extensions:
    Behat\MinkExtension:
      javascript_session: 'selenium2'
      browser_name: 'chrome'
      show_cmd: "open %s"
      selenium2:
        wd_host: 'http://listjs.drupalvm.dev:4444/wd/hub'
        browser: 'chrome'

I have followed the docs, Acquia Blt code, this issue https://github.com/geerlingguy/drupal-vm/issues/367, I don't know what I am missing.

Noob question: I don't have to execute selenium from the host right? The VM will run the selenium, and we have to connect the selenium in VM to the host machine's Chrome browser, and it will open up the dialog.

Let me know if we can move this discussion to a separate issue.

FYI Only the tests with @javascript tag is not working.

subhojit777 avatar Feb 09 '17 10:02 subhojit777

Updated DrupalVM to the latest release 4.2.1 -- still no :(

subhojit777 avatar Feb 09 '17 12:02 subhojit777

BTW I am getting this error on provisioning:

fatal: [drupalvm]: FAILED! => {"changed": false, "cmd": "systemctl status selenium | grep \"active (running)\"", "delta": "0:00:00.007711", "end": "2017-02-09
 13:19:54.996325", "failed": true, "rc": 1, "start": "2017-02-09 13:19:54.988614", "stderr": "", "stdout": "", "stdout_lines": [], "warnings": []}

subhojit777 avatar Feb 09 '17 13:02 subhojit777

@subhojit777 - Are you executing tests inside the VM? e.g. where are you running the behat command?

geerlingguy avatar Feb 09 '17 23:02 geerlingguy

@geerlingguy Yes, inside the VM. I am executing the behat command inside the VM.

subhojit777 avatar Feb 10 '17 05:02 subhojit777

I wonder if this is due to some other recent change in BLT... @subhojit777 and @devert - Is this with projects built with BLT, or derived from the Behat setup used by BLT?

I have one project with BLT 8.6.6 running on Drupal VM 4.2.1, and I just ran a set of tests (both with and without @javascript tests), and it all worked fine (used blt tests:behat):

12 scenarios (12 passed)
82 steps (82 passed)
1m28.78s (75.84Mb)

I have another project with BLT 8.6.11 running on Drupal VM 4.2.1, and I just ran a set of tests, and got:

Current response status code is 403, but 200 expected. (Behat\Mink\Exception\ExpectationException)
...
1 scenario (1 failed)
3 steps (1 passed, 1 failed, 1 skipped)

But that seems like it's a different issue altogether... hrm, I haven't run the behat tests for this other project for a while, so I'll have to see what's going on.

geerlingguy avatar Feb 13 '17 22:02 geerlingguy

Various google searches suggest that this is the result of a version mismatch between chromedriver and selenium-server-standalone.

grasmash avatar Feb 13 '17 22:02 grasmash

In any case, it sounds like whatever the fix, it will need to be done in https://github.com/arknoll/ansible-role-selenium/issues

geerlingguy avatar Feb 13 '17 22:02 geerlingguy

Yay, I think I finally reproduced the error!

Feature: Home page
  In order to verify that the home page is working
  As a user
  I should be able to load the homepage
  With and without Javascript

  @javascript
  Scenario: Load a page with Javascript                   # features/Home Page.feature:8
Starting ChromeDriver 2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320) on port 27769
Only local connections are allowed.
    Given I am on "/"                                     # Drupal\DrupalExtension\Context\MinkContext::visit()
      Could not open connection: unknown error: Chrome failed to start: exited abnormally
        (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.13.0-32-generic x86_64) (WARNING: The server did not provide any stacktrace information)
      Command duration or timeout: 60.28 seconds
      Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
      System info: host: 'local', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.7.0_121'
      Driver info: org.openqa.selenium.chrome.ChromeDriver (Behat\Mink\Exception\DriverException)

geerlingguy avatar Feb 13 '17 22:02 geerlingguy

Doing some debugging based on this SE answer, which suggests the problem is "a mismatch between the versions of chromedriver and selenium-server-standalone".

vagrant@local:/usr/bin$ ./chromedriver
Starting ChromeDriver 2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320) on port 9515
Only local connections are allowed.

So I'm using 2.27, which is the latest version of chromedriver according to http://chromedriver.storage.googleapis.com/LATEST_RELEASE (which the arknoll.selenium role uses to get the release version) and https://sites.google.com/a/chromium.org/chromedriver/downloads.

Next up, what Chrome version is available?

$ google-chrome --version
Google Chrome 56.0.2924.87

So that all seems well and good, and highly compatible. Next up, Selenium.

geerlingguy avatar Feb 13 '17 22:02 geerlingguy

Looks like selenium-server-standalone needs updating, maybe... http://www.seleniumhq.org/download/ says 3.0.1 is available. The role defaults to 2.53.0 currently. Going to test if this fixes it.

Test by adding selenium_version: "3.0.1" to your config.yml, then run vagrant provision.

geerlingguy avatar Feb 13 '17 22:02 geerlingguy

Still not sure what's going on... if I do the steps in the comment above, I'm still not able to get my tests to pass; it looks like Selenium is still picking up 2.53.1 somehow!

geerlingguy avatar Feb 13 '17 22:02 geerlingguy

PR against Selenium role here: https://github.com/arknoll/ansible-role-selenium/pull/30

geerlingguy avatar Feb 13 '17 22:02 geerlingguy

oooooh... apparently The selenium version is locked into BLT at 2.53.0. So might need to be updated there as well!

geerlingguy avatar Feb 13 '17 22:02 geerlingguy

So...

composer require --dev se/selenium-server-standalone:^3.0

But now I realize Ubuntu 14.04 defaults to Java 7 (OpenSDK 1.7), so I'm getting:

blt > tests:selenium:launch:
blt > tests:selenium:kill:
     [echo] Killing any selenium processes that are already running.
     [echo] Launching Selenium standalone server.
     [echo] Selenium2 logs are being written to /var/www/chn1/reports/selenium2.log.
     [echo] Waiting 15 seconds for Selenium standalone server (http://127.0.0.1:4444) to become available.
Possible malformed URL: http://127.0.0.1:4444/wd/hub
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/grid/selenium/GridLauncherV3 : Unsupported major.minor version 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
...
[phingcall] /var/www/chn1/vendor/acquia/blt/phing/tasks/tests.xml:128:8: /var/www/chn1/vendor/acquia/blt/phing/tasks/tests.xml:148:12: /var/www/chn1/vendor/acquia/blt/phing/tasks/tests.xml:151:18: Unable to start Selenium2 standalone server on http://127.0.0.1:4444/wd/hub.

BUILD FAILED/var/www/chn1/vendor/acquia/blt/phing/tasks/tests.xml:22:8: /var/www/chn1/vendor/acquia/blt/phing/tasks/tests.xml:25:26: Execution of the target buildfile failed. Aborting.
; 24.8082 seconds

Need to upgrade Java to 1.8 to get latest version of Selenium working, since requirements may have been bumped? Ugh.

geerlingguy avatar Feb 13 '17 23:02 geerlingguy

Manual steps to upgrade from OpenJDK 7 to OpenJDK 8 on Ubuntu 14.04:

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get purge -y openjdk*
sudo apt-get -y install openjdk-8-jdk

geerlingguy avatar Feb 13 '17 23:02 geerlingguy