Selenium Chrome 驱动程序和 Travis CI 不能一起工作
Selenium Chrome driver and Travis CI don't work together
当 Travis 构建我的应用程序并进行 Selenium 测试时,它在日志中抛出以下消息:
Only local connections are allowed.
然后测试失败并出现 org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
异常
.travis.yml:
language: java
jdk:
- openjdk8
sudo: required
dist: trusty
addons: # get google-chrome-stable
chrome: stable
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3
install:
- wget -N http://chromedriver.storage.googleapis.com/2.43/chromedriver_linux64.zip -P ~/
- unzip ~/chromedriver_linux64.zip -d ~/
- rm ~/chromedriver_linux64.zip
- sudo mv -f ~/chromedriver /usr/local/share/
- sudo chmod +x /usr/local/share/chromedriver
然后
System.setProperty("webdriver.chrome.driver", "/usr/local/share/chromedriver");
webDriver = new ChromeDriver();
依赖关系
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
我觉得这与 Travis 配置有关。我的应用程序是基于网络的 (Spring),因此它必须正常工作才能进行测试。
我应该怎么做才能使使用 Chrome 驱动程序的 Selenium 测试能够在 Travis CI 上运行?
到目前为止,我见过很多解决问题的方法,但其中 none 行得通。我觉得不可能。为什么这是有问题的?
已更新。
正如@LucasTierney 所说,尝试删除 - google-chrome-stable --headless --disable-gpu --no-sandbox --remote-debugging-port=80 http://localhost &
没有做任何更改。
已更新
好吧,它终于开始使用上面相同的配置了。我不知道发生了什么以及为什么它没有更早地工作。
您使用的 chromedriver 版本太旧。 2.30
仅支持(官方)v58-60
。如果您要使用最新的稳定版(目前 70
),在安装时,您应该使用支持它的 chromedriver。那将是 2.42
或更大
当 Travis 构建我的应用程序并进行 Selenium 测试时,它在日志中抛出以下消息:
Only local connections are allowed.
然后测试失败并出现 org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
异常
.travis.yml:
language: java
jdk:
- openjdk8
sudo: required
dist: trusty
addons: # get google-chrome-stable
chrome: stable
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3
install:
- wget -N http://chromedriver.storage.googleapis.com/2.43/chromedriver_linux64.zip -P ~/
- unzip ~/chromedriver_linux64.zip -d ~/
- rm ~/chromedriver_linux64.zip
- sudo mv -f ~/chromedriver /usr/local/share/
- sudo chmod +x /usr/local/share/chromedriver
然后
System.setProperty("webdriver.chrome.driver", "/usr/local/share/chromedriver");
webDriver = new ChromeDriver();
依赖关系
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
我觉得这与 Travis 配置有关。我的应用程序是基于网络的 (Spring),因此它必须正常工作才能进行测试。 我应该怎么做才能使使用 Chrome 驱动程序的 Selenium 测试能够在 Travis CI 上运行?
到目前为止,我见过很多解决问题的方法,但其中 none 行得通。我觉得不可能。为什么这是有问题的?
已更新。
正如@LucasTierney 所说,尝试删除 - google-chrome-stable --headless --disable-gpu --no-sandbox --remote-debugging-port=80 http://localhost &
没有做任何更改。
已更新
好吧,它终于开始使用上面相同的配置了。我不知道发生了什么以及为什么它没有更早地工作。
您使用的 chromedriver 版本太旧。 2.30
仅支持(官方)v58-60
。如果您要使用最新的稳定版(目前 70
),在安装时,您应该使用支持它的 chromedriver。那将是 2.42
或更大