Assert Text task | Zoho QEngine Help

Assert Text task

In a nutshell

The Assert Text task verifies that the visible text content of a web element exactly matches the expected value. The comparison is case-sensitive, so differences in capitalization will cause the assertion to fail. This confirms that the application is displaying the correct information, such as a record count, status, or field value, instead of assuming a previous step completed successfully.

1. Overview

The Assert Text task verifies that a specific web page element displays the expected visible text. It locates the target UI element, retrieves its rendered text, and compares it against an expected value.

This task is commonly used to validate scenarios such as confirming a success message after a form submission, verifying that a page heading matches a search term, or ensuring a total updates correctly after a discount is applied.

The task also includes configurable error handling, determining how the test responds if the text does not match. The test can either stop execution immediately or log the mismatch and continue running. Optionally, the result of the validation can be stored in a variable, enabling subsequent test steps to evaluate and act on the outcome.

NotesNote: Assert Text compares only the element's visible text, not hidden text, attributes, or the underlying HTML content, and it doesn't validate that the element is visible on the page as its own outcome. Use Assert Visible instead to confirm an element is present and displayed to the user. 

2. Syntax

assertText(<locator>, <text>, <errorHandling>);

(or)
<variable> = assertText(<locator>, <text>, <errorHandling>);

ParameterData TypeDescription
locatorSTRINGIdentifies the element that should contain the expected text.
NotesNote: You can find a locator by manually inspecting the webpage for the element, or by using an element already saved through a recording session. Learn more about Elements.
textSTRINGText expected to be found in the element.
errorHandlingSTRING

Determines how the test behaves if the text doesn't match:

  1. errorhandling.STOP_ON_ERROR - Stops the test case if the text doesn't match.
  2. errorhandling.CONTINUE_ON_ERROR - Records the result and continues running the test case regardless of a mismatch.

Return Type: Boolean

3. Examples

Example 1: Confirming the homepage banner text

This script verifies the tagline on the ZWatch Commerce homepage against its expected text.

// Open the ZWatch Commerce home page using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// <Wait> for the homepage banner to become visible
wait(10, ".theme-banner-heading", event.SHOW);
// Confirm the homepage banner shows the expected tagline
assertText(".theme-banner-heading", "Live Inspired", errorhandling.STOP_ON_ERROR);

where:

"https://zwatch.zohocommerce.com/"ZWatch Commerce home page URL.
"same window"Opens the page in the window already running the test.
10Maximum time to wait for the banner to become visible, in seconds.
.theme-banner-headingLocator for the homepage banner heading.
event.SHOWWaits until the banner becomes visible.
"Live Inspired"Expected tagline text.
errorhandling.STOP_ON_ERRORStops the test if the tagline doesn't match.

Example 2: Verifying the contact page title

This script clicks the Contact link from the home page and confirms the page title matches the Contact page, verifying that navigation landed on the intended page rather than an unexpected one.

// Open the ZWatch Commerce home page using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Click the Contact link using the Click task
click("a[href='/contact']");
// Confirm the page title matches the expected value
assertText("title", "Contact | Watch Shopping", errorhandling.STOP_ON_ERROR);

where:

"https://zwatch.zohocommerce.com/contact"ZWatch Commerce home page URL.
"same window"Opens the page in the window already running the test.
"a[href='/contact']"Locator for the Contact link on the home page.
titleLocator for the page's title element.
"Contact | Watch Shopping"Expected page title text.
errorhandling.STOP_ON_ERRORStops the test if the title doesn't match.

Example 3: Checking a required-field error message

This script attempts to submit the signup form with the email field left blank and confirms the inline error message appears beneath the field.

// Open the signup page using the Open URL task
openURL("https://www.<website_name>.com/<signup_page>", "same window");
// Attempt to submit the form without entering an email, using the Click task
click(ui.<signup_page>.<submit_button>);
// Confirm the inline "Email is required" error appears beneath the email field
assertText(ui.<signup_page>.<email_required_error>, "Email is required", errorhandling.CONTINUE_ON_ERROR);

where:

"https://www.<website_name>.com/<signup_page>"Signup page URL.
"same window"Opens the page in the window already running the test.
ui.<signup_page>.<submit_button>Locator for the submit button.
ui.<signup_page>.<email_required_error>Locator for the error message element.
"Email is required"Expected inline error message text.
errorhandling.CONTINUE_ON_ERRORContinues the test and returns the result instead of stopping if the message doesn't match.

Example 4: Confirming a registration count in an Event registration application

This script confirms the registration count on an event dashboard, built on Zoho Creator, increases by one after a new registration is submitted through the Event Registration form.

// Step 1: Open the event dashboard page in the Event Manager application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/event-manager#Page:Event_Details", "same window");
// Step 2: Confirm the registration count currently reads 41 registered
assertText(ui.eventmanager.registration-count, "41 registered", errorhandling.STOP_ON_ERROR);
// Step 3: Open the Event Registration form using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/event-manager#Form:Event_Registration", "same window");
// Step 4: Enter the registrant's name using the Set Value task
setValue(ui.eventmanager.registrant-name-field, "Jordan Lee");
// Step 5: Enter the registrant's email using the Set Value task
setValue(ui.eventmanager.registrant-email-field, "jordan.lee@example.com");
// Step 6: Submit the registration using the Click task
click(ui.eventmanager.submit-button);
// Step 7: Open the event dashboard page again using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/event-manager#Page:Event_Details", "same window");
// Step 8: Confirm the registration count reflects the new signup
assertText(ui.eventmanager.registration-count, "42 registered", errorhandling.STOP_ON_ERROR);

where:

"https://creatorapp.zoho.com/<orgname>/event-manager#Page:Event_Details"Event dashboard page URL.
"same window"Opens the page in the window already running the test.
"41 registered"Registration count before the new signup.
"https://creatorapp.zoho.com/<orgname>/event-manager#Form:Event_Registration"Event Registration form URL.
ui.eventmanager.registrant-name-fieldLocator for the registrant's name field.
"Jordan Lee"Name entered for the new registrant.
ui.eventmanager.registrant-email-fieldLocator for the registrant's email field.
"jordan.lee@example.com"Email entered for the new registrant.
ui.eventmanager.submit-buttonLocator for the form's submit control.
"42 registered"Expected registration count text.
errorhandling.STOP_ON_ERRORStops the test if the count doesn't match.

4. Use cases

Scenario 1: Confirming a search returns relevant results

Shoppers searching for a specific watch model expect the results heading to reflect what they searched for, not a generic or stale label.

A tester uses Zoho QEngine to confirm that performing a product search updates the results heading to display the entered search term. If this validation failed, shoppers may view irrelevant search results without realizing the search itself hadn't worked correctly.


Steps

  1. Open the home page in the same window.
  2. Search for a product.
  3. Confirm the results heading reflects the search term.

Implementation

// Step 1: Open the ZWatch Commerce home page in the same window using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Step 2: Click the search icon to reveal the search input using the Click task
click(".theme-search");
// Step 3: Enter a search term using the Set Value task
setValue("[data-search-input]", "Chrono 44");
// Step 4: Submit the search using the Send Keys task
sendKeys("[data-search-input]", [keys.ENTER]);
// Step 5: Confirm the results heading reflects the search term using the Assert Text task
assertText(".search-results-heading", "Results for Chrono 44", errorhandling.STOP_ON_ERROR);

Scenario 2: Verifying an inline validation message while typing

Some signup forms validate a password field as the customer types, showing an inline hint if the password doesn't meet requirements, rather than waiting until submission.

A tester uses Zoho QEngine to confirm that entering a weak password causes the inline hint to appear with the correct message. If this validation failed, customers could submit a weak password with no warning until the form rejects it later.

Steps

  1. Open the signup page in the same window.
  2. Enter a weak password.
  3. Confirm the inline validation message appears.

Implementation

// Step 1: Open the signup page in the same window using the Open URL task
openURL("https://www.<website_name>.com/<page_name>", "same window");
// Step 2: Enter a weak password using the Set Value task
setValue(ui.<page_name>.<element_name>, "12345");
// Step 3: Confirm the inline validation message appears using the Assert Text task
assertText(ui.<page_name>.<element_name>, "Password is too weak", errorhandling.STOP_ON_ERROR);

Scenario 3: Confirming a waitlist message once event capacity is reached

Consider an organization that uses a Zoho Creator Event Management application to manage event registrations. The Event Registration form has its Restrict Form Entries property configured with a maximum entry limit and a custom message, "Registration is closed," to display once that limit is reached. For testing, this limit is set to 1 entry so the closed-registration condition can be reproduced without needing real event capacity data. Once the limit is hit, the form becomes inaccessible, showing the closed-registration message in place of the form fields, so no one can submit a registration for an event that's already full.

A tester uses Zoho QEngine to confirm that submitting one registration to reach the configured limit causes the form to show the closed-registration message instead of its fields on the next visit. If this validation failed, a registrant could still access the form and submit for an event that's already full.

Steps

  1. Open the Event Registration form in the Event Manager application.
  2. Submit a registration to reach the configured entry limit (set to 1 for testing).
  3. Open the Event Registration form again.
  4. Confirm the closed-registration message appears instead of the form.

Implementation

// Step 1: Open the Event Registration form in the Event Manager application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/event-manager#Form:Event_Registration", "same window");
// Step 2: Submit a registration to reach the configured entry limit using the Click task
click(ui.eventmanager.register-button);
// Step 3: Open the Event Registration form again using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/event-manager#Form:Event_Registration", "same window");
// Step 4: Confirm the closed-registration message appears instead of the form using the Assert Text task
assertText(ui.eventmanager.restricted-access-message, "Registration is closed", errorhandling.STOP_ON_ERROR);

5. Points to note

  1. Assert Text checks for an exact text match. A partial or case-mismatched string returns a failed assertion.
  2. Use Assert Visible instead of Assert Text when confirming that an element is present, but its exact text doesn't matter.
  3. Whitespace or line breaks in the DOM can cause a mismatch even when the text looks identical on screen. Store the result in a variable to inspect and identify any extra whitespace before determining how the test should proceed.
  4. When locating the element, favor logical or recorded locators over raw full XPath strings.

6. Related topics

  1. Set Value
  2. Assert Value
  3. Assertion tasks

7. What's next

Next step
Previous step
Next step

Now that you've used the Assert Text task to confirm text on a page, learn how to verify an input's value using the Assert Value task.


Previous step

Before using the Assert Text task, ensure that you've learned how to enter a value into a field using the Set Value task.