由于Chrome与Chromedriver版本不匹配,Angular e2e测试在GitHub操作中失败

a5g8bdjr  于 2023-09-28  发布在  Go
关注(0)|答案(2)|浏览(128)

我的open source Angular project成功地在GitHub上对lintbuildteste2e进行了操作。然而,不久之后,我看到了这个:

[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。但它也没有意义,因为Angular使用webdriver-manager,我认为应该管理正确版本的chromedriver?为什么安装了错误的版本?还是说我把事情搞反了?
我的情况应该是可复制的,通过分叉存储库并设置相同的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 devdependencies,但是没有用。
我还尝试在工作流中设置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.

许多“解决方案”(例如this related SO thread)建议将chromedriver更新为特定的chrome版本。但这不是我想要的,因为每当GitHub更新他们的图像时,我都会再次遇到同样的问题。
同样重要的是要注意:我希望有一个专门针对线人的解决方案开发人员(即我)通常会在他们的机器上安装最新的Chrome,所以运行npm run e2e应该仍然会为我的机器提供正确的chromedriver。

**底线:如何让Angular项目下载正确版本的chromedriver?**也就是说:属于机器上安装的Chrome版本的那个?

c8ib6hqw

c8ib6hqw1#

问题在于量角器,而不是Github操作。这个问题似乎发生了很多。基本上量角器更新Chrome驱动程序,以最新的 chrome 出来之前,与稳定的版本,使差距导致这种设置打破。正如你已经提到的,目前量角器正在下载版本85,但Chrome版本是84.

来源:https://github.com/angular/protractor/issues/5460

分叉了你的代码,找到了两个解决方案

**解决方案1:**更新google Chrome到最新的inside工作流程

- run: sudo apt-get install google-chrome-stable

这将安装当前最新的稳定版本的谷歌Chrome器,这是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
工作流编码URL:https://github.com/meroware/sample-angular-oauth2-oidc-with-auth-guards/blob/master/.github/workflows/ci-workflow.yml

下面是一个简短的变化片段

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
nzkunb0c

nzkunb0c2#

我把另一个答案重新混合到我的最终解决方案中。我想单独分享它,因为对于其他人来说,它可能也像这几行一样简单:

- name: Update Chrome # See https://stackoverflow.com/q/63651059/419956
  run: |
    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
    sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
    sudo apt-get update
    sudo apt-get --only-upgrade install google-chrome-stable

不知何故,我使用的GitHub Actions的图像也需要Google的apt源(即使它已经预装了Google Chrome),之后更新+安装技巧开始正常工作。

2023年8月关于使用量角器的Angular的说明:

量角器已达到“寿命终止”,它显示。底层的webdriver-manager尝试下载Chrome 114的驱动程序(需要更新以在新位置找到116的驱动程序,但与Protractor一起下线),而GitHub Actions现在默认随Chrome 116一起提供。有点像是原始问题的反向问题。请参见this example issue on my own repository

相关问题