简体   繁体   English

Travis-CI上的Chromedriver

[英]Chromedriver on Travis-CI

I am having trouble getting chromedriver on Travis-CI working for my project knockout-secure-binding . 我无法在Travis-CI上获得chromedriver,因为我的项目是敲门安全绑定 I am trying to use WebdriverJS to automate testing with Chrome, at the least. 我试图使用WebdriverJS来自动化Chrome测试,至少。

I noted that there seems to be some issues with chromedriver on Travis-CI, including: 我注意到 Travis-CI上的chromedriver似乎存在一些问题,包括:

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. 这个问题似乎是“chrome无法访问”的变体,而且从我可以收集的内容来看,它需要Google的上游参与来修复它。

The details of the error are available through the Travis build log . 通过Travis构建日志可以获得错误的详细信息。

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. 没有明显的解决方法,尽管有一条评论提到了使用--no-sandbox ,但目前尚不清楚在WebdriverJS中何时或如何使用它。

Any thoughts on this would be sincerely appreciated. 对此的任何想法都将深表感谢。

—— Edit —— - 编辑 -

As a matter of interest I am using Sauce Labs in lieu of Chromedriver. 我感兴趣的是我使用Sauce Labs代替Chromedriver。

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. 有一种更简单的方法可以在Travis CI上启动Chrome,只需在addons / apt / sources中指定google-chrome,在addons / apt / packages中指定google-chrome-package。

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

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. 我认为Travis确实支持chrome驱动程序,如果你在travis.yml中添加它们,提取正确的chromedriver并将其解压缩到一个已知的位置,以便你以后可以追踪它。

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. 另外,当您调用selenium或任何测试自动化库时,您需要添加此代码,这里的代码是Python但这也可以在JavaRuby完成。

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 ). 编辑:截至2018年10月,Travis CI正逐渐远离集装箱(见官方公告 )。 Therefore, one can omit sudo: false , but the given ChromeDriver setup still works. 因此,可以省略sudo: false ,但是给定的ChromeDriver设置仍然有效。

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): 如果您想使用基于容器的环境(快速启动但没有sudo ),您也可以按照以下方式执行此操作(包括language等):

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 ): 之后,正如您已经提到的,将--no-sandbox添加到您的Chrome选项中(取自此要点 ):

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. 这是由于特拉维斯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 . 但是,如果你仍然需要sudo或者有一个长期运行的构建,其中基于容器的环境只有有限的意义,你也可以设置sudo: true并省略添加--no-sandbox

Additional resources: 其他资源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM