Bitbucket Pipeline 尝试 运行 Nightwatch E2E 测试失败并出现 Chromedriver 错误

Bitbucket Pipeline fails attempting to run Nightwatch E2E tests with Chromedriver Error

我正在尝试 运行 在 bitbucket 管道中部署时使用 nightwatch 进行端到端测试。我在 windows 本地机器上安装了 nightwatch 和 chromedriver,一切正常。

当我在管道中 运行 npm nightwatch 时收到此错误

An error occurred while trying to start ChromeDriver: cannot resolve path: "/opt/atlassian/pipelines/agent/build/node_modules/chromedriver/lib/chromedriver/chromedriver". Please check that the "webdriver.server_path" config property is set correctly.

这是它指定路径的文件结构

文件结构

node_modules/
    chromedriver/
        lib/
            chromdriver/
                chromerdriver.exe
                chromedriver_win32.zip

很明显 node_modules/chromedriver/lib/chromedriver/chromedriver 不存在。容器是 Linux 所以它不知道如何执行 chromedriver.exe 文件。

那么如何将 bitbucket 管道连接到 运行 chromedriver.exe?或者如何让 chromedriver 进入它正在寻找的路径。我敢肯定,之前有人不得不 运行 参与其中。在这方面苦苦挣扎了一段时间,正在寻求帮助。谢谢。

bitbucket-pipelines.yml 文件

image: rastasheep/alpine-node-chromium
pipelines:
  custom:
    develop:
      - step:
          name: Serve and Test
          caches:
            - node
          script:
            - apt-get update && apt-get install -yq libnss3
            - if [ ! -d "node_modules/nightwatch" ]; then npm install; fi
            - npm start
            - npm run nightwatch

nightwatch.conf.js

const chrome = require('chromedriver')

module.exports = {
  'src_folders': [
    './nightwatch/tests/elements'
  ],
  'output_folder': './nightwatch/reports',
  'globals_path': './nightwatch/utils/globals/globals.js',
  'webdriver': {
    'start_process': true,
    'server_path': chrome.path,
    'log_path': './nightwatch/reports',
    'cli_args': [
      '--verbose'
    ],
    'port': 9515
  },
  'test_settings': {
    'default': {
      'launch_url': 'http://localhost:3100',
      'desiredCapabilities': {
        'browserName': 'chrome',
        'javascriptEnabled': true,
        'chromeOptions': {
          'args': [
            'no-sandbox',
            'headless'
          ]
        }
      },
      'screenshots': {
        'enabled': true,
        'on_failure': true,
        'on_error': true,
        'path': 'nightwatch/screenshots'
      }
    }
  }
}

我能够通过删除 rastasheep/alpine-node-chromium 添加节点映像并在步骤中自己安装 chrome 来解决。

image: node:10.15.0
pipelines:
  default:
    - step:
    name: NewHomePageNav
    script:
      # First we are going to install dependencies that chrome and chromedriver will need
      - apt-get update && apt-get install -yq libnss3 unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4
      # Install chrome browser as it does not exist with the node image
      - curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
      - echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
      - apt-get -y update
      - apt-get -y install google-chrome-stable
      - npm install
      # Start and run your server. Using the & will allow bitbucket to move onto testing
      - npm start &
      - npm test