2016-09-21 7 views
-2

石鹸(無料版)には、対応して生成された文書をエクスポートするオプションがあります。アプリケーション/ pdfファイルを抽出してローカルフォルダに保存するグルービー機能はありますか?groovyを使ってsoapレスポンスからpdf添付ファイルをエクスポートするには?

enter image description here

+0

から取られますが任意のソリューションをしようと試みたことがありますか? – adalPaRi

+0

@adalPaRi - 私はgroovyに慣れていませんが、VBスクリプトを知っています。私は石鹸応答に付属するpdfファイルを抽出する機能を見つけることができませんでした。しかし、私はgroovyを使ってテキストファイルにレスポンスを保存することができます。 – Rish

答えて

0

次のスクリプトは、ファイルに添付ファイルを保存することができるはずです。

次のスクリプトを現在の要求ステップにScript Assertionとして追加します。適切なコメントをインラインで探します。スクリプトの

ソースはhere

/** 
* Below script assertion will check 
* if the response is not null 
* there is an attachment 
* and saves file to the specified location, by default saves into system temp 
* directory 
**/ 
//change file name as needed 
def fileName = System.getProperty('java.io.tmpdir')+'/test.pdf' 

//Get the response and check if the response is not null 
def response = messageExchange.response 
assert null != response, "response is null" 

//Create output stream 
def outFile = new FileOutputStream(new File(fileName)) 

//Check if there is one attachment in the response 
assert 1 == messageExchange.responseAttachments.length, "Response attachments count not matching" 
def ins = messageExchange.responseAttachments[0]?.inputStream 
if (ins) { 
    //Save to file 
    com.eviware.soapui.support.Tools.writeAll(outFile, ins) 
} 
ins.close() 
outFile.close() 
+0

スクリプトを共有してくれてありがとう!!私は "いいえ、そのようなプロパティ:クラスのresponseAttachment:.."としてエラーを取得しています – Rish

+0

Stacktraceしてください?あなたに提供されたスクリプトには 'responseAttachment'ではなく' messageExchange.responseAttachments'があります。添付ファイルリストですので、 's'はありますが、あなたが指しているのはシングルです。あなたはそのまま使用しましたか?または変更?答えは、他のタイプのファイルのテスト済みのサンプルだったので、この場合は問題はありません。 – Rao

+0

はうまく動作します。 – Rish

関連する問題