Skip to main content

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 CI/CD variables.

const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

async function runSampleTest () {
  let driver;
  try {
    let options = new chrome.Options();
    options.set('platformName', 'WIN11');
    options.set('browserVersion', 'latest');
    options.set('tb:options', {
      'key': process.env.TESTINGBOT_KEY,
      'secret': process.env.TESTINGBOT_SECRET,
      'name': (process.env.CI_JOB_ID ? ("GitLab Build " + process.env.CI_JOB_ID) : "Simple Test")
    });

    driver = new webdriver.Builder()
      .usingServer("https://hub.testingbot.com/wd/hub")
      .withCapabilities(options)
      .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.

Was this page helpful?
Last updated