Forum Discussion

Nitin's avatar
Nitin
Occasional Contributor
16 years ago

how to modify request ??

Hi, I wanted to add modify following request. Want to set- OperatorId=2
How do i do this?
sample code for this will be really helpful.


 

 
     
       
        ?
       
       
       

       
        ?
     

 


Regards,
Nit

2 Replies

  • AnandKiran's avatar
    AnandKiran
    Frequent Contributor
    Hi Nitin,
                    Actually what is your exact requirement for modifying a request you can simply edit the values with the tags . Do you want to do it through groovy ?

    Can you be more specific with your issue .


    Thanks
    With Regards
    Anand Kiran G
  • Nitin's avatar
    Nitin
    Occasional Contributor
    Thanks for reply, AnandKiran

    Yes i wanted to do it through groovy. It's done now.  :-)


    def request = testRunner.testCase.getTestStepByName( "GetActiveVehicles - Request 1" );
    //log.info request
    def property = request.getProperty("request");
    //log.info property
    def node = new groovy.util.XmlParser(false,false).parseText(property.value);
    //log.info node
    //def textNodes = node["soapenv:Body"][0].children()
    //log.info textNodes
    def textNodes = node["soapenv:Body"]["tem:GetActiveVehicles"]["tem:OperatorId"][0].children()
    log.info textNodes

    // modify
    textNodes.clear();
    textNodes.add( "test" + System.currentTimeMillis() );

    // write back to string
    def writer = new java.io.StringWriter();
    def printer = new groovy.util.XmlNodePrinter( new PrintWriter( writer ));
    printer.print( node );

    // set property
    property.setValue( writer.toString() )