The text of element is different from expectation
  • 29 Aug 2024
  • 5 Minutes to read
  • Contributors
  • Dark
    Light

The text of element is different from expectation

  • Dark
    Light

Article summary

If the text of a target element differs from the expected value in a text assertion step, the following message will appear in the test result.
Text_of_the_element_is_different_from_expectation_EN.png

In this article, we will look at common examples and fixes. First, look at the screenshot of the failed step and see which of the following applies:

  1. In one of the steps before the failed step, the screenshot of the current test run is different from when the scenario was recorded or the last successful test run (The expected action was not performed).
  2. There are no issues in any of the steps before the failed step, but the target element is not found in the failed step, or the target element was found but the step failed.

1. An unintended action is performed in a step before the failed step

Please check the steps before the failed one and see whether an incorrect element has been clicked or whether a validation error occurred when entering values in a form. If so, please edit the step so that the correct action can be performed.

Let's look at an example where an error occurred in step 5:
Text_of_the_element_is_different_from_expectation_D_EN.png

First, click [Check screenshot] to see what it looked like when step 5 was executed.

Text_of_the_element_is_different_from_expectation_D_step5_JPEN.png

We can see that the text that this step is validating is different from the last successful test run, and it doesn't match the expected value.
Next, we'll check the steps before step 5 to see if an unintended action has been performed.
Text_of_the_element_is_different_from_expectation_D_step4_JPEN.png

In step 4, "English" should have been clicked, but for some reason, "Japanese" was clicked instead. As a result, the page didn't change to English and step 5 failed.

To fix this, instead of focusing our attention on step 5, we need to figure out why an unintended action was performed in step 4 (clicking the wrong element). In this example, Autify AI may have targeted the wrong element. Using Quick Element Update or re-recording would solve the issue.
If necessary, please refer to this page: Element not found. You may find the section "If the target element does not exist on the page" helpful.

2. The target element is not found in the failed step, or the target element was found but the step failed

2-1. The step failed even though the target element looks fine in the screenshot

In this error message, we can see that the actual value is blank (no value):
Text_of_the_element_is_different_from_expectation_E_EN.png

Click [Check screenshot] to see what the page looks like in step 2:

Text_of_the_element_is_different_from_expectation_E_step2_JPEN.png

Looking at the screenshots, it looks like the element was found, and the page doesn't seem to have any issues.
In this case, the target element may be a non-text element (e.g., an image element). Since text assertions are for validating text, you can't use this assertion command to validate non-text elements.
Please consider Visual regression testing for elements or Assertions on elements in a page.

2-2. There is a line break in the target element in the difference comparison section of the error message

Looking at the details of the error message below, it looks like there are no differences between the expected and actual values in step 12:

Text_of_the_element_is_different_from_expectation_B_EN_2.png

Next, let's check the Scenario Details page. We can see that step 12 is validating the value entered in step 11, and the text in step 11 and step 12 seems the same.
Looking at the details in step 11, the given value includes line breaks*.
*In the "Text to assign" section, line breaks you add by pressing Enter won't be displayed. However, if you look at the step details on the Scenario Details page as shown in the image below, you can see that line breaks are expressed as a symbol (↵).

Text_of_the_element_is_different_from_expectation_B_EN_7_1.png

Meanwhile, the expected value given in step 12 is different from the text entered in step 11 because a line break is specified using the line break symbol (↵).

Text_of_the_element_is_different_from_expectation_B_EN_8_1.png

In this case, the line breaks in the expected value of step 12 must be added by pressing Enter.

Text_of_the_element_is_different_from_expectation_B_EN_9_1.png

On the Test Results and the Scenario Details pages, line breaks are indicated by the line break symbol (↵). However, if you want to include line breaks as an expected value, press Enter instead of using the line break symbol.

Additional information

How line breaks are treated may differ depending on the browser in which the test is run.
For example, on Firefox, the step will fail if the expected value has a line break. However, the step will pass on other browsers.

2-3. The element value is a date/time

Take a look at the error message below. The test has failed at a step that validates a date.
Text_of_the_element_is_different_from_expectation_C_EN.png

If the failed step is one that compares date/time, it may be because your workspace's test execution environment time zone do not match the expected timezone.

Please consider the following:

  • If the expected value assumes UTC, make sure that your test execution environment timezone is not JST
  • If the expected value assumes JST (Japan time), make sure to set your test execution environment timezone to JST

Screenshot 2024-08-26 at 17.49.05.png

2-4. The target element exists in the screenshot but Autify is targeting a different element

In the example below, we can see that Autify is validating the same element as when the scenario was recorded (last successful test run).
However, what we actually wanted to validate was the date/time of the item on the top row.

Text_of_the_element_is_different_from_expectation_A_EN.png

To ensure that Autify reliably targets the correct element, please use a locator. This will allow you to specify the top/Nth/bottom element.
For detailed instructions, see How do I interact with the elements in a table or list the way I intended?.

Other than the examples described above, if you think Autify is targeting the wrong element, please read Target element not found. The section "If the target element exists on the page but was not found" may be helpful.

2-5. The wrong email is opened in an email test step

Look at the subject line in the following example. The email that is opened is different from the one that was opened when the scenario was recorded.
Text_of_the_element_is_different_from_expectation_mail_EN.png

One possible cause of this is that another email was opened before the target email was received, and the assertion was made against the wrong email.
If you think that Autify executed the email test step before the email is received, please add a Sleep step.
You may be able to resolve the issue by waiting for the email to be received.

If the email is not received, or for more information on the specifics of how Autify searches for emails, please see Email Testing Feature. The sections "If no email is received" and "Specifications for searching for emails to be verified" may be helpful.

If you are still having trouble...

Please contact us. We will work with you to resolve the issue.


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.