Search code examples
selenium-chromedrivernightwatch.jsbitbucket-pipelines

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


I am trying to run my E2E tests using nightwatch while deploying in a bitbucket pipeline. I have nightwatch installed, chromedriver installed on my windows machine locally and everything works.

When I run npm nightwatch in the pipeline I receive this error

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.

This is the file structure of the path it specifies

File structure

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

So clearly node_modules/chromedriver/lib/chromedriver/chromedriver does not exist. The container is Linux so it does not know how to execute the chromedriver.exe file.

So how can I get bitbucket pipeline to run chromedriver.exe? Or how do I get chromedriver into the path it's looking for. I'm positive someone has had to run into this before. Been struggling on this for a while and am looking for some help. Thanks.

bitbucket-pipelines.yml file

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'
      }
    }
  }
}

Solution

  • I was able to solve by removing rastasheep/alpine-node-chromium adding a node image and installing chrome myself in the step.

    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