Forum Discussion

jasa's avatar
jasa
Occasional Contributor
15 years ago

Setting the value of XML attributes using Groovy Step

Hello,

I have a Groovy test step in my test case where I need to set the attribute value of an XML node, this is what I am doing but it is not working:

INPUT XML:

 


Script:
...
holder.setNodeValue( "/Envelope/element@id", "700")

Expected XML:

 



The XML is coming from a property that is populated from the result of a previous service call.

Any help and or tips are greatly appreciated!

thanks,
Jan

1 Reply

  • jasa's avatar
    jasa
    Occasional Contributor
    I managed to get it working this way:

    def request = testRunner.testCase.getTestStepByName("XML Store");
    def prop = request.getProperty("property");

    def rootNode = new groovy.util.XmlParser(false,false).parseText(prop.value);

    rootNode.element[0].@id = "700"