2

我已经创建了 Web 服务项目。以下是我的测试用例的脚本,它验证文档中显示的元素文本

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

def response = WS.sendRequest(findTestObject('ProductById'))
WS.verifyElementText(response, "Product.Reference", "MyReference")

当我运行这个测试用例时,我收到了错误:[FAILED] - Unable to verify element text (Root cause: org.xml.sax.SAXParseException: Content is not allowed in prolog.)

然后我用:com.kms.katalon.core.util.KeywordUtil#logInfo来查看response.responseText我收到的,这是:

--uuid:4e39ea48-6560-46b7-a30c-201dfaf98f51
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:getProductResponse xmlns:ns2="http://mycompany.com/"><Product><Reference>VW3A8306R</Reference></Product></ns2:getProductResponse></soap:Body></soap:Envelope>
--uuid:4e39ea48-6560-46b7-a30c-201dfaf98f51--

我正在测试的 Web 服务已MTOM启用。这就是响应文本采用这种格式的原因。

在这种情况下如何创建测试用例?

4

1 回答 1

3

您可以拆分内容,然后继续处理。以下是 Katalon Studio 脚本,可在这种情况下为您提供帮助:

   import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
   import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

   def response = WS.sendRequest(findTestObject('ProductById'))
   response.responseText = (response.responseText =~ '<soap:Envelope.*
   </soap:Envelope>')[0]
   WS.verifyElementText(response, "getProductResponse.Product.Reference", 
   "MyPreference")
于 2017-08-02T07:43:43.137 回答