Forum Discussion

clay's avatar
clay
Contributor
8 years ago
Solved

How to verify the absence of an element in an XML checkpoint.

I have an application that is supposed to remove an element from an XML document.  So I want the checkpoint to pass if the tag is missing and fail if the tag is present.  How does one go about doing this?

 

Thanks.

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I personally would not use a checkpoint.  I'd actually create an instance of the MSXML.DOMDocument object and use it to search for the tag.  If the tag comes back, then it fails.  Specifically, I'd use the "selectNodes" method (https://msdn.microsoft.com/en-us/library/ms754523(v=vs.85).aspx).


    If you want do to checkpoints, basically, within your project, under the "Stores" section, add the XML node and then add an XML checkpoint for your XML Document.  Basically, make it to match the expected (i.e., missing the tag) and then use the "Check" method on that object to see if the tag is missing.  If it's there, the checkpoint should fail.  

     

    Read up at https://support.smartbear.com/testcomplete/docs/reference/project-objects/items/stores/xml/index.html

     

     

    • clay's avatar
      clay
      Contributor

      We have an event-driven logger that captures checkpoint data, so we need to use checkpoints for the logger to work.  So, I ended up incorporating a little of both your suggestions.  I did the check using the XML DOM library calls.  If the test passes (e.g., the tag is not found, then I call a Check method against a checkpoint that is basically an empty XML file so it is guaranteed to "Pass".  If the test fails, I make a Log.Error(...) call.

       

      This was bit of a kludge, but it works.

       

      BTW - has there been any talk of an XML checkpoint that finds unwanted tags?  I am thinking that it would be useful to validate an XML file against an XML schema to make sure the XML file is compliant with that schema - as an example.

       

      Thanks for the help - I will close out the issue.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Rather than kludging up an empty XML Checkpoint to get a "pass", you can actually manually call "Log.CheckPoint" to write a pass record out to the test log.