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

Modifying Network Requests With Iridium

DZone's Guide to

Modifying Network Requests With Iridium

With its built in proxy, the Iridium testing tool allows your to modify network requests as part of your integration tests

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

If you are just getting started with Iridium, please read the article An Introduction to Iridium, an Open Source Selenium and Cucumber Testing Tool.

A common requirement when writing browser tests is the ability to modify network requests. There are a number of reasons why you may want to do this including:

  • Simulating failures of backend systems
  • Blocking access to analytics to prevent your stats from being influenced by test runs
  • Blocking access to static resources like images to speed up tests
  • Preventing timeouts for resources that a CI system can’t access

Iridium embeds the BrowserMob proxy and exposes steps that can be used to support the above situations. To demonstrate this, let’s look at how you would modify the test of the DZone website in order to speed it up via the removal of image loading.

To run this example, right click, download and run this Web Start file. If you have not already done so, ensure that you have trusted the location where the Iridium JAR file is downloaded from using the instructions in the installation chapter of the getting started guide.

The only change to the test scripts shown in previous examples is the addition of a step that intercepts requests matching a certain regular expression (anything with the string “thumbnail” in our case) and immediately returns a 500 response code.

# Open up the web page
Scenario: Launch App
  And I set the default wait time between steps to "2"
  # Speed up tests by blocking thumbnails
  And I block access to the URL regex ".*?thumbnail.*" with response "500"
  And I open the application
  And I maximise the window

There is no additional configuration required for this step to work, as BrowserMob is enabled and configured by default.

Running the test confirms that the page being loaded indeed has no thumbnail images present. This significantly speeds up the execution of the test, as it removes a large percentage of the bandwidth required to load a page.

Screen Shot 2016-07-17 at 10.13.19 AM.png

For more information on the Iridium testing tool, check out the documentation and the GitHub project.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
website ,application ,web ,browser ,dzone ,jar ,selenium ,cucumber ,testing ,tool

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

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}