Remove attribute from request
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Remove attribute from request
Hi,
I have a simple SOAP request in XML format below. The attributes extension and root are referencing from the DataSource.
<v3:providerOrganizationID>
<v3:value extension="${DataSource#UPI}" root="${DataSource#Root}" />
</v3:providerOrganizationID>
And I have a negative test cases where the Extension and Root may have an Empty value in the DataSource. Is there an option specified in Ready! API to remove the attribute when the extension and root attributes are set to Empty? So, the outcome would become
<v3:providerOrganizationID>
</v3:providerOrganizationID>
Thanks.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't think theres an option to do this via the embedded functionality per se; are you thinking about having the empty attributes/element removal so you can use the looping functionality? Id think about this option carefully, the reason being its likely youd want different assertions for your negative tests to your positive tests.
If i use loops, the assertions have to be relevant to all the test scenarios you are executing in your loop.
Typically i have a looping testcase for my positive scenarios and a looping testcase for my negative test cases. Obviously id have different datasources configured for my positive and negative tests.
If i was going to try and do what you suggest, (remove the attributes and tag) id use groovy.
However i have a couple of questions/thoughts you also might want to think about.
Considering the root and extension are attributes of the value element, are you sure the system youre testing would actually remove the value tag also if the value element's attributes are empty? Cos thats quite unusual.
Are there any other elements enclosed within the providerOrganizationID parent/container element as well as the value element? Reason i ask is that if your system uses the approach of removing elements when empty (xml uses a lot of bandwidth so software architects like to remove any tag that isnt populated), then its reasonable to expect the container element (providerOrganizationID) to be removed also....?
That's it for me....one of the other forum members might have some alternative ideas.
Nice one,
Rich
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I would expect the container element (providerOrganizationID) would also be removed. Can I use Java instead of Groovy to remove the container element, attribute and tags?
Thanks.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Id double check in your validating .xsd if the elements are nillable=true. Do both the <value /> and <providerOrganizationID /> tags have minOccurs=0 in the .xsd? Both minOccurs and maxOccurs defaults are '1' in xml schema so the elements will need to have minOccurs set to '0' for this to be allowed. What you dont want is nillable=true and minOccurs=1 cos this will force the population of empty elements in your xml instance.
As to your question regarding whether you can use Java rather than groovy? Absolutely. Groovy uses the Java runtime, but you can use any java library from the Java api and use any bespoke ones as long as you add the relevant .jar files in and declare what youre using at the start.
I mentioned groovy cos thats what the default scripting language is packaged with ReadyAPI!. You can use JavaScript too, although that's extra effort and i think people are less knowledegeable on the forum relative to groovy experts on this thing.
Cheers
Rich
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
https://stackoverflow.com/questions/35826398/remove-a-specific-xml-node-with-namespace-using-groovy
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you richie and nmrao!
Hi @Sandro2020, were you able to complete your task using the advice from the Community? Or, mayhaps, you solved this in a different way?
Sonya Mihaljova
Community and Education Specialist
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Sandro2020 : you can achieve this by writing a small groovy code, it can't get deleted by any built in feature.
You can refer above replies on how to write the code for deleting the node. 🙂
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
Thanks and Regards,
Himanshu Tayal
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
