Forum Discussion
I like to use the XmlSlurper to parse XML data, here is a standalone example with your data:
import groovy.util.XmlSlurper def xmlData = '''\ <Results> <ResultSet fetchSize="128"> <Row rowNumber="1"> <UNIQUEID>80382049</UNIQUEID> <SOURCESYSTEM>HitsSC</SOURCESYSTEM> <ROUTEID>39812</ROUTEID> <SHIFTDATE>2018-12-07 00:00:00.0</SHIFTDATE> </Row> <Row rowNumber="2"> <UNIQUEID>80382096</UNIQUEID> <SOURCESYSTEM>NTExchange</SOURCESYSTEM> <ROUTEID>39812</ROUTEID> <SHIFTDATE>2018-12-07 00:00:00.0</SHIFTDATE> </Row> <Row rowNumber="3"> <UNIQUEID>80382097</UNIQUEID> <SOURCESYSTEM>NTExchange</SOURCESYSTEM> <ROUTEID>39812</ROUTEID> <SHIFTDATE>2018-12-07 00:00:00.0</SHIFTDATE> </Row> <Row rowNumber="4"> <UNIQUEID>80382098</UNIQUEID> <SOURCESYSTEM>NTExchange</SOURCESYSTEM> <ROUTEID>39812</ROUTEID> <SHIFTDATE>2018-12-07 00:00:00.0</SHIFTDATE> </Row> </ResultSet> </Results>''' def Results = new XmlSlurper().parseText(xmlData) Results.ResultSet.Row.each(){row -> log.info('UNIQUEID = ' + row.UNIQUEID + '; ROUTEID = ' + row.ROUTEID) }
- del_exaclee7 years agoNew Contributor
Thanks for this Radford. A couple of things:
1) I need the code to dynamically take its input from a JDBC response as this code will need to run 100 times for our test requirements so I need to parse the JDBC response as XML dynamically.
2) Once I have extracted that data from the JDBC response, can I populate this data into a single test case property so that I can inject it into a SOAP request?
Regards,
Ajay
- Radford7 years agoSuper Contributor
To get the results from the JDBC step I would just use the point and click Get Data functionality. Just right click in the groovy script, select the Get Data item, and select your desired data.
As for setting properties via Groovy script. See the following link for examples:
https://support.smartbear.com/readyapi/docs/testing/scripts/samples/variable.html
But in short, you will see that the test suites, cases and steps all have a setPropertyValue method, so from a Groovy script test step you'll write something like:
context.getTestCase().getTestStepByName('StepName').setPropertyValue( 'PropName', 'Value' )
- Olga_T7 years agoSmartBear Alumni (Retired)
Hi everyone,
Radford thank you for sharing your solution and the instructions!
del_exaclee did you manage to accomplish your task? If your question was answered, do you mind accepting Radford's reply as a Solution? This will help other users find the reply easier in the future.
Otherwise, feel free to provide us with updates on the issue.
Thank you in advance,
Related Content
Recent Discussions
- 18 hours ago
- 17 days ago