Over a million developers have joined DZone.

CI Testing With Iridium and PhantomJS

DZone's Guide to

CI Testing With Iridium and PhantomJS

Using PhantomJS is an easy way to add testing to your automated build process, and with Iridium it is trivial to swap between browsers in your various environments.

· DevOps Zone
Free Resource

The Nexus Suite is uniquely architected for a DevOps native world and creates value early in the development pipeline, provides precise contextual controls at every phase, and accelerates DevOps innovation with automation you can trust. Read how in this ebook.

In a previous article, I showed you how to write a simple test in Iridium that navigated the DZone website in Firefox. When the test was run, you could see Firefox start and begin clicking through the site.

Testing in desktop browsers is valuable when you need to simulate the end-user experience, and is an excellent way to ensure that your site works across multiple browsers. But, you’ll also want to be able to run tests in a headless environment like Jenkins or Bamboo on a regular basis to ensure that changes don’t break the expected behaviour of your application.

PhantomJS provides a headless browser that runs in CI environments, and Iridium supports PhantomJS out of the box. To see this in action, right click and download the Web Start file, and then run it. Note that you will want to enable the Web Start console so you can see what is going on. Refer to the Installation chapter of the Iridium Getting Started Guide for more details.

The complete jnlp file is shown below:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="https://s3-ap-southeast-2.amazonaws.com/ag-iridium/">
        <title>Iridium Web Application Tester</title>
        <vendor>Auto and General</vendor>
        <homepage href="https://autogeneral.gitbooks.io/iridiumapplicationtesting-gettingstartedguide/content/"/>
        <!-- Application Resources -->
        <j2se version="1.8+" href="http://java.sun.com/products/autodl/j2se"/>
            <property name="jnlp.packEnabled" value="true"/>
            <property name="javaws.configuration" value=""/>
            <property name="javaws.dataset" value=""/>
            <property name="javaws.appURLOverride" value="https://dzone.com"/>
            <property name="javaws.featureGroupName" value=""/>
            <property name="javaws.testSource" value="https://raw.githubusercontent.com/AutoGeneral/IridiumApplicationTesting/master/examples/17.simplesteps/test.feature"/>
            <property name="javaws.importBaseUrl" value=""/>
            <property name="javaws.testDestination" value="PHANTOMJS"/>
            <property name="javaws.webdriver.chrome.driver" value=""/>
            <property name="javaws.webdriver.opera.driver" value=""/>
            <property name="javaws.phantomjs.binary.path" value=""/>
            <property name="javaws.leaveWindowsOpen" value="false"/>
            <property name="javaws.openReportFile" value="true"/>
            <property name="javaws.saveReportsInHomeDir" value="true"/>
            <property name="javaws.webdriver.ie.driver" value=""/>
            <property name="javaws.enableVideoCapture" value="false"/>
            <property name="javaws.numberOfThreads" value="1"/>
            <property name="javaws.numberURLs" value="1"/>
            <property name="javaws.numberDataSets" value="1"/>
            <property name="javaws.enableScenarioScreenshots" value="true"/>
            <property name="javaws.tagsOverride" value=""/>
            <property name="javaws.phantomJSLoggingLevel" value="NONE"/>
            <property name="javaws.startInternalProxy" value=""/>
            <property name="jnlp.versionEnabled" value="true"/>
            <jar href="webapptesting-signed.jar" main="true" version="0.0.4" />
        name="Web Application tester"
    <update check="background"/>

Once launched, the test will run through from the command line without the need for a desktop browser.

The only change that was required was defining the testDestination system property:

<property name="javaws.testDestination" value="PHANTOMJS"/>

There are three other system properties that you should be aware of when running tests in PhantomJS.

The first is the phantomJSLoggingLevel property, which configures the logging level of the PhantomJS browser. PhantomJS was quite verbose with its default settings, which ended up cluttering the console output, so I usually leave this as NONE unless I need to debug an issue with a test script.

The second is the enableScenarioScreenshots property, which when set to true will automatically grab a screenshot of the webpage at the end of each scenario. Since you can’t see the test interacting with the webpage with a headless browser like PhantomJS, these screenshots are invaluable for debugging tests.

The final property is phantomjs.binary.path, which can be set to the PhantomJS executable downloaded from the PhantomJS website. This is optional, as Iridium includes a version of PhantomJS that is automatically configured for you, but you can override the included version through this system property.

Using PhantomJS is an easy way to add testing to your automated build process, and with Iridium it is trivial to swap between browsers in your various environments.

Related Refcard:

The DevOps Zone is brought to you in partnership with Sonatype Nexus.  See how the Nexus platform infuses precise open source component intelligence into the DevOps pipeline early, everywhere, and at scale. Read how in this ebook

web start ,end user experience ,headless ,phantomjs ,build ,browser ,testing ,continuous integration

Published at DZone with permission of Matthew Casperson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}