这是一个MCVE:
/.travis.yml
:
language: python
python:
- "3.5"
dist: trusty
addons:
chrome: stable
before_install:
- pip install selenium
- wget https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip -d test/driver/
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3
script:
- cd test
- python3 ./test_main.py
/test/test_main.py
:
from selenium.webdriver import *
b=Chrome('driver/chromedriver')
b.get('http://example.com')
b.quit()
构建将失败,引发一个例外,说铬崩溃了:
$ python3 ./test_main.py
Traceback (most recent call last):
File "./test_main.py", line 2, in <module>
b=Chrome('driver/chromedriver')
File "/home/travis/virtualenv/python3.5.4/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/home/travis/virtualenv/python3.5.4/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/home/travis/virtualenv/python3.5.4/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/travis/virtualenv/python3.5.4/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/home/travis/virtualenv/python3.5.4/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.14.12-041412-generic x86_64)
上面的代码几天前就已经运行了,所以我想知道它是否是travis构建环境中的一个bug。
答案 0 :(得分:5)
https://github.com/travis-ci/travis-ci/issues/8836
根据支持团队的说法:
我们在基于容器的基础架构上安装的Chrome版本似乎发生了变化。我们仍然在研究促成因素,我们很快就会提出解决方案。
与此同时,解决方法是通过在.travis.yml文件中添加以下内容,将构建路由到支持sudo的基础架构:
sudo: required addons: chrome: stable