In my test case I have two test step that produce an XML response. The XML structure is slightly different from one another but the data is the same and ordered the same.
I have created a Groovy Script test step that will read the iterations of data from both XMLs and assert that they equal. The number of rows in these XML Response can exceed 500 rows.
The Test Case loops over 349 times.
When I run the test case, it lags on the groovy script assert for the first loop through - taking greater than 5 minutes to complete. I am trying to figure out a way to improve the current script or a better approach to comparing the two XML Response.
JDBC Response:
<Results>
<ResultSet fetchSize="128">
<Row rowNumber="1">
<id>1540107</id>
<name>10C/Ar1</name>
<code>10C/Ar1</code>
<subjectId>349176</subjectId>
</Row>
<Row rowNumber="2">
<id>1540108</id>
<name>11A/Ar1</name>
<code>11A/Ar1</code>
<subjectId>349177</subjectId>
</Row>
...
REST Response:
<Response>
<e>
<id>1540107</id>
<name>10C/Ar1</name>
<code>10C/Ar1</code>
<subjectId>349176</subjectId>
</e>
<e>
<id>1540108</id>
<name>11A/Ar1</name>
<code>11A/Ar1</code>
<subjectId>349177</subjectId>
</e>
...
Groovy Script:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
//API Response
def HolderA = groovyUtils.getXmlHolder(context.expand('${01_Test_Step_05#ResponseAsXml}'))
def CountA = HolderA.getNodeValues("//e").size();
log.info CountA
//Database Query Response
def HolderB = groovyUtils.getXmlHolder(context.expand('${01_Test_Step_04#ResponseAsXml#//Results[1]/ResultSet[1]}'))
def CountB = HolderB.getNodeValues("//Row").size();
log.info CountB
//Asser Response Sizes
assert CountA == CountB : 'Response Counts Dont Equal'
def i = 1
while(i < (CountA + 1)) {
//API Response Elements
def id_A = context.expand( '${01_Test_Step_05#ResponseAsXml#//e[' + i + ']/id}' )
def name_A = context.expand( '${01_Test_Step_05[GET]#ResponseAsXml#//e[' + i + ']/name}' )
def code_A = context.expand( '${01_Test_Step_05[GET]#ResponseAsXml#//e[' + i + ']/code}' )
def subjectId_A = context.expand( '${01_Test_Step_05[GET]#ResponseAsXml#//e[' + i + ']/subjectId}' )
//Database Query Response Elements
def id_B = context.expand( '${01_Test_Step_04#ResponseAsXml#//Results[1]/ResultSet[1]/Row[' + i + ']/id}' )
def name_B = context.expand( '${01_Test_Step_04#ResponseAsXml#//Results[1]/ResultSet[1]/Row[' + i + ']/name}' )
def code_B = context.expand( '${01_Test_Step_04#ResponseAsXml#//Results[1]/ResultSet[1]/Row[' + i + ']/code}' )
def subjectId_B = context.expand( '${01_Test_Step_04#ResponseAsXml#//Results[1]/ResultSet[1]/Row[' + i + ']/subjectId}' )
//Assert API Response Elements & Database Query Response Elements
assert id_A == id_B : 'Mismatching IDs'
assert name_A == name_B : 'Mismatching Names'
assert code_A == code_B : 'Mismatching Codes'
assert subjectId_A == subjectId_B : 'Mismatching Subject IDs'
i++
}
