Chromedriver on Travis-CI

前端 未结 3 1741
孤街浪徒
孤街浪徒 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: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")

提交回复
热议问题