forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.ts
63 lines (58 loc) · 1.75 KB
/
commands.ts
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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import 'cypress-real-events/support';
import { Interception } from 'cypress/types/net-stubbing';
Cypress.Commands.add('loginAsReadOnlyUser', () => {
cy.loginAs({ username: 'apm_read_user', password: 'changeme' });
});
Cypress.Commands.add('loginAsPowerUser', () => {
cy.loginAs({ username: 'apm_power_user', password: 'changeme' });
});
Cypress.Commands.add(
'loginAs',
({ username, password }: { username: string; password: string }) => {
cy.log(`Logging in as ${username}`);
const kibanaUrl = Cypress.env('KIBANA_URL');
cy.request({
method: 'POST',
url: `${kibanaUrl}/internal/security/login`,
body: {
providerType: 'basic',
providerName: 'basic',
currentURL: `${kibanaUrl}/login`,
params: { username, password },
},
headers: {
'kbn-xsrf': 'e2e_test',
},
});
}
);
Cypress.Commands.add('changeTimeRange', (value: string) => {
cy.get('[data-test-subj="superDatePickerToggleQuickMenuButton"]').click();
cy.contains(value).click();
});
Cypress.Commands.add(
'expectAPIsToHaveBeenCalledWith',
({
apisIntercepted,
value,
}: {
apisIntercepted: string[];
value: string;
}) => {
cy.wait(apisIntercepted).then((interceptions) => {
if (Array.isArray(interceptions)) {
interceptions.map((interception) => {
expect(interception.request.url).include(value);
});
} else {
expect((interceptions as Interception).request.url).include(value);
}
});
}
);