-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Can we please overwrite query commands #25078
Comments
cypress-if and cypress-aliases are so core that I wish they were a part of the main code base. |
and cypress-map :) |
+1 to solve this issue soon, it's blocking us to be able to update to version 12. Thanks team! |
This comment was marked as duplicate.
This comment was marked as duplicate.
1 similar comment
This comment was marked as duplicate.
This comment was marked as duplicate.
To everyone responding with "+1" - please use reactions on the issue rather than filling the issue with comments. We are discussing this and thinking about it. |
One thing to keep in mind - if we add an API to overwrite queries, it will only be with other queries - there will be no replacing cy.get() with a non-query command. Something like cypress-if will still need to be written differently, rather than the current implementation of overriding My suggestion for cypress-if specifically would be to look at other ways to achieve it that don't involve overwriting particular commands. My suggestion would be to look at either making |
Looking at cypress-aliases, much of it should still work. The exceptions are the overrides of I don't see that cypress-map needs to override anything? It looks like a very smooth migration to use queries instead of commands. |
What is the motivation for blocking overwrite of queries in the first place? I use query changes similar to Gleb's libraries, but now blocked. Could it be made configurable by flag? |
For those that would like to see this feature, can you please add a comment on why overriding a query is needed vs adding a custom query. We are interested in use-cases on why this is desirable beyond it preventing overriding existing queries for the sake of re-using the command name. |
We didn't block overrwriting so much as not add it - mostly due to time constraints. To support overwriting them will require a new API - As Emily said, we'd like to see the use cases people have, so when we do create a query overwrite API, we can make sure it's actually useful to people! |
conditional testingWhen testing frontend with live services, conditional testing is often required (or I should call it "conditionally closing irrelevant popups"). My solution still works with Cypress 12: https://github.com/mirobo/cypress-fiddle/blob/main/cypress/support/commands.js#L61-L88 But I'd like to see functionality like cypress-if added to cypress directly because @bahmutov 's solution blends in much better with cypress' syntax style and offers more features. It should be a core feature. alias handlingthe current possibilities with aliases and variables ( https://docs.cypress.io/guides/core-concepts/variables-and-aliases ) are leading to unreadable code when extensively used in RWA's.
by using cypress-aliases, the callback hell can be eliminated completely:
@bahmutov haven't tested if it works with multiple aliases... but it would be incredibly good!
|
In my case, I overwrite |
We have all our testing constants declared in a separate JSON file testing-constants.json, e.g. In commands.ts we check if it's usual selector or data-test-id:
Then we have 3 commands overwritten:
In the spec file we import values from testing-constants.json as TC and use it in the following way:
Before Cypress 12 came out It was very comfortable for us to have it overwritten and not write steps like this: or even
I managed to create a new command for our custom cy.get() to make it work in Cypress 12, but having troubles with cy.contains() & cy.find(). |
My org relies on |
Any update on this one? |
Update is pretty straightforward - this is definitely something we want to support, and is next on my list after #25134 (which is a way larger change than it looks on the surface). I don't have exact details on the what the API will look like yet, though. We're looking ahead a bit to design it in a way that will ultimately be compatible with the upcoming Async/Await API (which is the big project on my plate for this year). I want to make sure that when we do provide an overwrite API for queries we won't have to change it a couple months down the line to support the next set of changes - this is why Cy12 didn't ship with it. |
Looking forward to getting this functionality back. We have overwritten |
I'll be starting work on this this week. Tentatively, the rules will work like this:
Be aware that most queries rely on
The above example adds a bunch of console.logs() to the execution of .get(). |
@BlueWinds hey! Any update on the status of this ticket? Being able to update to the latest cypress version is very important to us and we can't upgrade to V12 until this issue is fixed. Thanks! |
The linked pull request is in review; we should have it merged in later this week, to go out with the next release. |
Nice, thanks!! looking forward to have it and upgrade to the latest cypress version 🚀 |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
What would you like?
Cypress v12 designated several query commands, and now prevents me from overwriting them. Which broke my plugins bahmutov/cypress-if#58 and bahmutov/cypress-aliases#17
Can we please allow overwriting queries, I promise to use it for good
Why is this needed?
I keep track of information or change behavior of several query commands in my plugins
Other
No response
The text was updated successfully, but these errors were encountered: