Since the early 1990s XML files have been widely used for data transfer between application modules and even between different systems. An XML file may contain, for instance, the results of a billing record for a cellular phone customer. In such a case, it may be of high value to be able to have preset expected results and be able to compare actual XML files with these.
Proceed with the following steps:
<?xml version="1.0"?> <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="bk102"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description> </book> <book id="bk103"> <author>Lucas, George</author> <title>The Force Awakens</title> <genre>Sci-Fi</genre> <price>11.78</price> <publish_date>2015-12-18</publish_date> <description> Set approximately 30 years after the defeat of the Empire and the demise of Darth Vader, the plot follows a trio of young leads, along with characters from the previous installments.</description> </book> <book id="bk104"> <author>Wright, Jonathon</author> <title>Experiences of Test Automation</title> <genre>Computer</genre> <price>25.95</price> <publish_date>2012-01-09</publish_date> <description>Software test automation has moved beyond a luxury to become a necessity. Applications and systems have grown ever larger and more complex, and manual testing simply cannot keep up.</description> </book> <book id="bk105"> <author>Crispin, Lisa</author> <title>Agile Testing: A Practical Guide</title> <genre>Computer</genre> <price>25.95</price> <publish_date>2008-12-30</publish_date> <description> Testing is a key component of agile development. The widespread adoption of agile methods has brought the need for effective testing.</description> </book> <book id="bk106"> <author>Graham, Dorothy</author> <title>Software Test Automation</title> <genre>Computer</genre> <price>14.95</price> <publish_date>1999-05-28</publish_date> <description> This book describes how to build and implement an automated testing regime for software development. It presents a detailed account of the principles of automated testing.</description> </book> <book id="bk107"> <author>Hendrickson, Elisabeth</author> <title>Explore It!</title> <genre>Computer</genre> <price>14.95</price> <publish_date>2013-03-03</publish_date> <description> Uncover surprises, risks, and potentially serious bugs with exploratory testing. Rather than designing all tests in advance, explorers design and execute small, rapid experiments.</description> </book> <book id="bk108"> <author>Adzic, Gojko</author> <title>Specification by Example</title> <genre>Computer</genre> <price>24.95</price> <publish_date>2011-05-06</publish_date> <description> Specification by Example is an emerging practice for creating software based on realistic examples, bridging the communication gap between business stakeholders and the dev teams building the software.</description> </book> <book id="bk109"> <author>Whittaker, James</author> <title>How Google Tests Software</title> <genre>Computer</genre> <price>16.95</price> <publish_date>2012-03-23</publish_date> <description> Do you need to get it right, too? Then, learn from Google.</description> </book> <book id="bk110"> <author>O'Brien, Tim</author> <title>Microsoft .NET: The Programming Bible</title> <genre>Computer</genre> <price>36.95</price> <publish_date>2000-12-09</publish_date> <description>Microsoft's .NET initiative is explored in detail in this deep programmer reference.</description> </book> <book id="bk111"> <author>O'Brien, Tim</author> <title>MSXML3: A Comprehensive Guide</title> <genre>Computer</genre> <price>36.95</price> <publish_date>2000-12-01</publish_date> <description>The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more.</description> </book> <book id="bk112"> <author>Galos, Mike</author> <title>Visual Studio 7: A Comprehensive Guide</title> <genre>Computer</genre> <price>49.95</price> <publish_date>2001-04-16</publish_date> <description>Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment.</description> </book> </catalog>
Now, for each node we will be able to define whether we wish to:
When traversing the hierarchy we can view the specific values of nodes, as shown:
We can also click on the Activate Schema Validation button to validate the integrity of the XML document with regards to a schema (XSD), either referenced in the document or an external one:
In case our, XML is expected to be based on such a schema, this would give us a comprehensive checkpoint, which not only verifies the contents of the XML document but also its structure.
Action
:XMLFile("catalog.xml").Check CheckPoint("catalog.xml")
In addition, our Object Repository now includes XMLFile
as TO and a CheckPoint
object of XMLFile
. The XMLFile
TO carries a single description property, that is, its filename, which stores its path. Of course, as with other TOs, it is possible to parameterize this property. In a similar fashion, as with the DbTable
checkpoint, the CheckPoint
object of XMLFile
will have the properties as we defined in the XML Checkpoint Properties dialog previously.
When invoking the Check
method of XMLFile
with the XML CheckPoint
object, the target file is opened and checked against the data stored as expected results. Running the command yields a results report, as follows (here we have deliberately changed one value in the XML file to make the checkpoint fail):
If prompted to allow ActiveX Add-In, then approve in order to see Captured Data. Clicking on the View XML Checkpoint Results button in that pane will open a window titled XML Checkpoint Results:
We see that for each node there is a checkpoint summary giving details about the checks that were performed. As the tooltip shows, we can browse through our results very efficiently to drill-down and examine the failures. Clicking on the icon to find the next error will lead us to the node in which UFT found a discrepancy between the expected and actual data: