SoapUI比较两个XML响应非常慢 [英] SoapUI Comparing two XML responses is incredibly slow

查看:74
本文介绍了SoapUI比较两个XML响应非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的测试案例中,我有两个测试步骤来生成XML响应.XML结构彼此稍有不同,但是数据相同且顺序相同.

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.

我创建了一个Groovy脚本测试步骤,该步骤将从两个XML中读取数据的迭代并断言它们相等.这些XML响应中的行数可以超过500行.

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.

测试用例循环349次.

The Test Case loops over 349 times.

当我运行测试用例时,它滞后于第一个循环的groovy脚本断言-需要5分钟以上的时间才能完成.我正在尝试找出一种改进当前脚本的方法,或者是一种比较两个XML响应的更好方法.

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响应:

<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>
   <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脚本:

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

推荐答案

有一种简便的方法,但是这种方法不会突出显示2种XML之间不匹配的内容.它肯定会告诉您不匹配的内容

There is an easy way to do it But this way will not highlight what did not matched between 2 XML. It will surely tell things did not matched

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

        </ResultSet>
            </Results>
      '''

def xml2='''<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>
   </Response>'''

def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context)
def x1=   groovyUtils.getXmlHolder(xml1)
def x2=   groovyUtils.getXmlHolder(xml2)

def a1=x1.getNodeValues("//*:Row/*")
def a2=x2.getNodeValues("//*:e/*")

if(a1.toString()==a2.toString())
{
    log.info "Values matched in both XML for values"
}
else
{
    log.error "Values did not matched in both XML for values"
}


尽管很难对失败进行调试,但这是一种比较XML上所有值的有效方法.您甚至可以在各个节点级别进行比较.

Though this one is hard to debug as to where is the failure but an efficient way of comparing all values across XML. You can even compare at various nodes level.

XMLParser 相比,它更易于理解

This one is even easier to understand compared to XMLParser

这篇关于SoapUI比较两个XML响应非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆