Question

I am having trouble getting chromedriver on Travis-CI working for my project knockout-secure-binding. I am trying to use WebdriverJS to automate testing with Chrome, at the least.

I noted that there seems to be some issues with chromedriver on Travis-CI, including:

The issue seems to be a variant of "chrome not reachable", and from what I can gather it requires an upstream engagement by Google to fix it.

The details of the error are available through the Travis build log.

No workaround is apparent, though one comment mentioned using --no-sandbox, but it is not clear where or how one would employ this in WebdriverJS.

Any thoughts on this would be sincerely appreciated.

—— Edit ——

As a matter of interest I am using Sauce Labs in lieu of Chromedriver.

Était-ce utile?

La solution

There's an easier way to launch Chrome on Travis CI, simply specify google-chrome in addons/apt/sources and google-chrome-package in addons/apt/packages.

Here's my sample config for a better understanding:

sudo: required
dist: trusty
addons:
  apt:
    sources:
      - google-chrome
    packages:
      - google-chrome-stable

language: node_js
node_js:
  - "6"
cache:
  directories: node_modules
branches:
  only: master

before_script:
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start
  - npm i -g npm@^3
  - sleep 3

Autres conseils

I think Travis does support chrome driver, if you add these in your travis.yml, extract the right chromedriver and unzip it to a known location, so that you can trace it later.

before_script:
  - wget http://chromedriver.storage.googleapis.com/2.10/chromedriver_linux64.zip
  - unzip chromedriver_linux64.zip -d /home/travis/virtualenv/python2.7.9/
  - export CHROME_BIN=chromium-browser
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
  - sleep 3 

Plus when you call selenium or any testing automation library, you would need to add this the code here is in Python but this can be done in Java and Ruby as well.

options = webdriver.ChromeOptions()
options.binary_location = '/usr/bin/chromium-browser'
#All the arguments added for chromium to work on selenium
options.add_argument("--no-sandbox") #This make Chromium reachable
options.add_argument("--no-default-browser-check") #Overrides default choices
options.add_argument("--no-first-run")
options.add_argument("--disable-default-apps") 
driver = webdriver.Chrome('/home/travis/virtualenv/python2.7.9   /chromedriver',chrome_options=options)

EDIT: As of October 2018, Travis CI is slowly moving away from containers (see official announcement). Therefore, one can omit sudo: false, but the given ChromeDriver setup still works.

If you want to use a container-based environment (fast boot time but no sudo), you can also do it as follows (include language and so forth accordingly):

dist: trusty
sudo: false

addons:
  chrome: stable
  apt:
    packages:
      - chromium-chromedriver

before_script:
  # include ChromeDriver in PATH
  - ln --symbolic /usr/lib/chromium-browser/chromedriver "${HOME}/bin/chromedriver"
  # start Chrome and listen on localhost
  - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &

Afterwards, as you already mentioned, add --no-sandbox to your Chrome options (taken from this gist):

var webdriver = require('selenium-webdriver');

var chromeOptions = {
    'args': ['--no-sandbox']
};

var chromeCapabilities = webdriver.Capabilities.chrome();
chromeCapabilities.set('chromeOptions', chromeOptions);

var driver = new webdriver.Builder().withCapabilities(chromeCapabilities).build();

This is due to an issue in Travis CI. However, if you need sudo anyway or have a long-running build where a container-based environment makes only limited sense, you can also set sudo: true and omit adding --no-sandbox.

Additional resources:

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top