问题
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