Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2] Is data-test-id a good idea? #202

Open
ziofat opened this issue Apr 28, 2022 · 0 comments
Open

[3.2] Is data-test-id a good idea? #202

ziofat opened this issue Apr 28, 2022 · 0 comments

Comments

@ziofat
Copy link

ziofat commented Apr 28, 2022

I have seen this in cypress's documents that suggest to use data-test-id attribute to locate specific element. This can make test more stronger that survive changes like html structures and css names. However, in practice we found it is hard to avoid name conflicts in big project, and a lot of 3rd party ui components cannot add this attribute.

What we do is to use user aware information to locate element. In my opinion, if the feature requirement has changed, then the tests should change as well. For e2e testing, using data-test-id violates the principle 1.4 "Stick to black-box testing".

So we use text to locate elements. If the element has no text, like icon button, as far as it is Interactable, it should have some a11y information for visual disability users. And our test framework is another user with such disability. Therefore, aria attributes are used to locate almost every elements that should be cared in our test cases. I think this is a better practice compared to data-test-id. And we use Google's Semantic Locators to achieve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant