How to transfer dynamic auth value in all requests instead of changing the value in every request's header in SOAPUI

假如想象 提交于 2019-12-13 08:14:22

问题


I am new in SOAP UI. I have an one scenario like I have to pass the access token value coming as a response to all the requests under the test suite.This access token type is "Bearer". I ADD this token value in the next request header field called "Authorization" and it is working but my query is there any method OR grovy script that I can add which can be applied for all the soap requests, instead of changing the value every time for all request's header.How to automate this?Please guide me on this.


回答1:


I don't understand exactly what you are trying to achieve, I suppose that you want to add an http-header for Authoritzation with your token as value for each request within this testCase, to do so you can put a groovy script testStep below the testStep request where you get your token. In this groovy script you can put the follow code which sets an http-header for each testStep in this testCase:

// 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"
    }
}

This script adds the required http-header for each testStep in your testCase.

EDIT

Another possible approach is to add a testCase property as an http-header value and then set the value for this property when you need to refresh this value. To do so in your TestStep request click on Headers() tab and add a http-header with name Authoritzation and value ${#TestCase#Authoritzation} as in the follow image:

Then each time that you want to set the value for this property you can use different approaches (I don't have enough details about your case so I give you different possible solutions), property transfer testStep or a groovy script testStep using testRunner.testCase.setPropertyValue('Authoritzation',yourToken).

Hope it helps,



来源:https://stackoverflow.com/questions/33008555/how-to-transfer-dynamic-auth-value-in-all-requests-instead-of-changing-the-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!