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

Dead Link Checking With Iridium

DZone's Guide to

Dead Link Checking With Iridium

With just a few simple steps, you can check for dead links in any web page as part of an automated test.

· Web Dev Zone
Free Resource

Get deep insight into Node.js applications with real-time metrics, CPU profiling, and heap snapshots with N|Solid from NodeSource. Learn more.

Dead links are the bane of many a web developer’s existence. It is so easy for old content to rot over time as the content that it points to is deleted or moved, and there is nothing worse for your users to find a page that has text like “click here for the solution” only to have the link no longer work.

But how do you find dead links? Any given page can have hundreds of links, and these links can change at a moment's notice. You can manually click around and hope that you’ll catch any dead links, but this is tedious and error prone. Obviously you need an automated solution.

Iridium takes the pain out of finding dead links with two simple steps that you can add to any test script. To see this in action, right click and download this web start file. When you run it, you should see Chrome open up the tips and tricks section of the Iridium user guide, which has an invalid link in it.

Screen Shot 2016-07-27 at 2.11.23 PM.png

Let’s take a look at the test script that initiates this link scan. 

Feature: Open an application
 # Open up the web page
 Scenario: Launch App
   And I set the default wait time between steps to "2"
   And I open the application
   And I maximise the window
   # This step find all the <a> elements and opens all their href urls
   And I open all links in new tabs and then close the tabs

 Scenario: Verify Response Codes
   # This step reports on any http requests that resulted in HTTP errors.
   # Typically, when used in conjunction with the
   # "I open all links in new tabs and then close the tabs" step, these
   # errors means your site has dead links.
   And I verify that there were no HTTP errors

The first step is “And I open all links in new tabs and then close the tabs”. This step scans the current HTML page for any <a> elements, finds and valid urls in their href attributes, and then opens the link in a new tab before closing the tab down again.

The benefit of opening the links in the browser, as opposed to making a network request from Java directly, is that all cookies and local storage are used when opening the link, which is critical for content that requires authentication. You can write an Iridium test script that logs into a web app, initiate a link scan and be sure that any secure links will work as expected.

The second step is “And I verify that there were no HTTP errors”. Thanks to the integrated BrowserMob proxy, Iridium can track all HTTP requests and watch for any that result in an error. This second step then fails if any HTTP requests resulted in an error, which typically means that there was a dead link on the page.

Node.js application metrics sent directly to any statsd-compliant system. Get N|Solid

Topics:
http requests ,http ,http errors ,links ,errors

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 }}