Skip to content

[Documentation] Incorrect example in containsText assertion documentation #38823

@Z-Ning0

Description

@Z-Ning0

Page(s)

https://playwright.dev/java/docs/next/api/class-locatorassertions#locator-assertions-to-contain-text

Description

The example in the 'containsText' assertion documention appers to be incorrect.

Current Documentation

For the HTML:
<ul>
<li>Item Text 1</li>
<li>Item Text 2</li>
<li>Item Text 3</li>
</ul>
The documentation shows:
// Contains the right items in the right order
assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});

Expected Behavior

The example should fail because:

  • The third element in the array ("Text 4") does not exist in any of the list items
  • The second list item contains "Item Text 2", not "Text 3"

Therefore, this should not be labeled as "Contains the right items in the right order"

Suggested Fix

Either correct the example or clarify the intended behavior of the array matching algorithm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions