我创建了Web服务项目。以下是我的测试用例的脚本,它验证了documentation:
中显示的元素文本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--
我正在测试MTOM
的Web服务已启用。这就是响应文本是那种格式的原因。
在这种情况下如何创建测试用例?
答案 0 :(得分: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")