forked from Greenstand/treetracker-admin-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogin.steps.js
More file actions
97 lines (76 loc) · 2.11 KB
/
login.steps.js
File metadata and controls
97 lines (76 loc) · 2.11 KB
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
97
const { Before, Given, When, Then } = require('@cucumber/cucumber');
const LoginPage = require('../page-objects/LoginPage');
const LOG_OUT_BUTTON = '//button[normalize-space(.)="LOG OUT"]';
async function navigate(path) {
await browser.url(path, { wait: 'none' });
}
async function clearAppStorage() {
await navigate('/');
await browser.execute(() => {
window.localStorage.clear();
window.sessionStorage.clear();
});
await browser.deleteCookies();
}
async function isExisting(selector) {
return $(selector)
.isExisting()
.catch(() => false);
}
async function openKeycloakLoginPage() {
await navigate('/login');
if (await LoginPage.isOpen()) {
await LoginPage.waitForPage();
return;
}
await navigate('/account');
try {
await browser.waitUntil(
async () =>
(await LoginPage.isOpen()) || (await isExisting(LOG_OUT_BUTTON)),
{ timeout: 15000, interval: 250 }
);
} catch {
await navigate('/login');
await LoginPage.waitForPage();
return;
}
if (await LoginPage.isOpen()) {
await LoginPage.waitForPage();
return;
}
const logoutButton = $(LOG_OUT_BUTTON);
await logoutButton.waitForDisplayed({ timeout: 10000 });
await logoutButton.scrollIntoView();
await logoutButton.click();
await LoginPage.waitForPage();
}
async function ensureLoggedOut() {
await clearAppStorage();
await openKeycloakLoginPage();
}
async function assertInvalidCredentialFeedback() {
await LoginPage.waitForInvalidCredentials();
}
Before(async () => {
await ensureLoggedOut();
});
Given('I am on the login page', async () => {
await openKeycloakLoginPage();
await LoginPage.waitForPage();
});
When(
'I enter username {string} and password {string}',
async (username, password) => {
await LoginPage.enterCredentials(username, password);
}
);
When('I click the login button', async () => {
await LoginPage.submit();
});
Then('I should see an error message', async () => {
await assertInvalidCredentialFeedback();
});
Then('I should be redirected away from the login page', async () => {
await LoginPage.waitForSuccessfulRedirect();
});