Xpectador 1.0

Xpectador is a command-line tool for verifying the content of XML-documents, any XML-documents. It's very easy to use, and requires almost zero learning.

Suppose we expect our XML document to have the following "profile":

<root>
<element_a attr_1="X">value_a</element_a>
<element_b>
<element_c>value_c</element_c>
</element_b>
</root>

What we would do is: save that expectation as an XML file, and executes Xpectador the following way:

xpectador my_expectation.xml document_tobe_verified.xml

That is all. In case xpectador finds that your document doesn't meet the expectation, it will exit with code -1, and print out some messages, such as: "Expected element could not be found: <element_b>...</element_b>". That will help you identify the issue in your document more quickly.

Note that I used the word "profile" instead of "content" because Xpectador performs more than simple text-comparisons.

It allows you to express the following expectations:

  • Positive expectation: I want to see this particular element that contains these attributes, etc.
  • Negative expectation: I don't want to see this particular element.
  • Don't care: I don't care whether the document contains this element or not.

The neat thing about Xpectador: you don't need to learn any new syntax (format). You state your expectations -- as XML document -- using the same format as the document that you want to verify.

You've seen the an example of "positive expectation" above. To state a "negative expectation", in the expectation file you only need to insert a special attribute in the element that you don't want to see. Example:

<root>
<element_b>
<element_c Expected="N">value_c</element_c>
</element_b>
</root>

That's a way of saying "I don't want to see element_c whose value is value_c, inside element_b". In case that expectation is not met, you will get the following message from the xpectador: "Non-expected element was found: <element_c>...</element_c>".

"Don't care"? Well, it's the easiest: just omit the element from your expectation document.

You can specify a different name for that special attribute. You do that by specifying the third in the execution of xpectador. Example:

xpectador my_expectation.xml document_tobe_verified.xml esperado

We'll, I guess that's all for the intro. There actually isn't much to talk about how-to-use this application due to its simplicity. However I know you will ask "can I trust the outcome?". That was also my concern, and I do have the list of test-cases for this application. I'll try to find a time sometime next week to be able to write a couple of things about it.

In the meantime, feel free to use it. Grab it from here (box.net). Just unzip the file, you'll find one EXE file in there (xpectador.exe). You will reap the real benefit of this kind of tool if you integrate it to your chain of automated-tests.

The source: http://www.box.net/shared/u55s51p9hf

Feel free to drop me an email if you have any question regarding this tool or in case you find anything that looks like a bug. My email: raka.angga@gmail.com.

Credits: this tool is written in Python, with a 3rd-party library for XML-processing (lxml), and compiled to EXE using py2exe..., on Vista :D