Ask a Question

how to datasink values from a dynamic response

New Contributor

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 want to capture the value from the tech_value_string but only when the Tech_TechCode is 67. Can anyone help with the best approach to datasinking this value please?


<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<TechnicalData xmlns="">
<Tech diffgr:id="Tech1" msdata:rowOrder="0">
<Dc_Description>Emissions - ICE</Dc_Description>
<tech_value_string>Not Available</tech_value_string>
<Tech diffgr:id="Tech2" msdata:rowOrder="1">
<Dc_Description>Emissions - ICE</Dc_Description>
<Tech diffgr:id="Tech3" msdata:rowOrder="2">
<Dc_Description>Emissions - ICE</Dc_Description>
<tech_value_string>Not Available</tech_value_string>
<Tech diffgr:id="Tech4" msdata:rowOrder="3">
<Dc_Description>Emissions - ICE</Dc_Description>
<tech_value_string>Not Available</tech_value_string>
<Tech diffgr:id="Tech5" msdata:rowOrder="4">
<DT_LongDescription>Noise Level dB(A)</DT_LongDescription>
<Dc_Description>Emissions - ICE</Dc_Description>
<tech_value_string>Not Available</tech_value_string>




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
    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()


SmartBear Alumni (Retired)

Thanks for the help, @jsheph01!

@cstott02, is this what you are looking for?

Tanya Yatskovskaya
SmartBear Community and Education Manager

Showing results for 
Search instead for 
Did you mean: