-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.js
96 lines (88 loc) · 2.43 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// ***********************************************
// 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 is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
import { createClient } from '../helpers'
Cypress.Commands.add(
'authCodeFlow',
(
client,
{
override: { scope, client_id, client_secret } = {},
consent: {
accept: acceptConsent = true,
skip: skipConsent = false,
remember: rememberConsent = false,
scope: acceptScope = []
} = {},
login: {
accept: acceptLogin = true,
skip: skipLogin = false,
remember: rememberLogin = false,
username = '[email protected]',
password = 'foobar'
} = {},
prompt = '',
createClient: doCreateClient = true
} = {},
path = 'oauth2'
) => {
if (doCreateClient) {
cy.wrap(createClient(client))
}
cy.visit(
`${Cypress.env('client_url')}/${path}/code?client_id=${
client_id || client.client_id
}&client_secret=${client_secret || client.client_secret}&scope=${(
scope || client.scope
).replace(' ', '+')}&prompt=${prompt}`,
{ failOnStatusCode: false }
)
if (!skipLogin) {
cy.get('#email').type(username, { delay: 1 })
cy.get('#password').type(password, { delay: 1 })
if (rememberLogin) {
cy.get('#remember').click()
}
if (acceptLogin) {
cy.get('#accept').click()
} else {
cy.get('#reject').click()
}
}
if (!skipConsent) {
acceptScope.forEach((s) => {
cy.get(`#${s}`).click()
})
if (rememberConsent) {
cy.get('#remember').click()
}
if (acceptConsent) {
cy.get('#accept').click()
} else {
cy.get('#reject').click()
}
}
}
)