[Question] What's the correct usage of setTestIdAttribute?
See original GitHub issueHi, team.
I have a custom test id attribute and I don’t understand the right place to set it (where to call selectors.setTestIdAttribute). I tried to do it in global-setup script, but alas. I don’t really want to wrap getByTestId function and set the test id before it, but that’s the only way I see right now.
It would be nice:
- add configuration parameter for custom test id;
- update the docs and provide more examples.
Related articles: https://playwright.dev/docs/api/class-locator#locator-get-by-test-id https://playwright.dev/docs/api/class-selectors#selectors-set-test-id-attribute
Thanks in advance!
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
What is the data-testid attribute in testing? - Educative.io
data-testid is an attribute used to identify a DOM node for testing purposes. It should be used as a handler to the test...
Read more >[testing] add data-testid attribute to all components #1001
This attribute would be used in place of class or id selectors in testing automation for applications that consume this library. For exported, ......
Read more >ByTestId - Testing Library
ByTestId functions in DOM Testing Library use the attribute data-testid by default, following the precedent set by React Native Web which ...
Read more >Question about using data-testid attribute for unit testing - Reddit
If you use data-testid, your test will fail if you remove that testid. Did the behaviour of the component change if you just...
Read more >How to add data-testid attribute to react-select components
Ordinarily, the react-testing-library way to do this is to add a 'data-testid' attribute to the item in question. I've found that it's possible ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ll update the docs…
I think docs should be updated on following page too.
Edit: Maybe similarly here: