Skip to main content

[WS] Verify Element Text

Description

Verify an element with expected text appeared in the returned data from a web service call.

Keyword name: WS.verifyElementText

Parameters

ParameterParameter TypeMandatoryDescription
responseResponseObjectRequiredThe object that represents an HTTP response.
locatorStringRequiredThe element locator that Katalon uses to look for the expected data. To learn more about element locators, you can refer to this document: Handle Response messages.
textStringRequiredThe expected text of element you want to verify in the responded data (usually JSON/XML)
flowControlFailureHandlingOptionalSpecify failure handling schema to determine whether the execution should be allowed to continue or stop. To learn more about failure handling settings, you can refer to this document: Failure handling.

Returns

  • true, if your element text is found, otherwise; false.

Example

Given the following sample SOAP_TransactionResult SOAP object:

<?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>

We want to verify the TransactionResult element in the SOAP response after sending the request. We use the WS.verifyElementText() keyword as below:

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 com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords 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('SOAP_TransactionResult'))

'Verify the selected element in the response'
WS.verifyElementText(response, 'PreAuthorizeResponse.Receipt.TransactionResult', 'Approved')
Note:

Katalon checks if the XML element content text is strictly equal to the expected value. For example, if there is whitespace after the Approved value, you need to add it to the third argument as follows:

  • Katalon checks if the XML element content text is strictly equal to the expected value. For example, if there is whitespace after the Approved value, you need to add it to the third argument as below:

    groovy WS.verifyElementText(response, 'PreAuthorizeResponse.Receipt.TransactionResult', 'Approved  ')
WS.verifyElementText(response, 'PreAuthorizeResponse.Receipt.TransactionResult', 'Approved ')

See also