Forum Discussion

cstott02's avatar
cstott02
New Contributor
6 years ago

how to datasink values from a dynamic response

Each time i send a request to a SOAP service the repsonse provided is dynamic and the location of a particular field i'm interested in data sinking may change.    Within the below XML response, i...
  • jsheph01's avatar
    6 years ago

    I'm not sure if there is a way to do what you are asking with an assertion sctipt since you wont have access to testRunner. You should be able to do that with a groovy script step. Depending on how your datasink is setup you may have to disable it so it does not run after the request and log everything. Just a warning; I have not been able to test this code, but it should get you started.

     

    //get the response as xml
    def tStep = testRunner.testCase.getTestStepByName("testStepName")
    def reponse =  '${testStepName#ResponseAsXml}' 
    xmlHold = context.expand(response)
    def holder = new XmlParser().parseText(xmlHold)
    holder instanceof Node
    def max = holder.TechnicalData.Tech.size()
    
    //loop through each tech node
    for(cnt=0;cnt<max;cnt++){ 
        if(holder.TechnicalData.Tech[cnt].Tech_TechCode.text() == "67"){
    		tStep = testRunner.testCase.getTestStepByName("dataSink")
            def tech_value_string = (holder.TechnicalData.Tech[cnt].tech_value_string.text()
    	    tStep.setPropertyValue(dataSinkTarget,tech_value_string)
    	}
    }