2021-11-03 00:45:52 +08:00
|
|
|
require('dotenv').config();
|
|
|
|
const { expect } = require('@playwright/test');
|
|
|
|
const parameters = require('./parameters');
|
|
|
|
const helpers = require('./helpers');
|
2021-11-18 04:07:14 +08:00
|
|
|
const e = require('./elements');
|
2021-11-20 01:32:56 +08:00
|
|
|
const { ELEMENT_WAIT_TIME } = require('./constants');
|
2021-11-03 00:45:52 +08:00
|
|
|
|
|
|
|
class Page {
|
2021-11-16 00:42:29 +08:00
|
|
|
constructor(browser, page) {
|
2021-11-03 00:45:52 +08:00
|
|
|
this.browser = browser;
|
2021-11-16 00:42:29 +08:00
|
|
|
this.page = page;
|
2021-11-03 00:45:52 +08:00
|
|
|
this.initParameters = Object.assign({}, parameters);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
this.meetingId = (meetingId) ? meetingId : await helpers.createMeeting(parameters, customParameter);
|
2021-11-03 00:45:52 +08:00
|
|
|
const joinUrl = helpers.getJoinURL(this.meetingId, this.initParameters, isModerator, customParameter);
|
|
|
|
await this.page.goto(joinUrl);
|
2021-11-19 04:09:29 +08:00
|
|
|
|
2021-11-03 00:45:52 +08:00
|
|
|
if (shouldCloseAudioModal) await this.closeAudioModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
async closeAudioModal() {
|
2021-11-18 04:07:14 +08:00
|
|
|
await this.page.waitForSelector(e.audioModal);
|
|
|
|
await this.page.click(e.closeAudioButton);
|
2021-11-03 00:45:52 +08:00
|
|
|
}
|
|
|
|
|
2021-11-20 01:32:56 +08:00
|
|
|
async waitForSelector(selector, timeout = ELEMENT_WAIT_TIME) {
|
|
|
|
await this.page.waitForSelector(selector, { timeout });
|
|
|
|
}
|
|
|
|
|
2021-11-03 00:45:52 +08:00
|
|
|
async type(selector, text) {
|
2021-11-20 01:32:56 +08:00
|
|
|
await this.waitForSelector(selector);
|
2021-11-03 00:45:52 +08:00
|
|
|
const handle = await this.page.$(selector);
|
2021-11-20 01:32:56 +08:00
|
|
|
await handle.focus();
|
2021-11-03 00:45:52 +08:00
|
|
|
await handle.type(text);
|
|
|
|
}
|
|
|
|
|
2021-11-20 01:32:56 +08:00
|
|
|
async waitAndClick(selector, timeout = ELEMENT_WAIT_TIME) {
|
|
|
|
await this.waitForSelector(selector, timeout);
|
|
|
|
await this.page.focus(selector);
|
2021-11-03 00:45:52 +08:00
|
|
|
await this.page.click(selector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-03 06:50:20 +08:00
|
|
|
module.exports = exports = Page;
|