cancel
Showing results for 
Search instead for 
Did you mean: 

how to datasink values from a dynamic response

SOLVED
Dear Community, API Masterminds week 4 has started!

Participate in the exciting online event by posting questions or replies and win! During the entire March, we decide top contributors each week and reward them with great gifts . Congratulate the winners of Week 3 here.
Week 4 task: Ask more questions, bring interesting topics and reply to existing ones in the ReadyAPI Community
Topics to participate in:
See All
Week 4 Leaders:
Members with the biggest number of posts
sonya_m 16 posts
nmrao 14 posts
HimanshuTayal 12 posts
pizzaTime 1 posts
richie 1 posts
Highlighted
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
Highlighted
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
Highlighted
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

Highlighted
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 Gorbunova
SmartBear Community Manager

 Join the 2020 API Masterminds event in the ReadyAPI Community to demonstrate your excellent expertise, help people and win prizes! Start participating today!
New Here?
Join us and watch the welcome video:
Join 2020 API Masterminds
We invite all lovers of API testing to participate in the API Masterminds event. Ask questions or help others by giving solutions and get rewarded.
>> Participate Today
Get Your Free Ticket
SBC2020
Top Kudoed Authors