DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Building MCP Hub for DevOps and CI/CD Pipelines
  • Engineering Habits for Building Resilient Software
  • Autonomous Pipelines: Transforming CI/CD With Full Automation
  • Rethinking the Software Supply Chain for Agents

Trending

  • Build Self-Managing Data Pipelines With an LLM Agent
  • Scaling Cloud Data Automation: A Practical Guide to Open Table Formats
  • Run Gemma 4 on Your Laptop: A Hands-On Guide to Google's Latest Open Multimodal LLM
  • From Data Movement to Local Intelligence: The Shift from Centralized to Federated AI
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. CI Testing With Iridium and PhantomJS

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.

By 
Matthew Casperson user avatar
Matthew Casperson
·
Jul. 14, 16 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
2.9K Views

Join the DZone community and get the full member experience.

Join For Free

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/">
    <information>
        <title>Iridium Web Application Tester</title>
        <vendor>Auto and General</vendor>
        <homepage href="https://autogeneral.gitbooks.io/iridiumapplicationtesting-gettingstartedguide/content/"/>
        <offline-allowed/>
    </information>
    <resources>
        <!-- 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" />
    </resources>
    <application-desc
        name="Web Application tester"
        main-class="au.com.agic.apptesting.Main"
        width="300"
        height="300">
    </application-desc>
    <update check="background"/>
    <security>
        <all-permissions/>
    </security>
</jnlp>

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:

Continuous Integration

Continuous Integration/Deployment

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

Opinions expressed by DZone contributors are their own.

Related

  • Building MCP Hub for DevOps and CI/CD Pipelines
  • Engineering Habits for Building Resilient Software
  • Autonomous Pipelines: Transforming CI/CD With Full Automation
  • Rethinking the Software Supply Chain for Agents

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook