-
Notifications
You must be signed in to change notification settings - Fork 0
Validating result counts
Using the previous test as an example we'll now have to create a test case that is capable of validating that then number of results returned is equal to the number of requests that was specified in the search request. This is quite easy since we can apply an XPath expression to count the number of results in each request. So the previous test will serve as the basis for this one and we'll validate the number of results between 1 and 42 and the term search will be a keyword that originates many results such as 'github'. Here is the resulting test:
<?xml version="1.0" encoding="UTF-8"?>
<script xmlns="http://dtf.org/v1" name="validate_result_count">
<info>
<author>
<name>Rodney Gomes</name>
<email>rlgomes@yahoo-inc.com</email>
</author>
<description>
This test validates that the result count returned is the same as the
one specified with the query parameter 'result' for values between 1 and
42.
</description>
</info>
<local>
<createstorage id="INPUT" path="${dtf.xml.path}/input"/>
<createstorage id="OUTPUT" path="${dtf.xml.path}/output"/>
<loadproperties uri="storage://INPUT/websearch.properties"/>
</local>
<property name="uri" value="${websearch.uri}?appid=dtftest"/>
<for property="i" range="1..42">
<log>checking ${i} result count</log>
<http_get uri="${uri}&query=github&results=${i}"/>
<property name="count"
value="${http.get.body:xpath:count(//ns:Result),[ns=>urn:yahoo:srch]}"
overwrite="true"/>
<assert><eq op1="${count}" op2="${i}"/></assert>
</for>
</script> The above test only needs to take advantage of the XPath function count() to count the elements in the result set returned. Other than that the test is very similar to the previous "simple term search" test and shows how easy it is to validate certain things about your data by using the built-in features that DTF has.
The test previously created can be found here