question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] What's the correct usage of setTestIdAttribute?

See original GitHub issue

Hi, 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
pavelfeldmancommented, Oct 20, 2022
        use: {
          testIdAttribute: 'data-pw',
        }

I’ll update the docs…

1reaction
sagrawal-codecommented, Oct 28, 2022

I think docs should be updated on following page too.

Edit: Maybe similarly here:

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found