Chromedriver on Travis-CI

前端 未结 3 1743
孤街浪徒
孤街浪徒 2021-02-01 18:53

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 leas

相关标签:
3条回答
  • 2021-02-01 19:13

    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)
    
    0 讨论(0)
  • 2021-02-01 19:23

    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:

    • Google Chrome addon on Travis CI
    • GUI and headless browser testing on Travis CI
    • How to make travis execute Angular tests on Chrome ("Please set env variable CHROME_BIN")
    0 讨论(0)
  • 2021-02-01 19:25

    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
    
    0 讨论(0)
提交回复
热议问题