数か月前に新しいジョブを開始し、視覚的な検証が必要なテストのバッチを実行するには、SoapUIの基本的な日常的な使用が必要です(視覚的な部分はまだ自動化されていません)。
しかし、今ではプロジェクトにインポートする必要のある新しいxmlファイルがたくさんあり、ファイルをインポートしてファイル内のコンテンツをxmlテキストとして使用するために誰かがGroovyスクリプトなどを持っているかどうか疑問に思っていました。パス、。HTTPリクエスト経由。
基本的に、私はalbciffがここで何をしたかを知りたいです。しかし、私のxmlファイルをHTTPステップに変えてください。
HTTPの正しいクラスを含めるように彼のスクリプトを変更しようとしましたが、修正できない例外が発生します
更新28/01
SoapUIの無料/標準版を使用しています。私は単なる機能テスターなので、コーディング/スクリプトの知識は限られています:(
私の現在のGroovyスクリプトは
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
import com.eviware.soapui.impl.wsdl.teststeps.registry.HttpRequestStepFactory
import groovy.io.FileType
// get the current testCase to add testSteps later
def tc = testRunner.testCase
// get the testStep as template to create the other requests
def tsTemplate = tc.getTestStepByName("Template")
// create the factory to create testSteps
def testStepFactory = new HttpRequestStepFactory()
def requestDir = new File("C://directory//..//final_dir")
// for each xml file in the directory
requestDir.eachFileRecurse (FileType.FILES) { file ->
def newTestStepName = file.getName()
// create the config
def testStepConfig = testStepFactory.createConfig( tsTemplate.getOperation(), newTestStepName )
// add the new testStep to current testCase
def newTestStep = tc.insertTestStep( testStepConfig, -1 )
// set the request which just create with the file content
newTestStep.getTestRequest().setRequestContent(file.getText())
}
そして、私が実行しているときに私が得る例外は
groovy.lang.MissingMethodException:メソッドの署名がありません:com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep.getOperation()は引数タイプに適用できます:()値:[]考えられる解決策:次の行でgetAssertions()エラー: 14
あなたはほとんどそこ:)
にいます、この方法を試してください(HttpRequestStepFactory.createNewTestStep
代わりに使用してくださいHttpRequestStepFactory.createConfig
):
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
import com.eviware.soapui.impl.wsdl.teststeps.registry.HttpRequestStepFactory
import groovy.io.FileType
// get the current testCase to add testSteps later
def tc = testRunner.testCase
// get the testStep as template to create the other requests
def tsTemplate = tc.getTestStepByName("Template")
// create the factory to create testSteps
def testStepFactory = new HttpRequestStepFactory()
def requestDir = new File("C://directory//..//final_dir")
// for each xml file in the directory
requestDir.eachFileRecurse(FileType.FILES){ file ->
def newTestStepName = file.getName()
// get the template endpoint
def endpoint = tsTemplate.getPropertyValue('Endpoint')
// create the config using endpoint and your method (post in your case)
def testStepConfig = testStepFactory.createNewTestStep(tc,newTestStepName,endpoint,'POST')
// add the new testStep to current testCase
def newTestStep = tc.insertTestStep( testStepConfig, -1 )
// set the request which just create with the file content
def testRequest = newTestStep.getTestRequest()
testRequest.setRequestContent(file.getText())
// UPDATED CODE BELOW BASED ON COMMENT
// you can use in this case HttpRequestConfig (due the type of your
// testStep you can use this class) to set some additional properties
// in your TestStep
def httpReqCfg = testRequest.getConfig();
// for example for mediaType as you said in your comment
httpReqCfg.setMediaType('application/json');
}
HttpTestRequestStep.clone
メソッドを使用する方が便利に見えることに注意してください。ただし、これをgroovyで呼び出すと、testStep
が作成されますが、groovyは次の例外をスローします(ここでは、SOAPUI APIに問題があると思います)。
java.lang.ClassCastException:com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStepをcom.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStepにキャストできません
ただし、ファイルコンテンツを使用してリクエストを設定することだけに興味があると思うので、上記の提案されたコードで十分です。
コメントに基づいて編集:
コメントで必要に応じてパラメータHttpRequestConfig
を設定mediaType
または追加するために使用することもできHttpRequestConfig
ます。APIを確認してください。また、上記のコードを更新して、このオブジェクトを取得して確認する方法の例を示しますsetMediaType
。
お役に立てれば、
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加