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

[QUERY] Can multiple test-ids be configured? #155

Closed
JohnJacobT opened this issue Sep 22, 2020 · 6 comments
Closed

[QUERY] Can multiple test-ids be configured? #155

JohnJacobT opened this issue Sep 22, 2020 · 6 comments

Comments

@JohnJacobT
Copy link

Hello,

First of all, thank you for creating this.

This is not a 'issue', but a query: Can you configure more than one testid attribute?

The section Configure testId attribute shows how to change the default testId attribute to another. Is it possible to configure multiple testid attributes, if yes, how?

Cypress documentation about Selector Playground talks about different testid attributes in the order of priority. In a couple of projects, I am working on, I see different testId attributes used in different sections of a web app. With these two, I assume, it is not uncommon to encounter different test id attributes in the same web app. Hence the question.

In case, configuring multiple test id attributes are not currently supported, is there a plan to incorporate this feature in later releases?

Regards,
John.

P.S - CODE_OF_CONDUCT.md, mentioned in the template that comes up while creating a new issue, is not found in this repository.

@kentcdodds

This comment has been minimized.

@kentcdodds

This comment has been minimized.

@kentcdodds
Copy link
Member

Hi John,

Unfortunately I don't think this is possible. But you could make your own command for those.

And here's the CODE_OF_CONDUCT.md file: https://github.com/testing-library/cypress-testing-library/blob/master/other/CODE_OF_CONDUCT.md Thanks!

@JohnJacobT
Copy link
Author

Thanks @kentcdodds

Do you have time to create and share an example of how to create a command to configre multiple test-id attributes?

@kentcdodds
Copy link
Member

Hi @JohnJacobT,

I don't have a lot of time, but take this for example:

cy.get('[mydata-testid="example"]')

That should get you an element with that attribute/value pair. From there you could paramarize it and make it a custom command:

Cypress.Commands.add('getByMyTestId', id => cy.get(`[mydata-testid="${id}"]`))

// then later

cy.getByMyTestId('example')

I hope that helps! Good luck!

@JohnJacobT
Copy link
Author

Got the idea. Thanks again!

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

2 participants