bigbluebutton-Github/bigbluebutton-tests/playwright/core/page.js

179 lines
6.0 KiB
JavaScript
Raw Normal View History

require('dotenv').config();
2022-03-29 21:53:07 +08:00
const { expect, default: test } = require('@playwright/test');
2022-03-21 23:04:43 +08:00
const { readFileSync } = require('fs');
const parameters = require('./parameters');
const helpers = require('./helpers');
2021-11-18 04:07:14 +08:00
const e = require('./elements');
2021-11-27 04:01:41 +08:00
const { ELEMENT_WAIT_TIME, ELEMENT_WAIT_LONGER_TIME, VIDEO_LOADING_WAIT_TIME } = require('./constants');
2022-02-05 03:26:35 +08:00
const { checkElement, checkElementLengthEqualTo } = require('./util');
2022-06-08 02:52:22 +08:00
const { generateSettingsData, getSettings } = require('./settings');
class Page {
constructor(browser, page) {
this.browser = browser;
this.page = page;
this.initParameters = Object.assign({}, parameters);
}
2021-11-30 21:42:57 +08:00
async bringToFront() {
await this.page.bringToFront();
}
async getLastTargetPage(context) {
const contextPages = await context.pages();
return new Page(this.browser, contextPages[contextPages.length - 1]);
}
2021-11-19 04:09:29 +08:00
async init(isModerator, shouldCloseAudioModal, initOptions) {
const { fullName, meetingId, customParameter } = initOptions || {};
if (!isModerator) this.initParameters.moderatorPW = '';
if (fullName) this.initParameters.fullName = fullName;
2022-01-29 03:52:22 +08:00
this.username = this.initParameters.fullName;
2021-11-19 04:09:29 +08:00
this.meetingId = (meetingId) ? meetingId : await helpers.createMeeting(parameters, customParameter);
const joinUrl = helpers.getJoinURL(this.meetingId, this.initParameters, isModerator, customParameter);
2022-06-08 02:52:22 +08:00
const response = await this.page.goto(joinUrl);
await expect(response.ok()).toBeTruthy();
const hasErrorLabel = await this.page.evaluate(checkElement, [e.errorMessageLabel]);
await expect(hasErrorLabel, 'Getting error when joining. Check if the BBB_URL and BBB_SECRET are set correctly').toBeFalsy();
2022-03-29 21:53:07 +08:00
this.settings = await generateSettingsData(this.page);
const { autoJoinAudioModal } = this.settings;
if (shouldCloseAudioModal && autoJoinAudioModal) await this.closeAudioModal();
}
2022-03-21 23:04:43 +08:00
async handleDownload(selector, testInfo, timeout = ELEMENT_WAIT_TIME) {
const [download] = await Promise.all([
this.page.waitForEvent('download', { timeout }),
this.waitAndClick(selector, timeout),
]);
await expect(download).toBeTruthy();
const filePath = await download.path();
const content = await readFileSync(filePath, 'utf8');
2022-06-08 02:52:22 +08:00
await testInfo.attach('downloaded', { body: download });
2022-03-21 23:04:43 +08:00
return {
download,
content,
}
}
2021-11-27 04:01:41 +08:00
async joinMicrophone() {
await this.waitForSelector(e.audioModal);
await this.waitAndClick(e.microphoneButton);
2022-01-20 21:03:18 +08:00
await this.waitForSelector(e.connectingToEchoTest);
2022-06-08 02:52:22 +08:00
const { listenOnlyCallTimeout } = getSettings();
2021-11-27 04:01:41 +08:00
await this.waitAndClick(e.echoYesButton, listenOnlyCallTimeout);
await this.waitForSelector(e.isTalking);
}
2021-12-15 01:10:44 +08:00
async leaveAudio() {
await this.waitAndClick(e.leaveAudio);
await this.waitForSelector(e.joinAudio);
}
async logoutFromMeeting() {
2022-01-13 23:11:17 +08:00
await this.waitAndClick(e.optionsButton);
2021-12-15 01:10:44 +08:00
await this.waitAndClick(e.logout);
}
2022-01-29 03:52:22 +08:00
async shareWebcam(shouldConfirmSharing = true, videoPreviewTimeout = ELEMENT_WAIT_TIME) {
2022-06-08 02:52:22 +08:00
const { webcamSharingEnabled } = getSettings();
2022-03-29 21:53:07 +08:00
test.fail(!webcamSharingEnabled, 'Webcam sharing is disabled');
2021-11-27 04:01:41 +08:00
await this.waitAndClick(e.joinVideo);
if (shouldConfirmSharing) {
await this.bringToFront();
2021-11-27 04:01:41 +08:00
await this.waitForSelector(e.videoPreview, videoPreviewTimeout);
await this.waitAndClick(e.startSharingWebcam);
2021-11-26 02:23:58 +08:00
}
2021-11-27 04:01:41 +08:00
await this.waitForSelector(e.webcamConnecting);
await this.waitForSelector(e.webcamContainer, VIDEO_LOADING_WAIT_TIME);
2021-11-27 04:01:41 +08:00
await this.waitForSelector(e.leaveVideo, VIDEO_LOADING_WAIT_TIME);
}
2022-01-20 03:50:59 +08:00
getLocator(selector) {
2021-11-26 02:23:58 +08:00
return this.page.locator(selector);
}
2022-02-05 03:26:35 +08:00
getLocatorByIndex(selector, index) {
return this.page.locator(selector).nth(index);
}
async getSelectorCount(selector) {
2022-01-20 03:50:59 +08:00
const locator = this.getLocator(selector);
2021-11-26 02:23:58 +08:00
return locator.count();
}
async closeAudioModal() {
2021-11-26 02:23:58 +08:00
await this.waitForSelector(e.audioModal, ELEMENT_WAIT_LONGER_TIME);
2022-01-20 21:03:18 +08:00
await this.waitAndClick(e.closeModal);
}
async waitForSelector(selector, timeout = ELEMENT_WAIT_TIME) {
await this.page.waitForSelector(selector, { timeout });
}
2022-02-05 03:26:35 +08:00
async waitUntilHaveCountSelector(selector, count, timeout = ELEMENT_WAIT_TIME) {
await this.page.waitForFunction(
checkElementLengthEqualTo,
[selector, count],
{ timeout },
);
}
async type(selector, text) {
2022-01-20 03:50:59 +08:00
const handle = this.getLocator(selector);
await handle.focus();
await handle.type(text, { timeout: ELEMENT_WAIT_TIME });
}
2021-11-26 02:23:58 +08:00
async waitAndClickElement(element, index = 0, timeout = ELEMENT_WAIT_TIME) {
await this.waitForSelector(element, timeout);
await this.page.evaluate(([elem, i]) => {
document.querySelectorAll(elem)[i].click();
}, [element, index]);
}
async waitAndClick(selector, timeout = ELEMENT_WAIT_TIME) {
await this.waitForSelector(selector, timeout);
await this.page.focus(selector);
await this.page.click(selector, { timeout });
}
2021-11-23 01:06:59 +08:00
2022-02-03 08:45:23 +08:00
async clickOnLocator(locator, timeout = ELEMENT_WAIT_TIME) {
await locator.click({ timeout });
}
2021-12-01 22:02:26 +08:00
async checkElement(selector, index = 0) {
return this.page.evaluate(checkElement, [selector, index]);
}
2021-11-23 01:06:59 +08:00
async wasRemoved(selector, timeout = ELEMENT_WAIT_TIME) {
2022-01-20 03:50:59 +08:00
const locator = this.getLocator(selector);
2021-11-23 01:06:59 +08:00
await expect(locator).toBeHidden({ timeout });
}
async hasElement(selector, timeout = ELEMENT_WAIT_TIME) {
2022-01-20 03:50:59 +08:00
const locator = this.getLocator(selector);
2021-11-23 01:06:59 +08:00
await expect(locator).toBeVisible({ timeout });
}
2021-11-26 02:23:58 +08:00
2022-01-29 03:52:22 +08:00
async hasElementDisabled(selector, timeout = ELEMENT_WAIT_TIME) {
const locator = this.getLocator(selector);
await expect(locator).toBeDisabled({ timeout });
}
2022-02-03 08:45:23 +08:00
async hasElementEnabled(selector, timeout = ELEMENT_WAIT_TIME) {
const locator = this.getLocator(selector);
await expect(locator).toBeEnabled({ timeout });
}
2021-11-26 02:23:58 +08:00
async hasText(selector, text, timeout = ELEMENT_WAIT_TIME) {
2022-01-20 03:50:59 +08:00
const locator = this.getLocator(selector);
2021-11-26 02:23:58 +08:00
await expect(locator).toContainText(text, { timeout });
}
}
2021-11-03 06:50:20 +08:00
module.exports = exports = Page;