2016-09-16 12 views
-1

SOAP UIを使用してWSDL/URLをテストするだけでしたが、この程度ではありませんでした。 SOAP UIからリクエストURLクエリパラメータを取得し、それらを使用してGroovyスクリプトを使用していくつかのものをテストする必要があります。リクエストurl soapuiからgroovyを使用してクエリを取得する

私は次のような階層内のSOAP UIでのGroovyスクリプトを作成したURL Id=111 ModeName=abc DeltaId=023423

から以下のものが必要

`http://myendpoint.com/customers?Id=111&ModeName=abc&DeltaId=023423` 

を次のように私はGetCustomers要求URLを考えてみましょう TestSuit-> TestCase-> TestStep-> GroovyScript

グルーヴィーなスクリプトでは、私は

def id = testRunner.testCase.getPropertyValue("Id")

を試してみましたが、私はidを印刷するとき、私はヌルとしてそれを取得しています。私はこれらのクエリパラメータにアクセスするために必要な他の設定についてはわかりません。 これらのクエリパラメータを取得し、それらのスクリプトに直接アクセスする方法はありますか?

+0

は、あなたがドキュメントを読むことをお勧めします。 org/rest-testing/understanding-rest-parameters.html – SiKing

答えて

2

あなたtestStep要求がGetCustomersあなたはStringとしてtestStepを得るために従ってGroovyのコードと、エンドポイントの値を持つプロパティを使用することができますと呼ばれていると仮定すると:

def ts = context.testCase.getTestStepByName('GetCustomers') 
def endpoint =ts.getPropertyValue('Endpoint') 
log.info endpoint // prints http://myendpoint.com/customers?Id=111&ModeName=abc&DeltaId=023423 

次にあなたがすることができますjava.net.URLクラスを使用してエンドポイントを解析し、getQuery()メソッドを使用してクエリパラメータを抽出します。その後、&で分割して各クエリ名の値のペアを取得し、最後に各ペアを=に分割し、結果をMapにします。要するに、あなたのコードのようなものが考えられます。URLクラスを使用せずに別のオプションがあります

import java.net.* 

def ts = context.testCase.getTestStepByName('GetCustomers') 
def endpoint =ts.getPropertyValue('Endpoint') 
// parse the endpoint as url 
def url = new URL(endpoint) 
// get all query params as list 
def queryParams = url.query?.split('&') // safe operator for urls without query params 
// transform the params list to a Map spliting 
// each query param 
def mapParams = queryParams.collectEntries { param -> param.split('=').collect { URLDecoder.decode(it) }} 
// assert the expected values 
assert mapParams['Id'] == '111' 
assert mapParams['ModeName']== 'abc' 
assert mapParams['DeltaId']=='023423' 

。これは単に(URL.getQuery()がするように)クエリパラメータを取得するために?を使用してURLを分割で構成されています。https:://www.soapuiあなたはGroovyのにすぎ入る前に

def ts = context.testCase.getTestStepByName('GetCustomers') 
def endpoint =ts.getPropertyValue('Endpoint') 

// ? it's a special regex... so escape it 
def queryParams = endpoint.split('\\?')[1].split('&') 
// transform the params list to a Map spliting 
// each query param 
def mapParams = queryParams.collectEntries { param -> param.split('=').collect { it }} 
// assert the expected values 
assert mapParams['Id'] == '111' 
assert mapParams['ModeName']== 'abc' 
assert mapParams['DeltaId']=='023423' 
関連する問題