Service Virtualization

  • 1.  Automate XML comparing

    Posted Mar 16, 2017 04:19 AM

    Hello,

     

    I'm looking for a way to automate comparing the content of 2 XML files

    and then report any differences found to a text file.

     

    Currently I'm using 2 "Parse text as response" steps to load both xml's and save it as a property.
    In the last step I added the "Graphical XML Side-by-Side Comparison" assertion and I'm able to load both xml's via the properties.

    I'm also using an "Output log message" step with a "Save property to file" filter trying to save any xml differences found to the text file. When running the test case in an ITR i can see a test event showing the xml differences, however I have no clue on how i can address it to save it to the text file.

     

    My questions:

    1. How can i find the name of the property that keeps the xml differences?

     

    2. In the "Parse text as response" steps you need to manually load the XML's. How could i make this more dynamic (by just specifying folders)? For instance I have a folder Expected XML and a folder Actual XML. I tried using 2 "Load a set of filenames" data sets, but I can't get them saved into a property to use in the "Graphical XML Side-by-Side Comparison" assertion.

     

    I feel like I'm a bit lost and trying to complicate things.
    Could anyone help me get on the right track?



  • 2.  Re: Automate XML comparing
    Best Answer

    Posted Mar 17, 2017 04:13 PM

    You can try below option:

    1. To save the difference, You can write a java code which will take the assertion result of last step and write into the property:

    List assertionList =testExec.getLastNode().getAssertions();

    String assertion_detail = assertionList.get(0).getFailDetail();

    testExec.setStateValue("Final_Report", assertion_detail);

     

    2. Try using External/SubProcess -> Read from file step instead of 'Parse text as a response'.

    Provide a dynamic path and that will help you load the file into a property.

     

    Hope that helps.

     

    Thanks,

    Monika



  • 3.  Re: Automate XML comparing

    Posted Mar 21, 2017 03:25 AM

    Hi Monika,

     

    Thanks for your feedback.

    I need to put this code in a new "Execute script (JSR-223)" step?

     

    How can I provide a dynamic path in a "Read from file" step? and then load into a property? Could you give some more detailed info as the documentation on the different steps is really poor.

     

    Kr,

    Dave



  • 4.  Re: Automate XML comparing

    Posted Mar 21, 2017 01:03 PM

    1. Yes, You need to put this code in Execute script (JSR-223) step.

    2.  You can use Properties that hold the path for the file. in Read from file step. Mention the property name in which you want to save to file content. and use it for comparison in assertion.

     

    Let me know if want some screenshots to explain it further.

     

    Thanks,

    Monika

     



  • 5.  Re: Automate XML comparing

    Posted Mar 27, 2017 03:40 AM

    Thanks Monika, I will definately try that.

     

    Just one last question, where can you see the properties and methods that you used in your code sample (e.g. the getFailDetail from assertionList)?

     

    Is there some kind of reference available?

    It would be interesting to know all the different items, methods, properties we could use for scripting.