Canoo Webtest WebTest Canoo

Extension Step storeDigest

Description

Stores a digest value for the response (or part of the response) into a property. This is useful when you don't care what the value within a response is but you want to ensure that the generated content hasn't changed. If any single character in the response changes, so will the digest. Supports content filters such as lineSeparatorFilter and replaceFilter to allow you to filter out changes that you don't care about and the table locator step if you are interested in content within a table.

Parameters

property
Required? yes
The target property name.
description
Required? no
The description of this test step.
htmlId
Required? no
The id of an HTML element. If present, processing will be limited to this element. Will be ignored if a nested table step is used.
propertyType
Required? no, default is the "defaultPropertyType" as specified in the "config" element is used.
The target property type. Either "ant" or "dynamic".
type
Required? no, default is SHA-1
The type of message digest algorithm to use, e.g. 'MD5' or 'SHA-1'.
xpath
Required? no
An XPath expression identifying an HTML element. If present, processing will be limited to this element. Will be ignored if htmlId is set or if a nested table step is used.

Nested Parameters

step
Required? yes
A webtest step.
table
Required? no
To locate a specific cell in a specific table on the page.

Details

The following example illustrates how to use the storeDigest step (illustrating the use of the nested line separator content filter which ensures that differences in line separator which may occur in different environments don't influence the digest value):

storeDigest example
<target name="testStoreDigestSimple">
    <property name="variableNumberRegexvalue="(?&lt;= )[0-9]+(?= time)"/>
    <property name="visitCountDigestvalue="c1 e2 29 ad d4 6b 2a 96 2f 18 18 f4 71 e6 bb 88 73 9a c7 62"/>
    <webtest name="storeDigest: Show how to use storeDigest step">
        <config ... />
        <steps>
            <invoke url="dummy.html"/>
            <storeDigest property="dummyDigestSHA1">
                <lineSeparatorFilter/>
            </storeDigest>
            <verifyProperty name="dummyDigestSHA1text="4e 7e c7 59 21 9 15 44 52 f3 45 70 76 b9 a1 93 e7 b3 78 f2"/>
            <storeDigest property="dummyDigestMD5type="MD5">
                <lineSeparatorFilter/>
            </storeDigest>
            <verifyProperty name="dummyDigestMD5text="27 e2 37 6c ff d6 ac 13 65 8d 80 d9 94 0 f7 21"/>
        </steps>
    </webtest>
</target>

Note that both SHA-1 (the default) and MD5 digest are shown. These are the most commonly used digests with Java (because they are built in) but about 20 different kinds of digests are available in various cryptography packages for Java and may be available to you if someone has downloaded an appropriate class library and configured your systems to use it. You may also have heard of the related terms checksum and/or hash (sometimes loosely means a digest, sometimes meaning a weaker algorithm which can be used to detect some forms of content change) or digital signature (a digest value can be part of this).

At the moment the best way to calculate the digest value (so that you can write the test) is to use a dummy value (e.g. 'xxxxx') and then run the test. Then when it fails it will tell you what it was expecting. Simply copy that value into your test. Eventually we may store digest values in a file and populate the file for you the first time the test is run or we may have a tool (e.g. Mozilla plug-in or one of the other recorder tools) to pre-calculate digest values for you.

See also: the verifyContent, storeLength, lineSeparatorFilter, replaceFilter, tagStripper and contentStripper steps.

news

Latest build: development
Posted: 19-Jul-2016 17:36

WebTest 3.0 released, featuring upgrades to Java 5, Groovy 1.6, and HtmlUnit 2.4.
The release includes support for maven integration, IDE-integration like for unit tests, capturing of background JavaScript errors, new steps for mouseOver and mouseOut events, better parallel execution of tests and - as usual - lots of handling improvements.
Posted: 5 March 2009

WebTest @ JavaOne
Dierk König presented "Functional testing of web applications: scaling with Java" on Wed May 7, 13:30 at JavaOne 2008 in the Tools and Scripting Languages track.
Posted: 8 May 2008

New WebTest screencast available:
Data Driven WebTest
Posted: 13 November 2007

First WebTest screencast available:
Creating a first Webtest Project

Extend WebTest with Groovy! Groovy in Action is available in every good bookstore.
Groovy in Action
Posted: 29 January 2007