Forum Discussion

ngoyal's avatar
ngoyal
Occasional Contributor
6 years ago

Modify Teststep request to add new nodes with attributes using groovy script

Team I am facing an issue where I am able to fetch muliple values of an attibute from reponse using groovy script and want to create new nodes with attributes in next test step request. I have gone t...
  • nmrao's avatar
    6 years ago

    ngoyal ,

     

    Get the list of ChainCode and HotelCode and put them in a map.

    Then loop thru map and append nodes.

     

    You were almost there, but trivial error.

     

    Here is the script that you try & test online

     

    //You need to build the map from previous response
    def map = ['03062': 'ABC', '03092': 'ABC', '03144': 'ABC']
     
    criteria = xml.'**'.find {'Criterion' == it.name()}
    criteria.appendNode {
    	map.each { k, v ->
    		HotelRef('ChainCode' : v, 'HotelCode': k)
    	}
    }
    log.info groovy.xml.XmlUtil.serialize(xml)