Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

XML Assertion for single element

api_tester
api_tester Posts: 28
edited August 2019 in SOAtest

Hi team,

I need to validate a value say itemID (used excel datasource ) from xml response but in the response xml a no. of itemID nodes gets generated ,so I have to check with each itemID present in the response.The required itemID in response doesnot everytime generates at the same node so while selecting the element I have given xpath as
/:Envelope/:Body/:Response/:itemID/text(). [/ * given]
I have used value assertion but if I have 5 RuleID in my response 1 will get validated and rest 4 will not match so the validation fails.

How to achieve this assertion ?

Kindly help.

Comments

  • api_tester
    api_tester Posts: 28

    Hi if anyone can help on the above

  • api_tester
    api_tester Posts: 28

    I have used the following simple custom assertion using JavaScript :
    function customAssertion(input, context) {
    value = context.getValue("Datasheet", "RuleID"); //Accessed from datasource
    Application.showMessage("Value from data source is " + value);
    Application.showMessage("Value from SOAP response is " + input.toString());
    return input.toString().contains(value);
    }

    but it is capturing all the 5 nodes' itemID passing 1 node's value because it matched with my DataSource's value and rest failed.

    Even I tried to add if else statement and break but it was not working. kindly help!!

  • api_tester
    api_tester Posts: 28

    Any help ??

  • jakubiak
    jakubiak Posts: 795 admin

    It sounds like you need to perform the same validation on each itemID node. If that is the case, you should be to do this by specifying an XPath that matches all itemID nodes, rather than just a specific itemID node.