Forum Discussion

Sandro2020's avatar
Sandro2020
New Contributor
4 years ago
Solved

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.

7 Replies

  • richie's avatar
    richie
    Community Hero
    Hi Sandro2020,

    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
    • Sandro2020's avatar
      Sandro2020
      New Contributor

      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. 

      • richie's avatar
        richie
        Community Hero
        Hey Sandro2020,

        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
  • 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. :)

     

  • nmrao's avatar
    nmrao
    Champion Level 3
    Marking this solved. If you still have issue feel free to open again.