Skip to content

[Feature Request] withText() case-insensitive option #2704

Closed
@stordopoulos

Description

@stordopoulos

What are you trying to achieve?

Currently, the withText() method identifies only case sensitive text. That works for many cases but can also be a source of instability. By definition, withText() searches for elements that contain a specific sub-string. If said sub-string moves within the same sentence, then it's very likely for it to change all lowercase to the first character being a capital letter - which will break the tests.

In my humble opinion, a preferred solution would be the addition of a separate method, like Test Library's getByText(). Here's a link to an example of getByText():

// Matching a string:
getByText('Hello World') // full string match
getByText('llo Worl', { exact: false }) // substring match
getByText('hello world', { exact: false }) // ignore case

// Matching a regex:
getByText(/World/) // substring match
getByText(/world/i) // substring match, ignore case
getByText(/^hello world$/i) // full string match, ignore case
getByText(/Hello W?oRlD/i) // advanced regex

// Matching with a custom function:
getByText((content, element) => content.startsWith('Hello'))

What do you get instead?

The withText() method identifies only case sensitive text.

Details

  • CodeceptJS version: v3.0.2
  • NodeJS Version: v14.8.0
  • Operating System: MacOS 10.15.4
  • playwright

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