0% Complete

Introduction

What is CI/CD?

CI/CD stands for Continuous Integration, Continuous Delivery (or Continuous Deployment), which represents a culture and process around constantly integrating new code. Conventional software development and delivery methods are rapidly becoming obsolete as deployment frequency increases. 

Before DevOps, most companies would deploy/ship software in monthly, quarterly, bi-annual, or even annual releases (also known as the Agile days). In the DevOps era, weekly, daily, and even multiple daily deployments are the norm. CI/CD provides developers a solution to the problems associated with constantly integrating new code.

Before taking this lesson 🖊

Make sure you are comfortable with the following lessons:

Learning Objectives 🧠

By the end of this you will:

  • Understand the importance of automation testing inside CI/CD pipeline
  • Know about different CI/CD integration options available in mabl.
  • How you can set them up and use in the CI/CD pipeline

Why is this important?❓

  • Automated testing enables continuous delivery, which ensures software quality and security and increases the profitability of code in production.
  • CI/CD pipelines enable a much shorter time to market for new product features, creating happier customers and lowering strain on development.
  • The great increase in overall speed of delivery enabled by CI/CD pipelines improves an organization’s competitive edge.
  • Automation frees team members to focus on what they do best, yielding the best end products.

How do I use it? 💻

Test on deployment 

Integrating mabl tests in your deployment process helps you test the end-to-end user experience in multiple browsers as soon as code is deployed to a hosting environment within your CI/CD pipeline.

All mabl tests can run across environments by design, so you can easily run the same tests across multiple environments — from ephemeral preview environments for testing pull/merge requests to persistent staging environments, and even production!

You can integrate mabl with your CI/CD pipeline to run tests on deployment using one of the following options, in order of ease of use:

  • Existing CI/CD integration: GitHub Actions, Bamboo, Jenkins, and more.
  • mabl CLI: Integrate with any CI tools that can install and run Node.js packages.
  • mabl APIs: Integrate with any CI tools where you cannot use the mabl CLI or need more control.

Existing CI/CD integration

Running tests on deployment mabl provides a variety of ways to integrate your automated end-to-end tests with your existing CI/CD pipeline including native plug-ins and a helpful curl-command builder.

Note: For all of the following integrations, your plans must be configured to use a deployment event as a trigger.

 

Jenkins integration plug-in

You can use the mabl Jenkins integration plugin to automatically trigger specific environment or application plans to run as a build stage with your existing Jenkins setup. Learn more.

 

Bamboo integration plug-in

mabl's Bamboo integration plugin is used to automatically trigger specific environment or application plans to run as a build stage in your current Bamboo pipeline. Learn more.

 

Microsoft Azure DevOps integration (VSTS)

With mabl you can integrate your mabl tests directly into your build and release pipelines inside Azure DevOps. Within Azure DevOps, use the mabl pipeline task to automatically trigger specific environment or application plans to run as a build task. Learn more.

 

GitHub integration

mabl integrates with GitHub through the mabl GitHub app and mabl Action. Doing so takes full advantage of GitHub Actions 2.0, automatic GitHub Issue creation, and filtering by GitHub data within mabl. Learn more.

 

GitLab integration

mabl provides GitLab pipeline images that - in addition to triggering test runs - allow you to see test result summaries as well as to review test results in merge requests. Learn more.

 

Octopus Deploy integration

You can use the Run mabl tests step template in the Octopus Deploy process to automatically trigger plans to run based on application, environment, or plan label settings. Learn more.

 

CircleCI integration

The trigger-tests Orb can be added to CircleCI pipelines to automatically trigger plans to run based on a wide variety of options. Learn more.

 

Other integrations

You can easily integrate mabl with most other CI/CD solutions through our built-in curl command builder. Learn more about integrating this way.

 

mabl CLI  

If you would like to integrate mabl CLI inside your CI/CD pipeline, you can either run them directly through mabl CLI commands or you can use the mabl-cli node package as a dependency in your project and define mabl tests with a testing framework such as Jest.

Note: 

  • Please ensure that you have reviewed the mabl Automation Testing CLI lesson that covers the basics of installing the CLI and how you can use it.
  • Have access to mabl runner. The mabl runner is available to select customers under the mabl Early Access Program.
Running tests from the command line
  • With the mabl CLI, you can run tests inside your CI/CD environment using the mabl runner.
  • Here are some examples of what a CI configuration might look like to run mabl tests with the CLI.

# install the CLI

npm install @mablhq/mabl-cli

# authenticate with Command Line Interface API key

mabl auth activate-key KEY_VALUE

# install wait-on to wait for the app to start

npm install wait-on

# start the web app AND wait until it loads

npm start & wait-on http://localhost:3000

# run a single mabl test

mabl tests run --id TEST_ID --environment-id ENVIRONMENT_ID --credentials CREDS_ID --headless

# run a set of tests by a label

mabl tests run --labels COOL_FEATURE_ONE --environment-id ENV_ID --headless

Running tests from code
  • You can use the mabl-cli node package to run end-to-end tests locally in your preferred testing framework. The mabl-cli package exposes the MablTestRunner as an importable object that can be used to initialize and run mabl tests from within JavaScript testing frameworks such as Jest.
  • By defining your mabl tests in code you can create an npm command in your package.json file that will run the tests desired. To run the tests you can either bundle them alongside your other tests or you can create a specific script for them in your package.json file.
  1. Install the mabl-cli as a dev dependency of your project.
    npm install --save-dev @mablhq/mabl-cli
  2. Authenticate using the below command and the CLI key
    mabl auth activate-key KEY_VALUE
  3. Adding the following script to your package.json file will use Jest to call our mabl tests file.

    “scripts”: {

        ...

        "mabl:test": "jest mablTests.test.ts",

        ….

    }

     

    import {createMablTestRunner, TestRunConfig} from '@mablhq/mabl-cli';

    jest.setTimeout(180000);

    const CICD_BRANCH_NAME = process.env.CI_BRANCH;

    const runConfig: TestRunConfig = {

      credentialsId: 'CREDS_ID',

      environmentId: 'ENVIRONMENT_ID',

      workspaceId: 'WORKSPACE_ID',

      url: 'http://localhost:3000',

      branchName: CICD_BRANCH_NAME ?? 'master',

      headless: true, // toggle to watch tests locally

    };

    describe('Super important mabl tests', () => {

      it('This needs to always work', async () => {

        const mablTestRunner = await createMablTestRunner({

          testId: 'TEST_ID',

          ...runConfig,

        });

        const result = await mablTestRunner.run();

        expect(result.success).toEqual(true);

      });

    });

  4. Now you can run the below command inside your CI environment to kick off the mabl tests. This is also a handy command for developers to run the mabl tests on their local using the mabl CLI.

    npm run mabl:test

Note: If you would like, you can refer to the JavaScript testing frameworks page for more info.

Recap 🗒

Reflect

What did we learn?

  • Importance of automation testing inside CI/CD pipeline
  • Different options of integrating mabl in CI/CD pipeline
  • How to trigger tests inside CI/CD pipeline