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

First parameter to custom child command is 'Window' #2898

Closed
benmonro opened this issue Dec 4, 2018 · 4 comments
Closed

First parameter to custom child command is 'Window' #2898

benmonro opened this issue Dec 4, 2018 · 4 comments

Comments

@benmonro
Copy link

benmonro commented Dec 4, 2018

In Cypress 3.1.1 the following code: worked:

Cypress.Commands.add("login", { prevSubject:true }, (userRole = 'usertypeQA') => {
  if (Cypress.$('[type=Email]').length > 0) {
    cy.get('[type="Email"]').clear();

    console.log(userRole); // == usetypeQA (or whatever is passed to cy.visit().login('xxx')
  }});

However, now it seems that as of 3.1.3, the 1st parameter is now 'Window'

Am I crazy or did that change?

Reason I'm putting this in as a bug report, rather than on Stack overflow, is that if so, I believe the documentation needs to be updated, as it's a bit confusing otherwise.

Thanks
Ben

@jennifer-shehane
Copy link
Member

Hey @benmonro, version 3.1.3 should not contain any breaking changes - so if this behavior is happening, it would be a bug. Am investigating now.

@jennifer-shehane jennifer-shehane added the stage: investigating Someone from Cypress is looking into this label Dec 5, 2018
@jennifer-shehane
Copy link
Member

jennifer-shehane commented Dec 5, 2018

Since you have passed prevSubject: true option to the custom command, the first argument will be whatever was yielded from the previously chained command.

For example:

cy.get('.misc-table').login() // first arg to login will be DOM `.misc-table`

cy.window().login() // first arg to login will be window

Did you chain the directly previous command that .login() is chained off of? If not, please provide the test code where .login() is called.

@jennifer-shehane jennifer-shehane added stage: needs information Not enough info to reproduce the issue and removed stage: investigating Someone from Cypress is looking into this labels Dec 5, 2018
@benmonro
Copy link
Author

benmonro commented Dec 5, 2018

@jennifer-shehane thanks for the reply. yes I'm doing this in cy.visit(url).login() in a setup. I could swear it was not passing the subject when i tried it previously, but I'm into my 40s now and that could be related. :)

@jennifer-shehane
Copy link
Member

Yes, cy.visit() yields the window object - looks to be behaving as documented.

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