angular - 由于 Chrome 与 Chromedriver 版本不匹配,Angular e2e 测试在 GitHub 操作中失败
问题描述
我的开源 Angular 项目在 GitHub 上对lint
、build
、test
和e2e
所有内容进行了成功的操作。但是,不久之后,我看到了这个:
[00:20:01] I/launcher - Running 1 instances of WebDriver
[00:20:01] I/direct - Using ChromeDriver directly...
[00:20:07] E/launcher - session not created: This version of ChromeDriver only supports Chrome version 85
(Driver info: chromedriver=85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}),platform=Linux 5.3.0-1034-azure x86_64)
[00:20:07] E/launcher - SessionNotCreatedError: session not created: This version of ChromeDriver only supports Chrome version 85
(Driver info: chromedriver=85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}),platform=Linux 5.3.0-1034-azure x86_64)
at Object.checkLegacyResponse (/home/runner/work/sample-angular-oauth2-oidc-with-auth-guards/sample-angular-oauth2-oidc-with-auth-guards/node_modules/selenium-webdriver/lib/error.js:546:15)
at parseHttpResponse (/home/runner/work/sample-angular-oauth2-oidc-with-auth-guards/sample-angular-oauth2-oidc-with-auth-guards/node_modules/selenium-webdriver/lib/http.js:509:13)
at /home/runner/work/sample-angular-oauth2-oidc-with-auth-guards/sample-angular-oauth2-oidc-with-auth-guards/node_modules/selenium-webdriver/lib/http.js:441:30
at processTicksAndRejections (internal/process/task_queues.js:97:5)
在某种程度上这是有道理的,因为 GitHub 图像包含 Chrome 84,并且似乎正在下载 chromedriver 的85版本。但这也没有意义,因为webdriver-manager
我认为应该管理正确版本的 chromedriver 的 Angular 使用?为什么会安装错误的版本?还是我有事情倒退?
通过分叉存储库并设置相同的 GitHub 操作,我的情况应该可以重现,这里是工作流的相关位:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Based on: https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
run: npm ci
- name: Linting
run: npm run lint
- name: Build
run: npm run build -- --prod
- name: Tests
run: npm run e2e -- --configuration=ci
angular.json
目标也很简单:
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "sample-auth-guards:serve"
},
"configurations": {
"production": {
"devServerTarget": "sample-auth-guards:serve:production"
},
"ci": {
"devServerTarget": "sample-auth-guards:serve:production",
"protractorConfig": "e2e/protractor-ci.conf.js"
}
}
}
我尝试更新所有 NPM 开发依赖项,但这没有帮助。
我还尝试webdriverUpdate=false
在工作流程中进行设置(假设由于来自 GitHub 的图像声称具有 Chrome 84和相关的 chromedriver 版本),但这会导致:
[16:43:43] I/launcher - Running 1 instances of WebDriver
[16:43:44] I/direct - Using ChromeDriver directly...
[16:43:44] E/direct - Error code: 135
[16:43:44] E/direct - Error message: Could not find update-config.json. Run 'webdriver-manager update' to download binaries.
[16:43:44] E/direct - Error: Could not find update-config.json. Run 'webdriver-manager update' to download binaries.
许多“解决方案”(例如这个相关的 SO 线程)建议将 chromedriver 更新为特定的chrome 版本。但这不是我想要的,因为每当 GitHub 更新他们的图像时,我都会再次遇到同样的问题。
同样重要的是要注意:我希望有一个特定于 CI 的解决方案。开发人员(即我)通常会在他们的机器上安装最新的 Chrome,因此运行npm run e2e
仍然应该为我的机器提供正确的 chromedriver。
底线:如何让 Angular 项目下载正确版本的 chromedriver?也就是:那个属于机器上安装的Chrome的版本?
解决方案
问题在于量角器而不是 github 操作。好像这个问题经常发生。基本上量角器在 chrome 推出稳定版本之前将 chrome 驱动程序更新到最新版本,因此差异导致此设置中断。正如您已经提到的,目前量角器正在下载版本 85,但 chrome 版本是 84。
来源: https ://github.com/angular/protractor/issues/5460
分叉您的代码并找到两个解决方案
解决方案 1:将 google chrome 更新到最新的内部工作流程
- run: sudo apt-get install google-chrome-stable
这将安装当前最新的稳定版本的谷歌浏览器,即 85。似乎已经发布,所以这可以让你正常运行一切。为了将来参考,这只是因为 chrome 最终发布了 85 作为稳定版本,如果没有,我们将遇到相同的问题,我们将不得不进行与解决方案 2 中相同的版本提取设置。
管道显示它有效: https ://github.com/meroware/sample-angular-oauth2-oidc-with-auth-guards/actions/runs/230800136
如果您想在不必担心版本奇偶校验的情况下进行实际修复,那么您可以执行以下操作。
解决方案 2:在 docker 内部运行以确保我们的构建是干净的
管道显示它有效: https ://github.com/meroware/sample-angular-oauth2-oidc-with-auth-guards/runs/1046824367
这是更改的快速摘要
container:
image: ubuntu:trusty
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '14.x'
# Based on: https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Setup chrome driver environment
run: |
apt-get update # Remove if running outside container
apt-get clean # Remove if running outside container
apt-get install -y wget # Remove if running outside container
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - # Remove if running outside container
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list # Remove if running outside container
apt-get -y update # Remove if running outside container
apt-get install -y google-chrome-stable # If not running in docker then run this line with sudo
VERSION=`google-chrome --version | egrep -o '[0-9]+.[0-9]+' | head -1` # Get chrome version that we just installed
npm i webdriver-manager@latest -D # Install webdriver manager locally
npm i chromedriver --chromedriver_version=$VERSION -D # Install chrome driver to the version that we got from google chrome installation above
推荐阅读
- java - 连接到 mysql 数据库的 java 销售点系统
- java - 如何使用 Selenium 和 Java 通过 sendKeys 方法传递双引号字符串
- javascript - 对于一个简单的 RESTful API 应用程序,如何使用 Node Js 和 Express 显示带有 GET 请求的对象数组
- vbscript - 如何使用 Classic ASP 和 Strict OAuth 2.0 获取 GoToWebinar 的访问令牌
- ios - 如何解决 Xcode kivy-ios 中的“动态模块未定义模块导出功能”错误?
- javascript - 单击时滚动更多数据
- python - 仅返回通过的测试数和失败的测试数
- javascript - 使用 Console.log 时数组不打印
- cassandra - 使用不同版本和操作系统引导 cassandra
- django - 使用 Nginx 和 gunicorn 在 django 中提供静态文件