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
  script:
    - node sample_test.js

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

npm -i selenium-webdriver --save
var webdriver = require('selenium-webdriver'), driver;
 
driver = new webdriver.Builder().
  withCapabilities({
    'browserName': 'firefox',
    'platform': 'VISTA',
    '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://" + testingbotKey + ":" + testingbotSecret +
              "@hub.testingbot.com/wd/hub").
  build();
 
driver.get('https://www.google.com');
 
driver.getTitle().then(function (title) {
    console.log("title is: " + title);
});
 
driver.quit();

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

Looking for More Help?

Have questions or need more information?
You can reach us via the following channels: