Forum Discussion

SumitM's avatar
SumitM
Occasional Contributor
6 years ago

how to add / remove xml nodes from soap request with groovy test step.

Hi,

 

Can anyone please suggest me how to move forward for below issue.

 

Issue : I need to add / delete xml nodes from my base soap request as per my scenarios during run time.

 

Description : Suppose my base soap request is consisting of 10 nodes and during my tets execution, as per my scenario, I need to add some supplementary nodes in the test request. So my new test request for that scenario is now consisting of 15 nodes.

 

After the scenario is run successfull, I need to delete the newly added nodes and move on to next scenario. The next scenario can again have different set of nodes to be added to my base request.

 

Can anyone please suggest any way out of this issue.

 

Thanks,

Sumit M

  • Instead, you could replace the whole request instead of editing the nodes.

    May be store the exact request xmls into file per test and specify those file names in your excel data.
    While processing the datasource, read column value which is xml request file name, read that file and replace the request - which is more simple than what you are trying to do.
  • Radford's avatar
    Radford
    Super Contributor

    Just a very a high level overview of how I would approach this...

     

    You can get the xml data from your SOAP request using the Get Data Dialog from withing your Groovy test step. Then you can then user the XMLParser to convert this XML string data into Groovy objects which can easily be manipulated. Finally you can use the XmlUtil.serialize method to convert you newly manipulated Groovy XML object back to an XML string and then us it to update you SOAP request.

  • nmrao's avatar
    nmrao
    Champion Level 3
    How your test is designed? A screen shot please?
    Is it using data-driven approach? If so, how the data is stored which(test request) needs to be updated during runtime?
    • SumitM's avatar
      SumitM
      Occasional Contributor

      Hi,

      I am using data-driven approach to drive my test. My data is stored in excel file. I am using excel columns to pass data for different scenarios.

       

      As per my requirement, if I am encountering any perticular set of data then some nodes should be added to my soap request. Then after my scenario is run, I should remove my added nodes and move on to nxt scenario.

       

      Thanks,

      Sumit M

      • nmrao's avatar
        nmrao
        Champion Level 3
        Instead, you could replace the whole request instead of editing the nodes.

        May be store the exact request xmls into file per test and specify those file names in your excel data.
        While processing the datasource, read column value which is xml request file name, read that file and replace the request - which is more simple than what you are trying to do.