Core Step verifyContent
Description
Compares the current response with an expected file. Supports content filters such as lineSeparatorFilter and replaceFilter and the nested table step.
Parameters
- referenceFile
- Required? yes
- The file to compare to
- 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.
- mode
- Required? no
- The diff mod to use for comparison. Possible values are "auto" (the default, uses "text" or "bin" depending on the type of the content to compare), "text" (performs a unified diff like diff), "bin" (compares byte per byte and displays differences in hex format), and "regexPerLine" (each line of the reference file is a regex that should match the actual content).
- readFiltered
- Required? no, default is true
- Indicates that when reading referenceFile that the content should be filtered.
- 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 verifyContent step (illustrating the use of the nested regular expression replacement filters to remove dynamically changing content which would otherwise make the comparison fail):
verifyContent example
<target name="testVerifyContentRegex">
<property name="variableNumberRegex" value="(?<= )[0-9]+(?= time)"/>
<webtest name="verifyContent: verifyContent with regex replace">
<config ... />
<steps>
<invoke url="visitCount.jsp"/>
<verifyContent referenceFile="verifyContent/expectedVisitCount.html">
<replaceFilter regex="(as at ).*(</title>)" replacement="$1[DATE REMOVED]$2"/>
<replaceFilter regex="${variableNumberRegex}"/>
<lineSeparatorFilter/>
</verifyContent>
<invoke description="load page again - content will change" url="visitCount.jsp"/>
<verifyContent referenceFile="verifyContent/expectedVisitCount.html">
<replaceFilter regex="(as at ).*(</title>)" replacement="$1[DATE REMOVED]$2"/>
<replaceFilter regex="${variableNumberRegex}"/>
<lineSeparatorFilter/>
</verifyContent>
</steps>
</webtest>
</target>
<property name="variableNumberRegex" value="(?<= )[0-9]+(?= time)"/>
<webtest name="verifyContent: verifyContent with regex replace">
<config ... />
<steps>
<invoke url="visitCount.jsp"/>
<verifyContent referenceFile="verifyContent/expectedVisitCount.html">
<replaceFilter regex="(as at ).*(</title>)" replacement="$1[DATE REMOVED]$2"/>
<replaceFilter regex="${variableNumberRegex}"/>
<lineSeparatorFilter/>
</verifyContent>
<invoke description="load page again - content will change" url="visitCount.jsp"/>
<verifyContent referenceFile="verifyContent/expectedVisitCount.html">
<replaceFilter regex="(as at ).*(</title>)" replacement="$1[DATE REMOVED]$2"/>
<replaceFilter regex="${variableNumberRegex}"/>
<lineSeparatorFilter/>
</verifyContent>
</steps>
</webtest>
</target>
If the files differ, you should see a message indicating the differences in your logs (depending on what logging levels you have set), for example:
verifyContent error
<log>
**** The last response and the expected file 'expected/expectedDummyWithChanges.html' differ.
The differences are:
[3] >> <title>Dummy</title>
[3] << <title>Dummy with Changes</title>
[7] >> Dummy page
[7] << Altered Dummy page
</log>
**** The last response and the expected file 'expected/expectedDummyWithChanges.html' differ.
The differences are:
[3] >> <title>Dummy</title>
[3] << <title>Dummy with Changes</title>
[7] >> Dummy page
[7] << Altered Dummy page
</log>
See also: the storeDigest, storeLength, lineSeparatorFilter, replaceFilter, tagStripper and contentStripper steps.