cypress
cypress copied to clipboard
Need way to get list of existing aliases / intercepts
What would you like?
Would like a way of getting existing aliases / intercepts in order to check if an alias already exists or not, since cy.get(@alias) throws an error on an alias that doesn't exist.
Why is this needed?
Need access to list of intercept aliases
Other
related question: https://github.com/cypress-io/cypress/discussions/24289
You can currently get a list of aliases using cy.state('aliases') although this is an internal API and it's not documented, so we can't guarantee that it's not going to change.
However I think there should be an official, public API for acquiring these, and we'll internally reference your request as we revisit modifications to the public API at a later time.
It would also be helpful if you could expand on your request and help us better understand your use case. Do you mind explaining with code what you're trying to accomplish? Thanks.
@BlueWinds labeling this issue as topic: cy api as an input for exploring future cy API enhancements. Just putting it on your radar.
It would also be helpful if you could expand on your request and help us better understand your use case. Do you mind explaining with code what you're trying to accomplish? Thanks.
Example use case:
describe('Outermost Suite', () => {
beforeEach(() => {
if (!Cypress.aliases.includes('interceptAlias') ) { // here is the requested feature-- would be fine as a promise as well
cy.intercept(/** the intercept */).as('interceptAlias')
}
// rest of beforeEach code here
})
context('Suite That Uses Default Intercept', () => {
it('test 1')
})
context('Suite that overrides the Default Intercept in the outer beforeEach', () => {
beforeEach(() => {
cy.intercept(/** overrides the outer beforeEach intercept*/).as('interceptAlias')
})
it('test 2')
}
)
})
I have the same request. In my team, we actively use cy.session(). The session wraps user creation - and we store the user data under alias: cy.wrap(response.body).as('user'). The problem is cy.session() doesn't keep aliases. So, I have to check if user alias exists and if no, get it another way.
In my case, best solution would be to keep aliases together with session.
Hi team, I'm also waiting for this feature.
What I want to do is aliasing some values that need to be cleaned up. In order to abstract the cleanup process, I want to check if I need to clean up or not, by checking the existance of the alias.
I hope this is pretty following the cypress-way but please let me know if any of you know some decent alternative way.
What I want to do is aliasing some values that need to be cleaned up. In order to abstract the cleanup process, I want to check if I need to clean up or not, by checking the existance of the alias.
Another great use case for this feature.