Webtest WebTest GitHub Home

Extension Step verifyLinkedContent

Description

Verify all selected links on a page for existence and, optionally, mime-type.

This step provides a mechanism to verify the availability of the resources linked from a page. The step tries to fetch all the resources referenced on the page that the xpath attribute selects. With this step, the availability of any kind of resources can be ensured, such as images, css stylesheets, linked javascripts, ...

Further, the step can verify that the webserver provides the resources with the correct mime-type.

Parameters

xpath
Required? yes
The links to checks
accept
Required? no, default is Accepts anything.
Type and subtype that the answer must have, in the classical mime-type notation.
description
Required? no
The description of this test step.

Details

The attribute accept follows a subset of the description of the http-accept header in RFC 2616, simplifying it where possible:
The attribute value takes one or more media-range, separated by a semi-colon.
A media-range is a pair of mime type and subtype separated by a slash. The special subtype * accepts all of subtypes of the named type, and the special media-range */* accepts any mime-type.

The most simple usage of <verifyLinkedContent> is to make sure that the server returns all resources. Note that the simple xpath selects the resources to verify.

Verify the existence of all stylesheet
<verifyLinkedContent
  xpath="/html/head/link[@rel='stylesheet']/@href"
  />

In a middle level, <verifyLinkedContent> can also enforce the mime-type returned by the server.

Verify the existence and the mime-type of all stylesheet
<verifyLinkedContent
  xpath="/html/head/link[@rel='stylesheet']/@href"
  accept="text/css"
  />

In an example of advanced usage, the xpath selects all images in the page and makes sure that the images are either gif or png.

Verify the existence and the mime-type of all images
<verifyLinkedContent
  xpath="//img/@src | //input[@type='image']/@src"
  accept="image/gif;image/png"
  />