[英]How to pass over an XML string to a sub API-test in UFT/QTP?
作為一個簡單的例子,在API測試流程中,我使用了另一個API測試模塊,必須將XML字符串(消息)傳遞給該模塊。 但是,一旦子模塊獲得了XML字符串,它就會在xml標記之前引發有關空白的運行錯誤步驟! 我什至在進入子模塊之前就用自定義代碼修剪輸入字符串,但得到相同的錯誤!
錯誤信息:“意外的XML聲明XML聲明必須是文件中的第一個節點,也沒有空格字符被允許在它之前出現。”
任何提示,請提前感激:)
事情就是這樣,UFT API將參數作為XML結構處理。 由於參數值也是XML結構,因此應將其作為文本(轉義)而不是XML傳遞。 因此,代替此:
<?xml version="1.0" encoding="UTF-8"?><shiporder orderid="889923" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="shiporder.xsd"><orderperson>John Smith</orderperson><shipto><name>Ola Nordmann</name><address>Langgt 23</address><city>4000 Stavanger</city><country>Norway</country></shipto><item><title>Empire Burlesque</title><note>Special Edition</note><quantity>1</quantity><price>10.90</price></item><item><title>Hide your heart</title><quantity>1</quantity><price>9.90</price></item></shiporder>
您應該通過此:
<?xml version="1.0" encoding="UTF-8"?><shiporder orderid="889923" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="shiporder.xsd"><orderperson>John Smith</orderperson><shipto><name>Ola Nordmann</name><address>Langgt 23</address><city>4000 Stavanger</city><country>Norway</country></shipto><item><title>Empire Burlesque</title><note>Special Edition</note><quantity>1</quantity><price>10.90</price></item><item><title>Hide your heart</title><quantity>1</quantity><price>9.90</price></item></shiporder>
在這里,您可以找到一個在線工具,可以幫助您轉義XML: http : //www.freeformatter.com/xml-escape.html
編輯:
解決此問題的一種動態方法是在執行調用API測試的步驟之前,在參數中包含自動轉義XML值的代碼。 例:
public void CallSTTest4_OnBeforeExecuteStepEvent(object sender, STActivityBaseEventArgs args)
{
CallSTTest4.InputProperties.GetElementsByTagName("XMLString").Item(0).InnerXml = System.Security.SecurityElement.Escape(CallSTTest4.InputProperties.GetElementsByTagName("XMLString").Item(0).InnerXml);
}
注意:就我而言,包含xml結構的輸入參數是“ XMLString”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.