我是SOAP UI的新手。 我有一个场景,比如我必须传递访问令牌值作为对测试套件下所有请求的响应。此访问令牌类型是“Bearer”。 我在名为“授权”的下一个请求头字段中添加此标记值,它正在工作,但我的查询是否有任何方法或可以添加的grovy脚本,可以应用于所有soap请求,而不是每次都更改值对于所有请求的标题。如何自动化?请指导我这个。
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.
最满意答案
我不明白你想要实现的目标,我想你想要为这个testCase每个请求添加一个用于Authoritzation的http-header作为值,为此你可以在下面放置一个groovy script testStep testStep请求获取令牌的位置。 在这个groovy脚本中,您可以放置以下代码,为此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的http-header和值${#TestCase#Authoritzation} ,如下图所示:
然后每次要设置此属性的值时,您可以使用不同的方法(我没有足够的有关您的案例的详细信息,因此我给出了不同的可能解决方案),属性转移testStep或使用testRunner.testCase.setPropertyValue('Authoritzation',yourToken)的groovy脚本testRunner.testCase.setPropertyValue('Authoritzation',yourToken) 。
希望能帮助到你,
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,
更多推荐
发布评论