Overview

Azure Pipelines is a mature and powerful tool meant for enterprises. It enables you to create workflows that automatically build, test, publish, release, and deploy code, allowing you to give complete traceability of the software development lifecycle.

In this article we will learn how to quickly build up test automation using the NightwatchJS testing library and integrate it into the Azure DevOps pipelines flow.

Prerequisites

  • Working project to test that has been pushed to Github
  • Tests run properly in your local system

Setup Guide

In this example we will be learning how to run Nightwatch tests using Azure Pipelines using the nightwatch-examples Github repo

Step 1: Create a New Pipeline

To create a new pipeline in Azure DevOps you have to navigate to Azure DevOps from your Azure DevOps home page, then hover on Pipelines and Click on Pipelines

And then click on the new pipeline as shown in the below image

Choose your repository management system where your project resides.

And then select your repository from the list

Step 3 : Select NodeJS plugin

You need to click on Node.js in order to configure its plugin. This will provide an environment to run the tests.

Step 4 : Configure azure-pipelines.yml file

Now you have to review and write the steps inside the azure-pipelines.yml file to run your tests.

# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install
  displayName: 'npm install'

- script: |
    sudo apt-get install xvfb

- script: xvfb-run --auto-servernum npm test -- --env chrome
  displayName: 'Run tests'

Step 3: Push azure-pipelines.yml file and Run the tests

After editing and reviewing the .yml file you should click on the save and run button

yaml-file-setup

Then click save and run button to commit .yml file after filling out the form accordingly.

Once you push your changes and click on save and run button, the pipeline will start and your tests will run automatically.

Note: After saving and running, you may encounter an error stating that no hosted parallelism has been purchased or granted. Please fill out the form to request a free parallelism grant.

Related articles