Skip to main content

[WS] Verify Elements Count


Verify the number of expected elements (JSON/XML) in the response (output) of a web service call.

Keyword name: WS.verifyElementsCount


ParamParam TypeMandatoryDescription
responseResponseObjectRequiredThe object that represents an HTTP response.
locatorStringRequiredAn expression Katalon will use to go through and look for the expected element(s). You can refer to this guide: Handle Web Service Response object. The syntax for locator is GPath. To learn more about GPath, see this guide.
countintRequiredThe expected number of element(s) should appear in the responded data (usually JSON/XML)
flowControlFailureHandlingOptionalSpecify failure handling schema to determine whether the execution should be allowed to continue or stop.


  • true, if your expectation is met, otherwise false.


You want to verify number of expected elements in the response is 3

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.testobject.RequestObject as RequestObject
import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WebAPI
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import as Mobile
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

'Send a SOAP request and returns its response'
def response = WS.sendRequest(findTestObject('REST_EmployeeInfo'))

'Verify number of expected employee contact records'
WS.verifyElementsCount(response, 'employee.contacts', 3)