-
Notifications
You must be signed in to change notification settings - Fork 3
/
commands.js
62 lines (59 loc) · 1.53 KB
/
commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
import '@cypress-audit/lighthouse/commands'
Cypress.Commands.add('login', (user, password) => {
return cy.session(
user,
() => {
cy.request({
method: 'POST',
url: '/user/login',
form: true,
body: {
name: user,
pass: password,
form_id: 'user_login_form',
},
})
},
{
// validate() {
// cy.visit('/user_profile');
// cy.contains(`Hello ${name}`);
// },
cacheAcrossSpecs: true,
},
)
})
Cypress.Commands.add('logout', () => {
return cy
.visit('/user/logout/confirm')
.get('#user-logout-confirm')
.submit()
.then(() => {
Cypress.session.clearAllSavedSessions()
})
})