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

Chaining is broken when reusing same options object in .type() command #365

Closed
bahmutov opened this issue Dec 29, 2016 · 6 comments · Fixed by #2016
Closed

Chaining is broken when reusing same options object in .type() command #365

bahmutov opened this issue Dec 29, 2016 · 6 comments · Fixed by #2016
Assignees
Labels
pkg/driver This is due to an issue in the packages/driver directory type: bug
Milestone

Comments

@bahmutov
Copy link
Contributor

bahmutov commented Dec 29, 2016

Here is a good one (Cypress 0.18.4)

This works

const dontLog = {log: false}
  cy
    .visit(url)
    .get('[name=email]', dontLog).clear().type(email, dontLog)
    .get('[name=password]', dontLog).clear().type(password, {log: false})
    .get('button', {log: false}).click({log: false})

This does not work (enters the password in the email field instead

const dontLog = {log: false}
  cy
    .visit(url)
    .get('[name=email]', dontLog).clear().type(email, dontLog)
    .get('[name=password]', dontLog).clear().type(password, dontLog)
    .get('button', {log: false}).click({log: false})

The above code is inside custom command Cypress.addParentCommand('login') {...}

I am attaching the video (without clicking submit so it stops and shows the problem)

login-problem-gif

@bahmutov
Copy link
Contributor Author

If I try freezing the options object, it throws an error "TypeError: Cannot read property 'is' of undefined".

const dontLog = Object.freeze({log: false})
  cy
    .visit(url)
    .get('[name=email]', dontLog).clear().type(email, dontLog)
    .get('[name=password]', dontLog).clear().type(password, dontLog)

@brian-mann
Copy link
Member

Yah we are internally mutating those objects which makes sense why this fails. Probably should not be doing that, should clone them first.

Curious why you can't use cy.request here, instead of using your UI to perform those same actions. I'm guessing you're wrapping this up as a custom command.

@bahmutov
Copy link
Contributor Author

this is a custom login command, which includes CSRF token. You probably want to use at least Cypress._.clone(options) ;)

@brian-mann
Copy link
Member

I see. You can still use cy.request for CSRF tokens.

Here's an example.

https://github.com/cypress-io/cypress-example-recipes#logging-in---csrf-tokens

@bahmutov
Copy link
Contributor Author

bahmutov commented Dec 29, 2016

of course, I saw that example yesterday :) But it a lot flakier than going through UI :)
"Flaky" is a wrong word - it is a lot more tied to implementation.

@brian-mann
Copy link
Member

How's it flakier? It should be much less flakier and much faster.

@jennifer-shehane jennifer-shehane added the pkg/driver This is due to an issue in the packages/driver directory label Mar 21, 2017
@kuceb kuceb self-assigned this Jul 16, 2018
@kuceb kuceb added this to the 3.0.3 milestone Jul 16, 2018
brian-mann pushed a commit that referenced this issue Jul 23, 2018
this grew to a large PR fixing many cy.type issues.

fix #365
fix #420
fix #586 
fix #593 
fix #596 
fix #610 
fix #651
fix #940
fix #1002 
fix #1108
fix #1171
fix #1209 
fix #1234 
fix #1366
fix #1381 
fix #1684 
fix #1686
fix #1926 
fix #2056
fix #2096 
fix #2110 
fix #2173
fix #2187
@jennifer-shehane jennifer-shehane added stage: pending release and removed stage: needs review The PR code is done & tested, needs review stage: needs investigating Someone from Cypress needs to look at this stage: in progress labels Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/driver This is due to an issue in the packages/driver directory type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants