4

I am trying to get end to end testing working in our bitbucket pipeline environment using nightwatch.js, we have hit a problem. How can we keep the dev server running and run the tests referencing the dev server.

This isn't a problem on our local machine since I can run two windows. Though I haven't found a way to emulate this in bitbucket pipelines. Any ideas, articles or pointers for how to achieve this?

bitbucket-pipelines.yml

image: atlassian/default-image:2
pipelines:
  default:
    - step:
    name: NewHomePageNav
    script:
      - npm install
      - npm test

nightwatch.config.js

module.exports = {
"src_folders": [
    "test/Testinprogress",
],
"page_objects_path": "./dist/",
"webdriver": {
    "start_process": true,
    "server_path": "node_modules/.bin/chromedriver",
    "cli_args": [
        "--verbose"
    ],
    "port": 9515
},

"test_workers": {
    "enabled": true,
    "workers": "auto"
}, 

"output_folder": "reports", // reports (test outcome) output by nightwatch

"test_settings": {
    "launch_url" : "http://localhost:8080"
    "default": {
        "skip_testcases_on_fail": false,
        "globals": {
            "waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
        },
        "desiredCapabilities": {
            "browserName": "chrome",
            "acceptSslCerts": true,
            "acceptInsecureCerts": true,
            "javascriptEnabled": true,
            "chromeOptions": {
                "args": [
                    "--no-sandbox",
                    "--headless",
                ]
            },
            "loggingPrefs": {
                "driver": "INFO",
                "server": "OFF",
                "browser": "INFO"
            }
        }
    }
}
}
dtsn
  • 1,077
  • 1
  • 10
  • 17

2 Answers2

2

I recently ran into this issue and spent hours troubleshooting, one fix led to more errors and it was a tiresome task. Anyway I hope this can help someone. I was able to solve with the following bitbucket-pipelines.yml

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
bilcker
  • 1,120
  • 1
  • 15
  • 43
0

You can either run the dev server as a service in Bitbucket Pipelines. See https://confluence.atlassian.com/bitbucket/use-services-and-databases-in-bitbucket-pipelines-874786688.html for details.

Or if you're producing the server as part of your build, you can package it as a Docker image and run it as a daemon using the docker run -d ... command. See https://confluence.atlassian.com/bitbucket/run-docker-commands-in-bitbucket-pipelines-879254331.html for details.