如何在 soapUI 中使用 属性 传输添加文本

How to add text with a property transfer in soapUI

我在 soapUI 中有一个测试套件,它有两个测试用例。

有什么办法,我可以做一个属性转账,在账号后面加上REC这三个字母。考虑到我必须多次执行测试,所以 accountID 每次都会更改。所以我想从第一个请求中获取 accountID 并将其传输到第二个请求,但也想向其中添加 REC。

是否可以通过 属性 传输或 groovy 脚本实现?
任何形式的帮助将不胜感激。

希望在 soapui 项目中创建了一个测试用例。

添加两个 SOAP 请求步骤,您可能已经有了。在两个请求步骤之间不需要 属性 传输或 groovy 脚本步骤。

对于第一个请求,使用以下代码添加 Script Assertion

//Check if there is response
assert context.response, 'Response is empty'

//provide the element name which data you need to extract, in this case accountId
def requiredElement = 'accountId'

def xml = new XmlSlurper().parseText(context.response)

//extract account id value from xml
def accountIdValue = xml.'**'.find{it.name() == requiredElement}?.text()

//Store at test case level custom property
context.testCase.setPropertyValue('ACCOUNT_ID', accountIdValue)

在第二个请求中,进行以下更改: 这假设元素名称是 AccountId,您可以根据需要更改以满足您的需要。

<AccountId>${#TestCase#ACCOUNT_ID}REC</AccountId>

当发送请求时,soapui 在第二个请求中替换为第一步提取的值。

Property transfer 的帮助下甚至可以完成上述操作。将值保存到测试用例中,并按照上面提到的方法将其用于带有 REC 和 属性 扩展的第二步。