Groovy断言附加响应标记值并在属性中设置

Groovy断言附加响应标记值并在属性中设置,groovy,soapui,Groovy,Soapui,下面是我从JDBC测试步骤得到的响应。这包括ErrorCode、ErrorType和ErrorText <Row rowNumber="1"> <ErrorType>W</ErrorType> <ErrorCode>000001</ErrorCode> <ErrorText>Message receiver not set to insurer or reinsurer</ErrorTex

下面是我从JDBC测试步骤得到的响应。这包括ErrorCode、ErrorType和ErrorText

<Row rowNumber="1">
     <ErrorType>W</ErrorType>
     <ErrorCode>000001</ErrorCode>
     <ErrorText>Message receiver not set to insurer or reinsurer</ErrorText>
  </Row>
  <Row rowNumber="2">
     <ErrorType>W</ErrorType>
     <ErrorCode>000002</ErrorCode>
     <ErrorText>Service Provider is not present in the message</ErrorText>
  </Row>

W
000001
消息接收方未设置为保险人或再保险人
W
000002
消息中不存在服务提供程序
我想在属性测试步骤的“Name”列中添加ErrorType&ErrorCode,并在属性测试步骤的“Value”列中添加ErrorText,属性测试步骤是我在JDBC测试步骤旁边创建的。 我的属性步骤应该如下面的屏幕截图所示


相信这可以通过在JDBC测试步骤中添加Groovy断言来实现。有人能帮忙吗?请让我知道更多信息,这里是JDBC请求测试步骤的脚本断言。不需要额外的Groovy脚本测试步骤

脚本断言

//Define the property test step name, change if needed
def stepName = 'Properties'
//check the response
assert context.response, 'response is empty'
def xml = new XmlSlurper().parseText(context.response)
//Get the response data as map
def map = xml.'**'.findAll { it.name() == 'Row' }.inject([:]){m, item -> m[item.ErrorType.text()+item.ErrorCode.text()] = item.ErrorText.text();m}

def step = context.testCase.testSteps[stepName]
//Use below statement if you need to remove existing properties and just keep the properties from current response only
step.propertyNames.each { step.removeProperty(it)}
//Create properties as needed into properties step from jdbc response
map.each { step.setPropertyValue(it.key,it.value)}

您可以在线检查以获取jdbc响应,如map-

Harry,以后您将如何使用这些值?这将有助于制定更好的办法。如果您获得更多的
s数据,该怎么办?在JDBC测试步骤中,我只选择了几行(最多5-6行,这是验证的预期结果)。。因此,无需担心大块行。。在属性步骤中保存后,我会进行不同的测试。好的,在将它们存储到属性中后,您需要做什么?这是主要问题。在属性步骤中存储后,我会进行不同类型的验证。。您已经在下面的线程中解决了这一问题:)。。在此之前,我已经在属性中手动添加了。。现在我必须从数据库中提取数据并将其存储在属性中。。这就是你为什么要澄清的原因。请检查答案。请注意,该答案经过编辑以处理从以前的运行中删除现有属性的操作。现在它总是只保留当前jdbc响应中的属性。。这奏效了。。但是在使用代码assert context.response“response is empty”时,我得到了错误消息“response is empty”,因此,我刚刚调整了代码def resp=context.testCase.getTestStepByName(“JDBC Stepname”).getPropertyValue(“ResponseAsXml”)。@Harry,不确定您是怎么做的。但是,当您实际运行测试或者已经有jdbc步骤的响应时,这种方法是有效的。否则,您将得到空值。是。。我在我的步骤中得到了回应。。只要替换我的代码,这就行了。。也拍了截图。。但我不知道如何在评论中插入截图。。但不管怎样,我还是从你那里得到了结果。:)谢谢你一如既往的精彩回复:)@Harry,很高兴它有所帮助。