soapUI(groovy指令碼作用1)請不要問為什麼系列1

來源:互聯網
上載者:User

SoapUI在測試WebService訊息時,在構造用例過程中部分請求參數可能需要通過查詢資料庫或者通過隨機數擷取,此時可以藉助Groovy指令碼完成此功能,具體步驟如下:

(1)從TestCase中擷取請求訊息

def request = testRunner.testCase.getTestStepByName( "TestStep名稱" );

def property = request.getProperty( "request" );

log.info(property.value)

(2)將請求訊息轉換為String,並通過XmlParser對其進行修改

def balanceQueryParser = new groovy.util.XmlParser(false,false).parseText(property.value);

//擷取需要修改的Node節點,每個節點都需要指定首碼限定,通過此種方式擷取的節點為NodeList,所以需要加上[0]
def transactionid =
balanceQueryParser["soapenv:Body"]["uvs:balanceQuery"]["uvs:BalanceQueryRequest"]["uvs:RequestMessage"]["uvs:MessageHeader"]["uvs:TransactionId"][0];

//通過Node.setValue方法可以對請求參數進行修改
transactionid.setValue(System.currentTimeMillis())

(3)將請求訊息寫回到TestStep中
def writer = new java.io.StringWriter();
def printer = new groovy.util.XmlNodePrinter( new PrintWriter(
writer ));
printer.print( balanceQueryParser );
property.setValue( writer.toString() )
log.info(property.value)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.