WS.verifyElementsCount - wrong count


Hi, everyone!

I have test-case of REST web-service where i try to count the number of templates(using WS.verifyElementsCount).
REST reponse is in XML:

<ArrayOfTemplate xmlns:xsd="" xmlns:xsi="">
    <end_date xsi:nil="true" />

Code of test-case:

'Отправка валидного запроса'
a = WS.sendRequest(findTestObject('DocFlow_WebServices/GetTemplates', [('Category_Code') : 'PaymentContract_Test', ('boolean') : true]))
'Проверка количества шаблонов(2)'
WS.verifyElementsCount(a, 'template', 2)

Failures text:

Test Cases/Test_WebServices/Test_GetTemplates FAILED because (of) (Stack trace: com.kms.katalon.core.exception.StepFailedException: Unable to verify element count (Root cause: Expected elements count 2 is not equal with actual count 1)

What is wrong?


Does anybody face with this problem?


Hi @evgeny_solodukhin,
I’ve just addressed this issue to Katalon team and I’ll inform you as soon as it gets fixed.


I tried to reproduce your problem.

I wrote a line in my testcase as this:

WS.verifyElementsCount(response, '//template', 2)

I guessed that the 2nd argument should be a valid XPath expression, so I wrote //template.

I ran the test case and got error. The message was a interesting one.

com.kms.katalon.core.exception.StepFailedException: Unable to verify element count (Root cause: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: unexpected token: def @ line 1, column 1.
    def //template = new XmlSlurper().parseText(xmlText); return //

1 error

I would interpret this as follows:

The line in test case

WS.verifyElementsCount(response, 'template', 2)

will be transformed by Katalon Studio into the following Groovy code:

def template = new XmlSlurper().parseText(xmlText); return template.size()

return template.size() will always return 1 : the number of XML root element <ArrayOfTemplate>.

My conclusion

WS.verifyElementsCount() is poor.

I looked at the documentation and found the specification of WS.veryElementsCount() is totally ambiguous. The document does not tell me how the locator param should be written (syntax) and what value the method should return (semantics).

I expect the keyword is able to process both of XML and JSON response. But obviously a locator for XML and a locator for JSON can not be the same. The locator parameter should be an expression of some Path-language: XPath for XML, JMESPath or JSONPath for JSON.

As the specification does NOT specifies how the keyword should be, the current implementation is just useless.


In fact, we do not need WS.verifyElementsCount() to count the number of <template> element in the target XML document. In a test case, we can use javax.xml.xpath.XPath which is built-in the standard Java8 runtime.