I have an xml file that I want to use as a template for recording my test results. I want eggPlant to fill in the blanks(add/remove/change nodes) as the tests and test cases are completed.
At the end of this process I want to reassemble the xml document using the modified (and some of the unmodified nodes) and combine the results into another xml file to be transformed using XSLT.
This problem I am having manifests itself when I try to traverse the xml template document, using eggPlant, as follows:
put file (global templateFilePath) as a tree into xmlDoc
put node “/document/layout” of xmlDoc into layoutNode
up to this point the process works well. When I try:
put node “/layout/table[@name=‘Windows’]” of layoutNode into windowsNode
I get nothing. Interestingly enough, when I try:
put node “/document/layout/table[@name=‘Windows’]” of xmlDoc into windowsNode
I get the results I expect.
Does anyone have any ideas, hints, or suggestions that could help solve my problem or point out what I am doing wrong?
Kinda surprised nobody responded to this one. I ran into the same issue, here’s the fix:
Change:
put file (global templateFilePath) as a tree into xmlDoc
put node “/document/layout” of xmlDoc into layoutNode
To:
put file (global templateFilePath) as a tree into xmlDoc
put node “/document/layout” of xmlDoc as tree into layoutNode
The missing “as tree” appears to be required to move the xml tree over to the new object. If this is the issue you can verify it quickly by logging layoutNode. If it has () around the whole value it’s not being treated as a tree.
Without seeing more of your script, and the XML source you’re working with, it’s hard to tell exactly what the problem is here or how to resolve it. Using “as tree” on a node really shouldn’t make any difference as it should be a tree already so I’m not sure what Erik is seeing there.
There are a couple of useful things to be aware of, though. First, there are currently some problems with the ‘node’ (xpath) expression functionality. Some node expressions throw an exception in the Mac version of eggPlant and don’t work at all. Other node expressions work differently on Windows than they do on the Mac. These problems are being addressed and we expect to have a fix ready in version 12.1 (in about a month or so).
In the meantime there is a good workaround for these issues and incompatibilities. For now, we strongly recommend using the DocumentTreeFromXML() function rather than ‘as tree’. This will create a full XML document internally (rather than a non-rooted node) which will provide these benefits:
all node expressions are supported (no exceptions thrown on Mac)
node expressions will work the same on all platforms (Mac, Windows, and Linux)
node expressions will work the same in future versions of eggPlant
The last point above is important because the future fix will (by necessity) change the behavior of at least some node expressions on at least one platform. We plan to make this change in behavior opt-in (only if you ask for it) at first, but it will likely become the default in a later release. Using DocumentTreeFromXML will save you from having to worry about these changes.
Getting back to your specific case, here is a simple script I wrote to test your scenario. Note that I’m using DocumentTreeFromXML here, and I believe everything is working as it should. Please feel free to expand on the very minimal xmlSource here if you have additional questions about specific node expressions or anything else about how this works.
set xmlSource to {{
<document>
<layout>
<table>
</table>
<table>
</table>
</layout>
</document>
}}
put DocumentTreeFromXML(xmlSource) into xmlDoc
put node "/document/layout" of xmlDoc into layoutNode
put layoutNode
put layoutNode is a tree
put "--------"
put node "/document/layout/table[@name='Windows']" of xmlDoc into tableNode
put tableNode
put "------------"
// update tableNode and put the modified node back into the document
insert "<testCase>FirstTest</testCase>" into tableNode
put tableNode
set node "/document/layout/table[@name='Windows']" of xmlDoc to tableNode
put "=========="
put xmlDoc
The solution I came up with was to create the two nodes I needed for my logging with eggPlant. I save each of the nodes to separate files at the end of the test.
The end of the test script creates a batch file from eggPlant which runs a python script which will in turn create a results xml file by adding the saved nodes to the template. If the results file exists then the python script parses that to add the new results to the file.
The resulting xml file is then transformed with xsl in a browser.
One of the problems I have run into is that if the test script fails to complete for any reason, the test results don’t get posted.
First, I’d like to follow up on my earlier post to mention that eggPlant v12.1 has shipped today, with improvements to node expressions. To make your script run consistently across platforms and into the future, we recommend that you set the StandardNodeExpressions to true. If you do this, you can go back to using “as tree” to convert your XML source to a tree. See the v12.1 Release Notes for more details.
Next:
To deal with this situation you might want to look at using a post-run script in your suite (on the Settings tab). A post-run script will be executed after every script run, whether that run succeeded or failed, so you may be able to do your XML result processing work there.