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

时间:2017-06-02 16:58:17

标签: web-services groovy soapui

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

  • 第一个测试用例的付款请求具有帐号,例如2356698.
  • 我的第二个请求是为客户创建自动转帐(定期)个人资料。在请求中,其中一个元素是accountID,上面有字母。像这样,2356698REC。

有没有办法,我可以进行房产转让,并在帐号后添加这三个字母REC。考虑到我必须多次执行测试,因此每次都会更改accountID。所以我想从第一个请求获取accountID并将其转移到第二个请求,但也想要将REC添加到它。

这是通过财产转移还是时髦的脚本来实现的? 任何形式的帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

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

添加两个SOAP请求步骤,您可能已经拥有它们。在两个请求步骤之间不需要属性转移或groovy脚本步骤。

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

var refresh = function(){

    $.ajax({
        url: 'ticker.php',
        type: 'POST',
        data: yourJsonData,
    })
    .done(function(msg) {
        document.getElementById('ticker').innerHTML = "<script src='ticker.php?" + new Date().getTime() + "'></script>";
    })
    //msg is equal to "document.write('It is the scrolling news');"
    //then JSON.parse(msg); to convert to a javascript object
    .fail(function(err) {
        console.log("error"+err);

    })
    .always(function() {
        console.log("complete");
    });

}

在第二个请求中,执行以下更改: 这假设元素名称为//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

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

即使上述情况也可以在<AccountId>${#TestCase#ACCOUNT_ID}REC</AccountId> 的帮助下完成。将值保存到测试用例并使用上面提到的第二步使用REC和属性扩展。