How do I check a specific value is present in the input XML document
This example demonstrates how to search for the occurrence of the value in an XML document and returns the result within the context of an automated test in execution.
In this example, you store the XML in a variable and using the "xmlSearchValueOccurrence" command, you verify the occurrence of age value "15" in the XML by specifying the value and the valid path.
Solution:
# | Command | Target | Value |
---|---|---|---|
store the xml | |||
1 | store | <?xml version="1.0" encoding="UTF-8"?> <insuranceData> <insurance category="valid"> <age>45</age> <income>55000</income> <zipcode>90001</zipcode> <result>You are eligible for a subsidy.</result> </insurance> <insurance category="valid"> <age>64</age> <income>25000</income> <zipcode>14301</zipcode> <result>You are eligible for a subsidy.</result> </insurance> <insurance category="invalid"> <age>15</age> <income>25000</income> <zipcode>08857</zipcode> <result>Combinations of inputs provided out of scope for the calculator.</result> </insurance> </insuranceData> |
XML |
To check for a specific value in XML | |||
1 | xmlSearchValueOccurrence | ${XML} || 15,/insuranceData//insurance[3]//age | OccurencesCount |
Tips, Tricks, Gotchas & Best Practices:
- The XML should be valid and encoded in "UTF-8" format.
- You can use the xmlAssertPathExistscommand to check if the path is valid or invalid.
- The nodeValue should not be greater than existing nodes.