CI-CD-pipeline

Build great software faster! CI/CD is hot and is still gaining interest. Test Automation is obviously essential within any Continuous Integration setup in order to get test feedback often and fast. Within the test automation groups here at spriteCloud we have seen a lot of different setups. We have been integrating test automation into CI tools such as Jenkins, TeamCity, Travis, TFS, Circle CI, Bamboo and Gitlab. Out of all the solutions we are a big fan of Gitlab, especially since it is making the integration of test automation a breeze.

We are also a big fan of our own test results dashboard Calliope.pro which allows testers to monitor, share, and compare test results with the rest of the development team. The benefit, aside from the collaborative aspects of Calliope, is being able to see the status of test results over time which is crucial to maintain a healthy CI/CD process. Give Calliope.pro a try for free today.


 

.gitlab.yml config file for your Selenium tests

So without further ado, let’s give you the complete code you need to run your tests within a Gitlab CI:

image: ruby:2.3

services:
- selenium/standalone-chrome:latest
variables:
  selenium_remote_url: "http://selenium__standalone-chrome:4444/wd/hub/"
cucumber:
  script:
  - cucumber -t @mytag

Wait, what? I only need a configuration file? That’s it? Yes!

There are some prerequisites of course:

  • Have the Gitlab runner executor set to ‘docker’ (for this example)
  • use your selenium_remote_url environment variable within your test scripts. The selenium chrome service we started is accessible through: http://selenium__standalone-chrome:4444/wd/hub/

Let’s make the CI setup a bit more efficient though by adding some caching:

image: ruby:2.3

services:
- selenium/standalone-chrome:latest

variables:
  selenium_remote_url: "http://selenium__standalone-chrome:4444/wd/hub/"

cache:
  paths:
  - "./cache/ruby"

before_script:
- bundle install --path ./cache

cucumber:
  script:
  - bundle exec cucumber -t @mytag

Configure your Selenium remote URL

The last thing to keep in mind is to include the selenium_remote_url in the test scripts. Here at spriteCloud we are using our open-source gem lapis-lazuli in order to quickly setup Ruby, Cucumber and Selenium test automation suites. This is how you integrate the URL within such a test suite:

require 'lapis_lazuli'
require 'lapis_lazuli/cucumber'
 
World(LapisLazuli)
 
LapisLazuli.Start do
  browser :remote, {
    :url => ENV['selenium_remote_url'],
    :caps => {
      "browser" => "Chrome"
    }
  }
end

But of course you can use selenium-webdriver directly as well if you want:

require 'selenium-webdriver'
driver = Selenium::WebDriver.for :remote,
                                 :url => ENV['selenium_remote_url'],
                                 :desired_capabilities => :chrome

Want to try this out yourself in Gitlab? We have setup an example Gitlab project where you can see it in action! Gitlab Cucumber Selenium CI test setup. Enjoy!

If you want to get started with test automation using ruby and cucumber you can read our introduction post about Lapis Lazuli and be sure to also read “Getting started with test automation: Cucumber with Lapis Lazuli”.

 

Suggested Posts

top