Forum Discussion

dinojadhav's avatar
dinojadhav
Occasional Contributor
5 years ago
Solved

How to capture values from a duplicate tags using groovy script

Hello All,   I have a soap response from which I want to capture some values to use it later. I am able to capture the value from the first tag but unable to capture the value from the second tag...
  • HimanshuTayal's avatar
    HimanshuTayal
    5 years ago

    dinojadhav ,

     

    So to count

    <stl19:RecordLocator>KYIHBI</stl19:RecordLocator>, 

    <stl19:RecordLocator>KYIFID</stl19:RecordLocator>
    You can use count and then iterate the count to each duplicat record. Refer below piece of code for reference:
     
    import com.eviware.soapui.support.GroovyUtils
    import com.eviware.soapui.support.XmlHolder
    
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def xmlHolder = groovyUtils.getXmlHolder(xml)
    def val = xmlHolder["//*:RecordLocator"]
    def count = xmlHolder["count(//*:RecordLocator)"]
    
    for(i=0;i<count.toInteger();i++){
    	log.info val[i] // it will print all the values from duplicate RecordLocator tags
    }