-
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
Alias created in before() only works on first test (but it's only used in the second test) #5351
Comments
@dsesami Can you provide an example of this behavior that we can run completely on our machines? We do not know what is happening within your custom |
@jennifer-shehane here's a simpler example with the example tests that are generated with cypress initialization. /// <reference types="Cypress" />
context('Window', () => {
// new function
before(() => {
cy.visit('https://example.cypress.io/commands/window')
cy.get('h1').as('obj') // here's the alias
})
beforeEach(() => {
cy.visit('https://example.cypress.io/commands/window')
})
it('cy.window() - get the global window object', () => {
// https://on.cypress.io/window
cy.window().should('have.property', 'top')
cy.get('@obj').value // calling this alias works
})
it('cy.document() - get the document object', () => {
// https://on.cypress.io/document
cy.document().should('have.property', 'charset').and('eq', 'UTF-8')
cy.get('@obj').value // calling this alias doesn't work
})
}) Note that the alias is cleared after the first test when using
|
@jennifer-shehane this is just a light ping, wondering if you've had a chance to look this over. Thank you! |
Hello, I'm having this issue too. I noticed that the alias inside the "cypress": "^3.4.1",
node: v10.13.0
npm: 6.4.1 |
Moving this code into a Closing as duplicate of #665 |
@jennifer-shehane as this is apparently a very regularly-duplicated issue, may I suggest that the docs be updated to specify this nuance? Many users get tripped up by it. |
@dsesami We updated the scope of the original issue to issue a warning when defining an alias in a before, please direct all comments to the original issue. #665 (comment) |
Update 10/16: See #5351 (comment) for a clearer example and explanation.
Original Post Below This Line
------------------------------------------
This appears to be really similar to #2766 (and #665 in turn), but it seems like it's a bit different. The alias definition exists, like
user
as an object exists, anduser.id
exists, but the value ofuser.id
is null.Note that an alias created within the second test doesn't appear to work --
Current behavior:
The before() hook contains an alias. I would expect
this
to havethis.user
available as an object. If it is in the first test (I copy and move the test to the top), the test works. However, after the first test,this.user
exists, but its value is empty and undefined.Desired behavior:
I would expect
this.user
to remain a consistent object available throughout each test in the spec file. I can currently get around this withcy.createUser().then((user) => )
, but that's why I wanted to use aliases in the first place. Alternatively, I'd expect an alias to be create-able within a test.Steps to reproduce:
Test setup:
Versions
Latest cypress (Oct 11 2019), chrome, fedora.
If you need more info, please feel free to ask.
The text was updated successfully, but these errors were encountered: