I hope Katalon Team to spare time to improve the official document of WS.verifyElementText
I tried 8.2.0beta. I confirmed that
WS.verifyElementText() works for a SOAP response with Header element.
I would remind you of an outstanding issue.
Provided that the response SOAP XML is like this:
<?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> <env:Body> <ns:PreAuthorizeResponse xmlns:ns="beep" xmlns:ns2="bop" xmlns:ns1="foo" > <ns:Receipt> <ns1:DataKey>123</ns1:DataKey> <ns1:CustomerId>12345</ns1:CustomerId> <ns1:PaymentId>123456 </ns1:PaymentId> <ns1:TransactionResult>Approved </ns1:TransactionResult> ...
I tried the following test:
WS.verifyElementText(response, 'PreAuthorizeResponse.Receipt.TransactionResult', 'Approved')
This failed as follows:
2021-10-08 18:36:01.105 ERROR c.k.k.core.keyword.internal.KeywordMain - ❌ Expected text is 'Approved' but actual element text is: Approved 2021-10-08 18:36:01.122 ERROR c.k.k.core.keyword.internal.KeywordMain - ❌ Unable to verify element text (Root cause: com.kms.katalon.core.exception.StepFailedException: Expected text is 'Approved' but actual element text is: Approved at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:50) ...
I amended the test script as follows:
WS.verifyElementText(response, 'PreAuthorizeResponse.Receipt.TransactionResult', '''Approved ''')
Please note that the 3rd argument
contains a NEWLINE character plus 8 whitespaces.
The amended test script passed.
This example shows that the
WS.verifyElementText() keyword is difficult to use. It checks if the XML element content text is strictly equal to the 3rd argument string. Any NEWLINEs and whitespace characters easily break the equality test. Unfortunately the keyword offers no way to make the verification tolerant of whitespaces.
The official documentation explains nothing about the strictness for whitespaces. I am afraid that many people would get stuck with it.
Therefore I would still argue, users should not rely on this keyword. They should rather parse the XML in the Web Service Response themselves to look up elements of their interest while trimming (or ignoring) whitespaces in the content text as appropriate.
Yes, sure @kazurayam.
Thanks for your suggestion.
I would like to suggest a code change:
boolean isEqual = (text.equals(String.valueOf(retValue)))
I would propose to change this to:
boolean found = String.valueOf(retValue).contains(text.trim())
This change would not break existing scripts of users.
And the keyword
WebUI.verifyElementText() will become tolerant for whitespaces in the response body.
The current official document writes:
- true , if your element text is found, otherwise; false .
This description is ambiguous enough. The aforementioned change would not break the doc.
We will verify the solution and apply it if it works perfectly.
Really appreciate your idea!