如何在所有请求中传输动态auth值,而不是在SOAPUI中更改每个请求的标头中的值

问题描述 投票:0回答:1

我是SOAP UI的新手。我有一种情况,例如我必须传递访问令牌值,以作为对测试套件下所有请求的响应。此访问令牌类型为“承载”。我将此令牌值添加到称为“授权”的下一个请求标头字段中,并且可以正常工作,但是我的查询中有可以添加的任何方法或常规脚本,可将其应用于所有肥皂请求,而无需每次都更改该值为所有请求的标头。如何自动执行此操作?请为此指导我。

web-services soap soapui
1个回答
1
投票

我不确定您要实现的目标,我想您想为Authoritzation添加一个HTTP标头,并将令牌作为此testCase中每个请求的值,为此,您可以将在testStep请求下方的groovy script testStep中,您可以从中获取令牌。在这个常规脚本中,您可以将以下代码放入该testCase中为每个testStep设置一个http-header的示例中:

// testSteps is a map where keys are request names and values are the instance
// of the testStep
testRunner.testCase.testSteps.each{ name, testStep ->
    log.info name
    // check if the testStep has required methods (to avoid error
    // trying to add header on groovy script testSteps for example)
    if(testStep.metaClass.getMetaMethod("getTestRequest")){
        def request = testStep.getTestRequest()
        def headers = request.getRequestHeaders()
        headers.add('Authoritzation','yourToken')
        request.setRequestHeaders(headers)
        log.info "Added header to $name"
    }
}

此脚本为您的testCase中的每个testStep添加必需的http-header。

编辑

[另一种可能的方法是将testCase属性添加为http-header值,然后在需要刷新此值时为此属性设置值。为此,请在您的TestStep请求中单击Headers()选项卡,并添加一个名称为Authoritzation和值${#TestCase#Authoritzation}的http标题,如下图所示:

enter image description here

然后,每次您要为此属性设置值时,可以使用不同的方法(我没有关于您的案例的足够详细的信息,因此我给您提供了不同的可能解决方案),属性传递testStep或使用[ C0]。

希望有帮助,

© www.soinside.com 2019 - 2024. All rights reserved.