Groovy 附加响应标记值并在属性中设置的断言
Groovy Assertion to append the response tagvalues and set in the properties
我从 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>
我想附加 ErrorType 和 ErrorCode 以在 'Name' 列中设置,并在我在 JDBC 旁边创建的属性测试步骤的 'Value' 列中附加 ErrorText测试步骤。
我的属性步骤应该与下面的屏幕截图类似。
相信这可以通过在 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 响应作为映射 - Demo
我从 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>
我想附加 ErrorType 和 ErrorCode 以在 'Name' 列中设置,并在我在 JDBC 旁边创建的属性测试步骤的 'Value' 列中附加 ErrorText测试步骤。 我的属性步骤应该与下面的屏幕截图类似。
相信这可以通过在 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 响应作为映射 - Demo