Features

GitLab CI Automated Testing

GitLab CI/CD is a part of GitLab and provides a Continuous Integration system to run automated tests.

Below are the steps to run your Selenium tests via GitLab CI, once the tests are up and running you can even display a TestingBot Status badge showcasing your Selenium tests status.

1. Get GitLab CI up and running

Download GitLab CI and set up GitLab CI to your requirements.

2. Create a simple Selenium test

Add a simple Selenium test to your GitLab project, modify the .gitlab-ci.yml file in your repository to indicate you want to run a Selenium test.

Example .gitlab-ci.yml file:

image: node:latest
stages:
  - Test TestingBot

Selenium Test:
  stage: Test TestingBot
  before_script:
    - npm install
    - npm install selenium-webdriver
  script:
    - node sample_test.js

Add your TESTINGBOT_KEY and TESTINGBOT_SECRET environment variables to GitLab's Variables Page.

var webdriver = require('selenium-webdriver');

async function runSampleTest () {
  let driver;
  try {
    driver = new webdriver.Builder().
      withCapabilities({
        'browserName': 'chrome',
        'platform': 'WIN10',
        'version': 'latest',
        'client_key': process.env.TESTINGBOT_KEY,
        'client_secret': process.env.TESTINGBOT_SECRET,
        'name': (process.env.CI_JOB_ID ? ("GitLab Build " + process.env.CI_JOB_ID) : "Simple Test")
      }).
      usingServer("https://" + process.env.TESTINGBOT_KEY + ":" + process.env.TESTINGBOT_SECRET +
                  "@hub.testingbot.com/wd/hub").
      build();

    await driver.get('https://www.google.com');

    var title = await driver.getTitle();
    console.log("title is: " + title);
  } catch (e) {
    console.log(e);
  } finally {
    if (driver) {
      await driver.quit();
    }
  }
}
runSampleTest();

Now you're ready to run this first sample test with GitLab CI.