Ask a Question

how to datasink values from a dynamic response

SOLVED
cstott02
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">
<Tech_TechCode>110</Tech_TechCode>
<DT_LongDescription>CO</DT_LongDescription>
<Dc_Description>Emissions - ICE</Dc_Description>
<tech_value_string>Not Available</tech_value_string>
</Tech>
<Tech diffgr:id="Tech2" msdata:rowOrder="1">
<Tech_TechCode>67</Tech_TechCode>
<DT_LongDescription>CO2</DT_LongDescription>
<Dc_Description>Emissions - ICE</Dc_Description>
<tech_value_string>165</tech_value_string>
</Tech>
<Tech diffgr:id="Tech3" msdata:rowOrder="2">
<Tech_TechCode>133</Tech_TechCode>
<DT_LongDescription>HC</DT_LongDescription>
<Dc_Description>Emissions - ICE</Dc_Description>
<tech_value_string>Not Available</tech_value_string>
</Tech>
<Tech diffgr:id="Tech4" msdata:rowOrder="3">
<Tech_TechCode>113</Tech_TechCode>
<DT_LongDescription>HC+NOx</DT_LongDescription>
<Dc_Description>Emissions - ICE</Dc_Description>
<tech_value_string>Not Available</tech_value_string>
</Tech>
<Tech diffgr:id="Tech5" msdata:rowOrder="4">
<Tech_TechCode>109</Tech_TechCode>
<DT_LongDescription>Noise Level dB(A)</DT_LongDescription>
<Dc_Description>Emissions - ICE</Dc_Description>
<tech_value_string>Not Available</tech_value_string>

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jsheph01
Contributor

Re: how to datasink values from a dynamic response

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

 

View solution in original post

2 REPLIES 2
jsheph01
Contributor

Re: how to datasink values from a dynamic response

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

 

View solution in original post

TanyaYatskovska
Community Manager

Re: how to datasink values from a dynamic response

Thanks for the help, @jsheph01!

@cstott02, is this what you are looking for?

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager

Join Wintertainment 2021 to share your stories, have fun, earn community badges, and more!
cancel
Showing results for 
Search instead for 
Did you mean: