SOAPUI 从 JDBC 响应中拾取值到数组中以进行断言
SOAPUI picking up values from JDBC response into an array for assert
我在这上面花了几个小时,在阅读了一些文章后,我不确定我是否采用了正确的方法。最后更多关于这个问题。
在我的 中,发现我在不该使用的时候使用了数组。我最近的问题是相反的,因为我想从我的 jdbc 响应中获取数据到一个数组中,以针对也在数组中的 SOAP 响应进行断言。
我有来自数组形式的 SOAP 响应的实际(已编辑)结果工作正常,但 JDBC 响应仅获取第一个值,因此断言失败。
这是我的 JDBC 回复的片段:
<Results>
<ResultSet fetchSize="64">
<Row rowNumber="1">
<TW070_VALIDATION.CODE>APP</TW070_VALIDATION.CODE>
<TW070_VALIDATION.VALID_DATA/>
</Row>
<Row rowNumber="2">
<TW070_VALIDATION.CODE>CHI</TW070_VALIDATION.CODE>
<TW070_VALIDATION.VALID_DATA>1</TW070_VALIDATION.VALID_DATA>
</Row>
<Row rowNumber="3">
<TW070_VALIDATION.CODE>DEN</TW070_VALIDATION.CODE>
<TW070_VALIDATION.VALID_DATA>1</TW070_VALIDATION.VALID_DATA>
</Row>
</ResultSet>
</Results>
我想为返回的每一行提取这两个值。因此,在此示例中,我希望获得以下内容以用于我的预期结果:
APP= ,CHI=1,DEN=1
我的断言脚本目前看起来像这样:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( messageExchange.responseContent )
def pxml = new XmlSlurper().parseText(context.response)
//grab the expected result from jdbc response
def expectedCodes = context.expand( '${JDBC Request for expected results#ResponseAsXml#//*:TW070_VALIDATION.CODE}' )
//grab the actual result from the SOAP response
def actualCodes = pxml.'**'.findAll{it.name() == 'ReportAssessment'}.collectEntries{[(it.ReportAssessmentGroup.text()):it.Ranking.text()]}
log.info expectedCodes
log.info actualCodes
assert expectedCodes == actualCodes
编辑:添加我的测试结构的图片。
EDIT2:添加来自我的 SOAP 响应的示例(第 4 步)
<ns2:ReportAssessment>
<ns2:ReportAssessmentGroup>APP</ns2:ReportAssessmentGroup>
<ns2:Ranking>0</ns2:Ranking>
<ns2:ReportAssessmentGroupDescription>APPLIANCES</ns2:ReportAssessmentGroupDescription>
</ns2:ReportAssessment>
<ns2:ReportAssessment>
<ns2:ReportAssessmentGroup>CHI</ns2:ReportAssessmentGroup>
<ns2:Ranking>1</ns2:Ranking>
<ns2:ReportAssessmentGroupDescription>CHIROPRACTIC</ns2:ReportAssessmentGroupDescription>
</ns2:ReportAssessment>
<ns2:ReportAssessment>
<ns2:ReportAssessmentGroup>DEN</ns2:ReportAssessmentGroup>
<ns2:Ranking>1</ns2:Ranking>
<ns2:ReportAssessmentGroupDescription>DENTAL</ns2:ReportAssessmentGroupDescription>
我一直在阅读有关循环方法的信息,所以不确定我是否可以在 groovy 脚本中解决这个问题,或者我是否需要不同的测试结构来包含循环。
给你:
您似乎遇到了问题,因为元素名称有 .
。因此,它需要包含在引号之间,如下所示:
首先找到所有 Rows
并根据每一行创建地图。
这里是Script Assertion
//Define the expected map (key value pairs)
def expected = [APP: '', CHI: '1', DEN: '1']
//Read the xml and create map
def xml = new XmlSlurper().parseText(context.response)
def actual = xml.'**'.findAll{it.name() == 'Row'}.collectEntries{ [(it.'TW070_VALIDATION.CODE'.text()): it.'TW070_VALIDATION.VALID_DATA'.text() ]}
log.info actual
assert expected == actual
编辑:基于 OP 评论和聊天
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( messageExchange.responseContent )
def pxml = new XmlSlurper().parseText(context.response)
//grab the expected result from jdbc response
def jdbcResponse = context.expand( '${JDBC Request for expected results#ResponseAsXml}')
def xml = new XmlSlurper().parseText(jdbcResponse)
def expectedCodes = xml.'**'.findAll{it.name() == 'Row'}.collectEntries{ [(it.'TW070_VALIDATION.CODE'.text()):it.'TW070_VALIDATION.VALID_DATA'.text() ]}
//grab the actual result from the SOAP response
def actualCodes = pxml.'**'.findAll{it.name() == 'ReportAssessment'}.collectEntries{[(it.ReportAssessmentGroup.text()):it.Ranking.text()]}
log.info expectedCodes
log.info actualCodes
assert expectedCodes == actualCodes
您可以在线快速试用demo
我在这上面花了几个小时,在阅读了一些文章后,我不确定我是否采用了正确的方法。最后更多关于这个问题。
在我的
我有来自数组形式的 SOAP 响应的实际(已编辑)结果工作正常,但 JDBC 响应仅获取第一个值,因此断言失败。
这是我的 JDBC 回复的片段:
<Results>
<ResultSet fetchSize="64">
<Row rowNumber="1">
<TW070_VALIDATION.CODE>APP</TW070_VALIDATION.CODE>
<TW070_VALIDATION.VALID_DATA/>
</Row>
<Row rowNumber="2">
<TW070_VALIDATION.CODE>CHI</TW070_VALIDATION.CODE>
<TW070_VALIDATION.VALID_DATA>1</TW070_VALIDATION.VALID_DATA>
</Row>
<Row rowNumber="3">
<TW070_VALIDATION.CODE>DEN</TW070_VALIDATION.CODE>
<TW070_VALIDATION.VALID_DATA>1</TW070_VALIDATION.VALID_DATA>
</Row>
</ResultSet>
</Results>
我想为返回的每一行提取这两个值。因此,在此示例中,我希望获得以下内容以用于我的预期结果:
APP= ,CHI=1,DEN=1
我的断言脚本目前看起来像这样:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( messageExchange.responseContent )
def pxml = new XmlSlurper().parseText(context.response)
//grab the expected result from jdbc response
def expectedCodes = context.expand( '${JDBC Request for expected results#ResponseAsXml#//*:TW070_VALIDATION.CODE}' )
//grab the actual result from the SOAP response
def actualCodes = pxml.'**'.findAll{it.name() == 'ReportAssessment'}.collectEntries{[(it.ReportAssessmentGroup.text()):it.Ranking.text()]}
log.info expectedCodes
log.info actualCodes
assert expectedCodes == actualCodes
编辑:添加我的测试结构的图片。
EDIT2:添加来自我的 SOAP 响应的示例(第 4 步)
<ns2:ReportAssessment>
<ns2:ReportAssessmentGroup>APP</ns2:ReportAssessmentGroup>
<ns2:Ranking>0</ns2:Ranking>
<ns2:ReportAssessmentGroupDescription>APPLIANCES</ns2:ReportAssessmentGroupDescription>
</ns2:ReportAssessment>
<ns2:ReportAssessment>
<ns2:ReportAssessmentGroup>CHI</ns2:ReportAssessmentGroup>
<ns2:Ranking>1</ns2:Ranking>
<ns2:ReportAssessmentGroupDescription>CHIROPRACTIC</ns2:ReportAssessmentGroupDescription>
</ns2:ReportAssessment>
<ns2:ReportAssessment>
<ns2:ReportAssessmentGroup>DEN</ns2:ReportAssessmentGroup>
<ns2:Ranking>1</ns2:Ranking>
<ns2:ReportAssessmentGroupDescription>DENTAL</ns2:ReportAssessmentGroupDescription>
我一直在阅读有关循环方法的信息,所以不确定我是否可以在 groovy 脚本中解决这个问题,或者我是否需要不同的测试结构来包含循环。
给你:
您似乎遇到了问题,因为元素名称有 .
。因此,它需要包含在引号之间,如下所示:
首先找到所有 Rows
并根据每一行创建地图。
这里是Script Assertion
//Define the expected map (key value pairs)
def expected = [APP: '', CHI: '1', DEN: '1']
//Read the xml and create map
def xml = new XmlSlurper().parseText(context.response)
def actual = xml.'**'.findAll{it.name() == 'Row'}.collectEntries{ [(it.'TW070_VALIDATION.CODE'.text()): it.'TW070_VALIDATION.VALID_DATA'.text() ]}
log.info actual
assert expected == actual
编辑:基于 OP 评论和聊天
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( messageExchange.responseContent )
def pxml = new XmlSlurper().parseText(context.response)
//grab the expected result from jdbc response
def jdbcResponse = context.expand( '${JDBC Request for expected results#ResponseAsXml}')
def xml = new XmlSlurper().parseText(jdbcResponse)
def expectedCodes = xml.'**'.findAll{it.name() == 'Row'}.collectEntries{ [(it.'TW070_VALIDATION.CODE'.text()):it.'TW070_VALIDATION.VALID_DATA'.text() ]}
//grab the actual result from the SOAP response
def actualCodes = pxml.'**'.findAll{it.name() == 'ReportAssessment'}.collectEntries{[(it.ReportAssessmentGroup.text()):it.Ranking.text()]}
log.info expectedCodes
log.info actualCodes
assert expectedCodes == actualCodes
您可以在线快速试用demo