Skip to content

(webdriverio): Add case insensitive text match feature #4951#11358

Merged
christian-bromann merged 4 commits intowebdriverio:mainfrom
AnthonyQuy:main
Oct 9, 2023
Merged

(webdriverio): Add case insensitive text match feature #4951#11358
christian-bromann merged 4 commits intowebdriverio:mainfrom
AnthonyQuy:main

Conversation

@AnthonyQuy
Copy link
Contributor

@AnthonyQuy AnthonyQuy commented Oct 6, 2023

Proposed changes

Add case insensitive text match feature #4951

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Further comments

Reviewers: @webdriverio/project-committers

@erwinheitzman
Copy link
Member

erwinheitzman commented Oct 6, 2023

Awesome work @AnthonyQuy 👍

It would be nice to add a function that lowercases text and then uppercases every other character so that we can use the same string for two different assertions and it keeps the rest easy to understand.

So something like:

const alternateCase = str => str.forEach(i => i % 2 == 0 ? i.toUpperCase() : i.toLowerCase())

alternateCase('example text') // outputs: eXaMpLe tExT

EDIT: actually after checking more individual testcases I feel this is a nice idea but the texts are a bit too specific to do this so you can ignore this suggestion and I'll resolve it

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good, thanks for picking it up 👍

Mind adding/updating the documentation on that in https://github.com/webdriverio/webdriverio/blob/main/website/docs/Selectors.md ?

@AnthonyQuy
Copy link
Contributor Author

Change looks good, thanks for picking it up 👍

Mind adding/updating the documentation on that in https://github.com/webdriverio/webdriverio/blob/main/website/docs/Selectors.md ?

@christian-bromann Seem the document page is using a sample project. I think we can merge this PR then update the sample project after new version release

@christian-bromann
Copy link
Member

@AnthonyQuy merged pr on example recipes, please go ahead.

@christian-bromann christian-bromann added the PR: New Feature 🚀 PRs that contain new features label Oct 9, 2023
@AnthonyQuy
Copy link
Contributor Author

Thanks @christian-bromann updated the Selectors.md

@AnthonyQuy
Copy link
Contributor Author

image

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use "we".

The rest looks good to me. Great work 👍

@AnthonyQuy
Copy link
Contributor Author

Agreed. Thank you!!

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think the code examples aren't properly updated, can you set it to:

Or using query partial text:

```js reference useHTTPS
https://github.com/webdriverio/example-recipes/blob/13eddfac6f18a2a4812cc09ed7aa5e468f392060/selectors/example.js#L44C9-L47
```

The same works for `id` and `class` names:

```html reference
https://github.com/webdriverio/example-recipes/blob/e8b147e88e7a38351b0918b4f7efbd9ae292201d/selectors/example.html#L4
```

You can query this element by calling:

```js reference useHTTPS
https://github.com/webdriverio/example-recipes/blob/13eddfac6f18a2a4812cc09ed7aa5e468f392060/selectors/example.js#L49-L67
```

@christian-bromann
Copy link
Member

So it looks more like this:

Screenshot 2023-10-08 at 9 54 34 PM

@AnthonyQuy
Copy link
Contributor Author

Yes you're right! Sorry I overlooked the page. Created a update commit

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@christian-bromann christian-bromann merged commit a687065 into webdriverio:main Oct 9, 2023
@bhanuagarwal73
Copy link
Contributor

Hey Team,

1 doubt:

What if someone want's to check the exact text ??
Just suggestion --> better add toHaveTextIgnoreCase(bla bla...)

@christian-bromann
Copy link
Member

What if someone want's to check the exact text ??

await expect($('div=some exact text')).toHaveText('some exact text') will do that!

@bhanuagarwal73
Copy link
Contributor

How can it be achievable with xpath?
With traditional translate only???
Let say
except($("//div[@Class = 'xyz']").toHaveText(some text)

@christian-bromann
Copy link
Member

except($("//div[@Class = 'xyz']").toHaveText(some text)

Exactly like that. Join our Discord server if you have further questions. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: New Feature 🚀 PRs that contain new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants