Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Running WebDriver Tests in Travis CI With Iridium

DZone's Guide to

Running WebDriver Tests in Travis CI With Iridium

In this post, we take a look at the YML code you'll need to know to help you run Iridium's Travis CI while you code, to make sure your web app is amazing.

· Web Dev Zone ·
Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

One of the goals of the Iridium project is to allow tests to be run by CI servers as part of the automated build process. Iridium itself is built by the Travis CI service, and as part of that build, a number of tests are run against a multitude of browsers to ensure that the steps exposed by Iridium work as expected across all popular browsers with each release.

The same implementation that runs the Iridium tests as part of a Travis CI build can also be used to run tests against any public website, and in this article, I’ll show you how to build a .travis.yml file that executes Iridium tests as part of a build.

Let’s take a look at the sample .travis.yml file that will run the Iridium tests for us:

sudo: required
dist: trusty
language: java
jdk:
- oraclejdk8
addons:
  firefox: "56.0"
before_install:
- export CHROME_BIN=/usr/bin/google-chrome
- sudo apt-get update
- sudo apt-get install -y libappindicator1 fonts-liberation
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- sudo dpkg -i google-chrome*.deb
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- wget https://s3.amazonaws.com/iridium-release/IridiumApplicationTesting.jar
script: >
  java
  -DtestSource=https://mcasperson.github.io/iridium/features/firsttest.feature
  -DtestDestination=Chrome
  -jar IridiumApplicationTesting.jar

This configuration does a few important things:

  • It installs the Chrome and Firefox browsers.
  • It starts xvfb, which provides us with the ability to run desktop browsers in a headless environment.
  • It downloads the Iridium JAR file.
  • It then executes an Iridium test.

Installing the Browsers

The Travis CI config file installs both Chrome and Firefox. Firefox is quite easy to configure, as it is provided as an addon by Travis CI itself.

addons:
  firefox: "56.0"

Installing Chrome involves a little more work, as we have to download and install the Ubuntu package for ourselves. We also have to install a few dependencies to ensure that Chrome will work as expected.

before_install:
- export CHROME_BIN=/usr/bin/google-chrome
- sudo apt-get update
- sudo apt-get install -y libappindicator1 fonts-liberation
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- sudo dpkg -i google-chrome*.deb

Start xvfb

In Linux, xvfb provides a way for applications to run on a virtual monitor. Like most CI systems, Travis CI is headless, which means there is no monitor attached to the virtual machine that is performing the build. By running xvfb, we can run the web browser of our choice as if there was a monitor attached.

- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

Download Iridium

In order to run Iridium, it first needs to be downloaded. Doing so is a simple call to wget to download the Iridium JAR file.

- wget https://s3.amazonaws.com/iridium-release/IridiumApplicationTesting.jar

Executing Iridium

All the previous configuration has provided us with is an environment where we can run Iridium tests. The actual execution of the test is done as part of a Travis CI script.

When an Iridium test is run from the JAR file, the return code will be zero on success, and a non-zero value for failure. Travis CI, in turn, will pass or fail the build based on the return code.

script: >
  java
  -DtestSource=https://mcasperson.github.io/iridium/features/firsttest.feature
  -DtestDestination=Chrome
  -jar IridiumApplicationTesting.jar

Summary

You can see a working example of this build in Travis CI based on code in this GitHub repo.

Image title

If you are interested in writing end-to-end tests like the one shown above, check out the Iridium documentation, and take a look at the course on Udemy. Iridium itself is a free and open source project on GitHub.

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

Topics:
iridium ,webdriver ,web dev ,travis ci

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}