-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Feature] Configurable selectors in codegen #9015
Comments
Currently if you want to use a different attribute selector to the existing ones you can use CSS selectors. In your case e.g. Is it about the element selectors itself or about the codegen feature? |
@mxschmitt About Codegen feature. I would like to pass to Codegen Selector constructing strategy that prepends default one, or override default list of preferred tags ["data-test-id", ...] with my own. So that i can use Codegen in a way it prefers my list of tags while constructing Selectors during record session. This exact feature was present in QA Wolf library before they went from full Open Source to SaaS. And it is awesome, because not everybody uses data-test-id. |
This is a valid feature request, can't give a eta but this is definitely a space where we want to invest time into (letting the user decide which selectors he want to use, there your custom attributes make also sense). |
Thank you, with that kind of attitude I believe you can really succeed on the promise to make Playwright as ground breaking and loved by whole world as Visual Studio Code :) |
I'll give my 2 cents here. We are currently using cypress but investigating an alternatives. We have a custom selector mechanism (for cypress playground) which works by grabbing the whole path to particular element using only |
@mxschmitt, as me and @kresli showed is that companies push this pattern to limits to achieve even better results, so allowing people to prepend their own script/selector generation strategy would be even more beneficial than just overriding tag name. Just something to consider. |
Upvote, we are using |
If you set the option e.g. |
@kareman It doesn't seem to be working.
but Playwright keeps collecting something like #18888 is marked as closed but I think it should be re-opened. My current version of playwright is |
@PetraStill you need to run a test in VSCode, then say record new test and then it will work. npx playwright codegen won't respect the config if thats what you are referring to. |
@mxschmitt |
You need to start it via the Testing tab in VSCode, not the terminal. See here: https://playwright.dev/docs/getting-started-vscode#generating-tests and https://www.youtube.com/watch?v=LM4yqrOzmFE |
@mxschmitt whereas I (to make it work) write it as However, the extension totally disregards my current settings and generates the test in type script though I chose java script. It's probably another issue though. |
@PetraStill for you applies most likely the same as for #24276 (comment). For the other issue please file a separate issue, so we don't spam the folks here who subscribe to this issue. The TypeScript we generate is also compatible with the normal JavaScript, so you should not have any issues here. Thanks! |
Hi @mxschmitt
and i what to codegen using page.getByTestId('uniq-id') locator instead of page.getByRole('button', { name: 'Submit' }) |
@anagami testIds always have the highest priority as of today. If it does not get picked up you either have a different test-id naming convention or we have a bug! |
Oops. you are right! My code has mistake - value of |
I love using codegen however I am stuck at using data-test-customer-name as an attribute. note that it is not like others who mentioned here as data-test-something=value but it is just an attribute.
codegen failed to recognize this and always uses a dynamic id attribute. The id field seems to change on every page load, so cannot use the script generated by codegen. This feature will really help us start using playwright as the only tool for test automation if it can be fixed. |
@kresli Why are you looking for an alternative to Cypress? since data-test-* is not supported in Playwright, I was thinking the next best thing is Cypress also since it has support for Cypress Studio (experimental feature) which is similar to Codegen. Sorry for asking this question here, but I really wanted to know the answer and it might help others who are looking at similar problems to solve. |
It is interesting that |
Please make the list of
["data-test-id", "data-testid", ...]
selector building attributes configurable. Or even please add an configuration option to add custom JS/TS method that prepends your selector building code.Reasons:
The text was updated successfully, but these errors were encountered: