-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Update auth examples for v12 on custom commands page #4894
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -173,21 +173,33 @@ cy.getSessionStorage('token').should('eq', 'abc123') | |||||
#### Log in command using UI | ||||||
|
||||||
```js | ||||||
Cypress.Commands.add('typeLogin', (user) => { | ||||||
cy.get('input[name=email]').type(user.email) | ||||||
|
||||||
cy.get('input[name=password]').type(user.password) | ||||||
Cypress.Commands.add('loginViaUi', (user) => { | ||||||
cy.session( | ||||||
user, | ||||||
() => { | ||||||
cy.visit('/login') | ||||||
cy.get('input[name=email]').type(user.email) | ||||||
cy.get('input[name=password]').type(user.password) | ||||||
cy.click('button#login') | ||||||
cy.get('h1').contains(`Welcome back ${user.name}!`) | ||||||
}, | ||||||
{ | ||||||
validate: () => { | ||||||
cy.getCookie('auth_key').should('exist') | ||||||
}, | ||||||
} | ||||||
) | ||||||
}) | ||||||
``` | ||||||
|
||||||
```js | ||||||
cy.typeLogin({ email: '[email protected]', password: 'Secret1' }) | ||||||
cy.loginViaUi({ email: '[email protected]', password: '$ecret1', name: 'johndoe' }) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would probably be a light version of what we have with the auth0/okta/cognito guides to show a general cy.origin pattern with cy.session There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
``` | ||||||
|
||||||
#### Log in command using request | ||||||
|
||||||
```javascript | ||||||
Cypress.Commands.add('login', (userType, options = {}) => { | ||||||
Cypress.Commands.add('loginViaApi', (userType, options = {}) => { | ||||||
// this is an example of skipping your UI and logging in programmatically | ||||||
|
||||||
// setup some basic types | ||||||
|
@@ -232,10 +244,10 @@ Cypress.Commands.add('login', (userType, options = {}) => { | |||||
|
||||||
```javascript | ||||||
// can start a chain off of cy | ||||||
cy.login('admin') | ||||||
cy.loginViaApi('admin') | ||||||
|
||||||
// can be chained but will not receive the previous subject | ||||||
cy.get('button').login('user') | ||||||
cy.get('button').loginViaApi('user') | ||||||
``` | ||||||
|
||||||
#### Log out command using UI | ||||||
|
@@ -245,6 +257,8 @@ Cypress.Commands.add('logout', () => { | |||||
cy.contains('Login').should('not.exist') | ||||||
cy.get('.avatar').click() | ||||||
cy.contains('Logout').click() | ||||||
cy.get('h1').contains('Login') | ||||||
cy.getCookie('auth_key').should('not.exist') | ||||||
}) | ||||||
``` | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is holy war material mate! https://google.github.io/styleguide/jsguide.html#naming-camel-case-defined