Repository navigation
Expand file tree
/
Copy pathadmin.page.js
More file actions
46 lines (41 loc) · 1.78 KB
/
Copy pathadmin.page.js
File metadata and controls
46 lines (41 loc) · 1.78 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
const Page = require('./page');
const { wdioWebdriverHelper: wdioHelper } = require('../../utils/wdio');
const { elements } = require('../../locators/admin/admin.locator');
const { PLATFORM_BASE_URL } = require('../../config/constants');
/**
* Page object for the restful-booker-platform admin panel
* (https://automationintesting.online/admin).
*/
class AdminPage extends Page {
// Absolute URL: this page lives on a different host than the default baseUrl.
open() {
return super.open(`${PLATFORM_BASE_URL}/admin`);
}
/**
* Log into the admin panel and wait for the room list to render. The app
* shows the login form when logged-out but redirects straight to the room
* list when a session already exists, so logging in is done only if needed.
*/
async login(username, password) {
// Wait until the SPA has rendered either the login form or the room list.
await browser.waitUntil(
async () =>
(await wdioHelper.isExisting(elements.USERNAME)) ||
(await wdioHelper.isExisting(elements.ROOM_ROW)),
{ timeout: 30000, timeoutMsg: 'Admin panel did not load' }
);
if (await wdioHelper.isExisting(elements.USERNAME)) {
await wdioHelper.setValue(elements.USERNAME, username);
await wdioHelper.setValue(elements.PASSWORD, password);
await wdioHelper.clickElement(elements.LOGIN_BUTTON);
await wdioHelper.waitForElementVisible(elements.ROOM_ROW);
}
}
/** Whether a room with the given name is shown in the admin room list. */
async isRoomListed(roomName) {
await wdioHelper.waitForElementVisible(elements.ROOM_ROW);
const rows = await wdioHelper.mapElements(elements.ROOM_ROW, (el) => el.getText());
return rows.some((text) => text.includes(roomName));
}
}
module.exports.AdminPage = new AdminPage();