2020-02-15 04:52:59 +08:00
|
|
|
require('dotenv').config();
|
2018-08-27 23:00:42 +08:00
|
|
|
const puppeteer = require('puppeteer');
|
2021-02-17 04:57:10 +08:00
|
|
|
const yaml = require('js-yaml');
|
2020-02-15 04:52:59 +08:00
|
|
|
const fs = require('fs');
|
2021-02-26 23:52:17 +08:00
|
|
|
const fsExtra = require('fs-extra');
|
2020-05-19 03:40:05 +08:00
|
|
|
const moment = require('moment');
|
2020-05-08 04:55:40 +08:00
|
|
|
const path = require('path');
|
2021-04-15 00:16:41 +08:00
|
|
|
const PuppeteerVideoRecorder = require('puppeteer-video-recorder');
|
2018-08-27 23:00:42 +08:00
|
|
|
const helper = require('./helper');
|
2021-10-01 02:36:31 +08:00
|
|
|
const params = require('./params');
|
2021-10-05 04:42:58 +08:00
|
|
|
const { ELEMENT_WAIT_TIME, VIDEO_LOADING_WAIT_TIME } = require('./constants');
|
2021-09-23 01:08:39 +08:00
|
|
|
const { getElementLength } = require('./util');
|
2018-08-27 23:00:42 +08:00
|
|
|
const e = require('./elements');
|
2021-05-26 00:05:11 +08:00
|
|
|
const { NETWORK_PRESETS } = require('./profiles');
|
|
|
|
const devices = require('./devices');
|
|
|
|
const linuxDesktop = devices['Linux Desktop'];
|
2018-08-27 23:00:42 +08:00
|
|
|
|
2018-10-13 02:46:26 +08:00
|
|
|
class Page {
|
2021-09-23 03:22:47 +08:00
|
|
|
constructor(page) {
|
|
|
|
this.page = page;
|
2018-11-23 03:15:52 +08:00
|
|
|
this.screenshotIndex = 0;
|
2018-11-23 20:55:16 +08:00
|
|
|
this.parentDir = this.getParentDir(__dirname);
|
2021-02-26 23:52:17 +08:00
|
|
|
this.recorder = new PuppeteerVideoRecorder();
|
2018-11-23 20:55:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getParentDir(dir) {
|
2018-12-10 10:12:42 +08:00
|
|
|
const tmp = dir.split('/');
|
2018-11-23 20:55:16 +08:00
|
|
|
tmp.pop();
|
|
|
|
return tmp.join('/');
|
2018-11-23 03:15:52 +08:00
|
|
|
}
|
|
|
|
|
2021-02-17 04:57:10 +08:00
|
|
|
async getSettingsYaml() {
|
|
|
|
try {
|
2021-08-03 00:26:09 +08:00
|
|
|
const settings = yaml.load(fs.readFileSync(path.join(__dirname, '../../../bigbluebutton-html5/private/config/settings.yml'), 'utf8'));
|
2021-02-17 04:57:10 +08:00
|
|
|
return settings;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
await this.logger(err);
|
2021-02-17 04:57:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-23 03:15:52 +08:00
|
|
|
// Join BigBlueButton meeting
|
2021-11-06 04:16:42 +08:00
|
|
|
async init(isModerator, shouldCloseAudioModal, testFolderName, fullName, meetingId, customParameter, connectionPreset, deviceX, extraFlags) {
|
2020-05-08 04:55:40 +08:00
|
|
|
try {
|
2021-11-06 04:16:42 +08:00
|
|
|
const args = this.getArgs(extraFlags?.length > 0 ? extraFlags : null);
|
2021-09-30 20:36:08 +08:00
|
|
|
this.effectiveParams = Object.assign({}, params);
|
|
|
|
if (!isModerator) this.effectiveParams.moderatorPW = '';
|
|
|
|
if (fullName) this.effectiveParams.fullName = fullName;
|
2020-05-08 04:55:40 +08:00
|
|
|
if (process.env.BROWSERLESS_ENABLED === 'true') {
|
|
|
|
this.browser = await puppeteer.connect({
|
|
|
|
browserWSEndpoint: `ws://${process.env.BROWSERLESS_URL}?token=${process.env.BROWSERLESS_TOKEN}&${args.args.join('&')}`,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.browser = await puppeteer.launch(args);
|
|
|
|
}
|
|
|
|
this.page = await this.browser.newPage();
|
2021-05-26 00:05:11 +08:00
|
|
|
this.page.emulate(deviceX || linuxDesktop);
|
|
|
|
await this.getUserAgent(this);
|
2021-04-02 08:54:55 +08:00
|
|
|
|
|
|
|
// Connect to Chrome DevTools
|
|
|
|
const client = await this.page.target().createCDPSession();
|
|
|
|
|
|
|
|
// Set throttling property
|
|
|
|
await client.send('Network.emulateNetworkConditions', connectionPreset || NETWORK_PRESETS.WiFi);
|
|
|
|
|
2021-05-26 00:05:11 +08:00
|
|
|
// if (process.env.DEVICE_NAME === 'Desktop') {
|
|
|
|
// await this.page.setViewport({ width: 1024, height: 720 });
|
|
|
|
// }
|
2021-04-02 08:54:55 +08:00
|
|
|
|
2020-05-08 04:55:40 +08:00
|
|
|
this.page.setDefaultTimeout(3600000);
|
2020-02-13 04:18:41 +08:00
|
|
|
|
2020-05-08 04:55:40 +08:00
|
|
|
// Getting all page console logs
|
|
|
|
// this.page.on('console', async msg => console[msg._type](
|
|
|
|
// ...await Promise.all(msg.args().map(arg => arg.jsonValue()))
|
|
|
|
// ));
|
2021-05-26 00:05:11 +08:00
|
|
|
|
2020-06-24 23:04:52 +08:00
|
|
|
await this.page.setExtraHTTPHeaders({
|
|
|
|
'Accept-Language': 'en-US',
|
|
|
|
});
|
2020-05-08 04:55:40 +08:00
|
|
|
await this.setDownloadBehavior(`${this.parentDir}/downloads`);
|
2020-05-13 21:53:14 +08:00
|
|
|
this.meetingId = await helper.createMeeting(params, meetingId, customParameter);
|
2021-08-14 01:35:00 +08:00
|
|
|
await this.logger('Meeting ID: ', this.meetingId);
|
2020-05-13 21:53:14 +08:00
|
|
|
|
|
|
|
const joinURL = helper.getJoinURL(this.meetingId, this.effectiveParams, isModerator, customParameter);
|
2021-02-26 23:52:17 +08:00
|
|
|
await this.page.goto(joinURL, { waitUntil: 'networkidle2' });
|
2021-04-02 08:54:55 +08:00
|
|
|
|
|
|
|
if (process.env.BBB_COLLECT_METRICS === 'true' && process.env.IS_MOBILE !== 'true') {
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitForSelector(e.anyUser);
|
2021-04-02 08:54:55 +08:00
|
|
|
await this.getMetrics(testFolderName);
|
|
|
|
}
|
2021-09-30 20:36:08 +08:00
|
|
|
if (shouldCloseAudioModal) await this.closeAudioModal();
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
await this.logger(err);
|
2020-03-04 22:50:56 +08:00
|
|
|
}
|
2018-08-27 23:00:42 +08:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:50:56 +08:00
|
|
|
// Joining audio with microphone
|
|
|
|
async joinMicrophone() {
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitForSelector(e.audioModal);
|
|
|
|
await this.waitAndClick(e.microphoneButton);
|
|
|
|
await this.waitForSelector(e.connectingStatus);
|
2021-02-17 04:57:10 +08:00
|
|
|
const parsedSettings = await this.getSettingsYaml();
|
|
|
|
const listenOnlyCallTimeout = parseInt(parsedSettings.public.media.listenOnlyCallTimeout);
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitAndClick(e.echoYesButton, listenOnlyCallTimeout);
|
|
|
|
await this.waitForSelector(e.isTalking);
|
2020-03-04 22:50:56 +08:00
|
|
|
}
|
|
|
|
|
2021-10-05 04:42:58 +08:00
|
|
|
async shareWebcam(shouldConfirmSharing, videoPreviewTimeout = ELEMENT_WAIT_TIME) {
|
|
|
|
await this.waitAndClick(e.joinVideo);
|
|
|
|
if (shouldConfirmSharing) {
|
|
|
|
await this.waitForSelector(e.videoPreview, videoPreviewTimeout);
|
|
|
|
await this.waitAndClick(e.startSharingWebcam);
|
|
|
|
}
|
|
|
|
await this.waitForSelector(e.webcamConnecting);
|
|
|
|
await this.waitForSelector(e.webcamVideo, VIDEO_LOADING_WAIT_TIME);
|
|
|
|
await this.waitForSelector(e.leaveVideo, VIDEO_LOADING_WAIT_TIME);
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:48:28 +08:00
|
|
|
// Joining audio with microphone
|
|
|
|
async joinMicrophoneWithoutEchoTest() {
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitAndClick(e.joinAudio);
|
2021-02-17 04:57:10 +08:00
|
|
|
const parsedSettings = await this.getSettingsYaml();
|
|
|
|
const listenOnlyCallTimeout = parseInt(parsedSettings.public.media.listenOnlyCallTimeout);
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitAndClick(e.leaveAudio, listenOnlyCallTimeout);
|
2021-02-17 04:57:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Leave audio
|
|
|
|
async leaveAudio() {
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitAndClick(e.leaveAudio);
|
|
|
|
await this.waitForSelector(e.joinAudio);
|
2020-05-15 22:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Logout from meeting
|
|
|
|
async logoutFromMeeting() {
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitAndClick(e.options);
|
|
|
|
await this.waitAndClick(e.logout);
|
2020-05-15 22:48:28 +08:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:50:56 +08:00
|
|
|
// Joining audio with Listen Only mode
|
|
|
|
async listenOnly() {
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitForSelector(e.audioModal);
|
|
|
|
await this.waitAndClick(e.listenOnlyButton);
|
2020-03-04 22:50:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async closeAudioModal() {
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitForSelector(e.audioModal);
|
|
|
|
await this.waitAndClick(e.closeAudioButton);
|
2020-03-04 22:50:56 +08:00
|
|
|
}
|
|
|
|
|
2018-11-23 03:15:52 +08:00
|
|
|
async setDownloadBehavior(downloadPath) {
|
2018-12-10 10:12:42 +08:00
|
|
|
const downloadBehavior = { behavior: 'allow', downloadPath };
|
2018-11-23 03:15:52 +08:00
|
|
|
await this.page._client.send('Page.setDownloadBehavior', downloadBehavior);
|
2018-08-27 23:00:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the test for the page
|
2018-10-13 02:46:26 +08:00
|
|
|
async test() {
|
2018-08-27 23:00:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Closes the page
|
2018-10-13 02:46:26 +08:00
|
|
|
async close() {
|
2018-08-27 23:00:42 +08:00
|
|
|
await this.browser.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gets the DOM elements being tested, as strings
|
2018-10-13 02:46:26 +08:00
|
|
|
async getTestElements() {
|
2018-08-27 23:00:42 +08:00
|
|
|
}
|
|
|
|
|
2020-07-14 03:03:41 +08:00
|
|
|
async clickBreakoutElement(element, pageNumber) {
|
|
|
|
const pageTarget = await this.browser.pages();
|
|
|
|
await pageTarget[pageNumber].click(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
async returnElement(element) {
|
2021-08-26 03:31:54 +08:00
|
|
|
return document.querySelectorAll(element)[0];
|
2018-08-27 23:00:42 +08:00
|
|
|
}
|
|
|
|
|
2021-05-26 00:05:11 +08:00
|
|
|
async getUserAgent(test) {
|
|
|
|
const useragent = await test.page.evaluate('navigator.userAgent');
|
2021-04-02 08:54:55 +08:00
|
|
|
console.log({ useragent });
|
|
|
|
return useragent;
|
|
|
|
}
|
|
|
|
|
2020-07-18 03:12:43 +08:00
|
|
|
// Get the default arguments for creating a page
|
2021-11-06 04:16:42 +08:00
|
|
|
getArgs(extraFlags) {
|
2020-05-08 04:55:40 +08:00
|
|
|
if (process.env.BROWSERLESS_ENABLED === 'true') {
|
|
|
|
const args = [
|
2020-03-05 03:00:45 +08:00
|
|
|
'--no-sandbox',
|
|
|
|
'--use-fake-ui-for-media-stream',
|
2020-06-24 23:04:52 +08:00
|
|
|
'--use-fake-device-for-media-stream',
|
2021-05-26 00:05:11 +08:00
|
|
|
'--window-size=1024,720',
|
2020-06-24 23:04:52 +08:00
|
|
|
'--lang=en-US',
|
2020-05-08 04:55:40 +08:00
|
|
|
];
|
2021-11-06 04:16:42 +08:00
|
|
|
if (extraFlags) args.push(...extraFlags);
|
2020-05-08 04:55:40 +08:00
|
|
|
return {
|
2020-07-20 23:52:48 +08:00
|
|
|
headless: true,
|
2020-05-08 04:55:40 +08:00
|
|
|
args,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
const args = [
|
|
|
|
'--no-sandbox',
|
|
|
|
'--use-fake-ui-for-media-stream',
|
|
|
|
'--use-fake-device-for-media-stream',
|
2021-04-02 08:54:55 +08:00
|
|
|
'--no-default-browser-check',
|
2021-05-26 00:05:11 +08:00
|
|
|
'--window-size=1150,980',
|
2020-06-16 04:00:35 +08:00
|
|
|
'--allow-file-access',
|
2020-06-24 23:04:52 +08:00
|
|
|
'--lang=en-US',
|
2020-05-08 04:55:40 +08:00
|
|
|
];
|
2021-11-06 04:16:42 +08:00
|
|
|
if (extraFlags) args.push(...extraFlags);
|
2020-05-08 04:55:40 +08:00
|
|
|
return {
|
2021-04-02 08:54:55 +08:00
|
|
|
headless: false,
|
2020-05-08 04:55:40 +08:00
|
|
|
args,
|
2021-04-02 08:54:55 +08:00
|
|
|
defaultViewport: {
|
2021-05-26 00:05:11 +08:00
|
|
|
width: 1250,
|
|
|
|
height: 850,
|
2021-04-02 08:54:55 +08:00
|
|
|
},
|
|
|
|
ignoreDefaultArgs: [
|
|
|
|
'--enable-automation',
|
|
|
|
],
|
2020-03-14 04:45:05 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-06 22:01:37 +08:00
|
|
|
static checkRegression(numb, screenshot) {
|
2021-05-26 00:05:11 +08:00
|
|
|
if (process.env.REGRESSION_TESTING === 'true') {
|
|
|
|
expect(screenshot).toMatchImageSnapshot({
|
|
|
|
failureThreshold: numb,
|
|
|
|
failureThresholdType: 'percent',
|
|
|
|
});
|
2021-08-14 01:35:00 +08:00
|
|
|
}
|
2020-09-09 23:51:56 +08:00
|
|
|
}
|
|
|
|
|
2021-04-02 08:54:55 +08:00
|
|
|
// async emulateMobile(userAgent) {
|
|
|
|
// await this.page.setUserAgent(userAgent);
|
|
|
|
// }
|
|
|
|
|
2018-08-27 23:00:42 +08:00
|
|
|
// Returns a Promise that resolves when an element does not exist/is removed from the DOM
|
2021-09-22 21:11:56 +08:00
|
|
|
async waitForElementHandleToBeRemoved(element, timeout = ELEMENT_WAIT_TIME) {
|
|
|
|
await this.page.waitForSelector(element, { timeout, hidden: true });
|
2018-08-27 23:00:42 +08:00
|
|
|
}
|
|
|
|
|
2021-09-22 22:36:58 +08:00
|
|
|
async wasRemoved(element, timeout = ELEMENT_WAIT_TIME) {
|
|
|
|
try {
|
|
|
|
await this.waitForElementHandleToBeRemoved(element, timeout);
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
this.logger(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-12 04:30:01 +08:00
|
|
|
async hasElement(element, visible = true, timeout = ELEMENT_WAIT_TIME) {
|
2021-09-22 22:36:58 +08:00
|
|
|
try {
|
|
|
|
await this.page.waitForSelector(element, { visible, timeout });
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
await this.logger(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:00:42 +08:00
|
|
|
// Presses a hotkey (Ctrl, Alt and Shift can be held down while pressing the key)
|
2018-10-13 02:46:26 +08:00
|
|
|
async hotkey(key, ctrl, alt, shift) {
|
|
|
|
if (ctrl) { await this.page.keyboard.down('Control'); }
|
|
|
|
if (alt) { await this.page.keyboard.down('Alt'); }
|
|
|
|
if (shift) { await this.page.keyboard.down('Shift'); }
|
2018-08-27 23:00:42 +08:00
|
|
|
|
|
|
|
await this.page.keyboard.press(key);
|
|
|
|
|
2018-10-13 02:46:26 +08:00
|
|
|
if (ctrl) { await this.page.keyboard.up('Control'); }
|
|
|
|
if (alt) { await this.page.keyboard.up('Alt'); }
|
|
|
|
if (shift) { await this.page.keyboard.up('Shift'); }
|
2018-08-27 23:00:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Presses the Tab key a set number of times
|
2018-10-13 02:46:26 +08:00
|
|
|
async tab(count) {
|
|
|
|
for (let i = 0; i < count; i++) {
|
2018-08-27 23:00:42 +08:00
|
|
|
await this.page.keyboard.press('Tab');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Presses the Enter key
|
2018-10-13 02:46:26 +08:00
|
|
|
async enter() {
|
2018-08-27 23:00:42 +08:00
|
|
|
await this.page.keyboard.press('Enter');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Presses the Down Arrow key a set number of times
|
2018-10-13 02:46:26 +08:00
|
|
|
async down(count) {
|
|
|
|
for (let i = 0; i < count; i++) {
|
2018-08-27 23:00:42 +08:00
|
|
|
await this.page.keyboard.press('ArrowDown');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Presses the up arrow key a set number of times
|
2018-10-13 02:46:26 +08:00
|
|
|
async up(count) {
|
|
|
|
for (let i = 0; i < count; i++) {
|
2018-08-27 23:00:42 +08:00
|
|
|
await this.page.keyboard.press('ArrowUp');
|
|
|
|
}
|
|
|
|
}
|
2018-11-21 07:51:40 +08:00
|
|
|
|
2021-03-09 05:11:36 +08:00
|
|
|
// Press a keyboard button
|
|
|
|
async press(key) {
|
|
|
|
await this.page.keyboard.press(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Press and hold a keyboard button
|
|
|
|
async hold(key) {
|
|
|
|
await this.page.keyboard.down(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release a hold pressed keyboard button
|
|
|
|
async release(key) {
|
|
|
|
await this.page.keyboard.up(key);
|
|
|
|
}
|
|
|
|
|
2021-09-23 03:22:47 +08:00
|
|
|
async bringToFront() {
|
|
|
|
await this.page.bringToFront();
|
|
|
|
}
|
|
|
|
|
|
|
|
async getLastTargetPage() {
|
|
|
|
const browserPages = await this.browser.pages();
|
|
|
|
return new Page(browserPages[browserPages.length - 1]);
|
|
|
|
}
|
|
|
|
|
2021-09-22 21:11:56 +08:00
|
|
|
async waitAndClick(element, timeout = ELEMENT_WAIT_TIME, relief = false) {
|
2018-11-21 07:51:40 +08:00
|
|
|
if (relief) await helper.sleep(1000);
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitForSelector(element, timeout);
|
|
|
|
await this.page.focus(element);
|
2021-02-17 04:57:10 +08:00
|
|
|
await this.page.click(element, true);
|
2018-11-21 07:51:40 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 01:08:39 +08:00
|
|
|
async waitAndClickElement(element, index = 0, timeout = ELEMENT_WAIT_TIME, relief = false) {
|
2021-09-22 21:11:56 +08:00
|
|
|
if (relief) await helper.sleep(1000);
|
|
|
|
await this.waitForSelector(element, timeout);
|
2021-09-23 06:13:12 +08:00
|
|
|
await this.page.evaluate((elem, i) => {
|
|
|
|
document.querySelectorAll(elem)[i].click();
|
2021-09-23 01:08:39 +08:00
|
|
|
}, element, index);
|
2021-09-22 21:11:56 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 05:16:11 +08:00
|
|
|
async clickNItem(element, n, relief = false) {
|
2021-03-09 05:11:36 +08:00
|
|
|
if (relief) await helper.sleep(1000);
|
2021-09-22 22:36:58 +08:00
|
|
|
await this.waitForSelector(element);
|
2021-03-09 05:11:36 +08:00
|
|
|
const elementHandle = await this.page.$$(element);
|
|
|
|
await elementHandle[n].click();
|
|
|
|
}
|
|
|
|
|
2018-11-21 07:51:40 +08:00
|
|
|
async type(element, text, relief = false) {
|
|
|
|
if (relief) await helper.sleep(1000);
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitForSelector(element);
|
2021-10-25 23:01:40 +08:00
|
|
|
await this.page.focus(element);
|
2018-11-21 07:51:40 +08:00
|
|
|
await this.page.type(element, text);
|
|
|
|
}
|
|
|
|
|
2021-02-26 23:52:17 +08:00
|
|
|
async startRecording(testName) {
|
|
|
|
if (process.env.WITH_RECORD === 'true') {
|
|
|
|
const today = moment(new Date()).format('DD-MM-YYYY');
|
|
|
|
const finalSaveFolder = path.join(__dirname, `../${process.env.TEST_FOLDER}`);
|
|
|
|
if (!fs.existsSync(finalSaveFolder)) {
|
|
|
|
fs.mkdirSync(finalSaveFolder);
|
|
|
|
}
|
|
|
|
this.testNameFolder = `${finalSaveFolder}/test-${today}-${testName}`;
|
|
|
|
if (!fs.existsSync(this.testNameFolder)) {
|
|
|
|
fs.mkdirSync(this.testNameFolder);
|
|
|
|
}
|
|
|
|
await this.recorder.init(this.page, `${this.testNameFolder}/recording`);
|
|
|
|
await this.recorder.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async stopRecording() {
|
|
|
|
if (process.env.WITH_RECORD === 'true') {
|
|
|
|
await this.recorder.stop();
|
|
|
|
await helper.sleep(5000);
|
|
|
|
await this.removeRecordingImages();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeRecordingImages() {
|
|
|
|
await fs.unlinkSync(`${this.testNameFolder}/recording/images.txt`);
|
2021-03-02 05:47:08 +08:00
|
|
|
await helper.sleep(5000);
|
2021-02-26 23:52:17 +08:00
|
|
|
await fsExtra.removeSync(`${this.testNameFolder}/recording/images`);
|
|
|
|
}
|
|
|
|
|
2020-05-22 00:45:52 +08:00
|
|
|
async screenshot(testFolderName, testFileName, relief = false) {
|
2020-05-20 00:26:10 +08:00
|
|
|
if (process.env.GENERATE_EVIDENCES === 'true') {
|
2021-02-26 23:52:17 +08:00
|
|
|
const today = moment(new Date()).format('DD-MM-YYYY');
|
2020-05-22 00:45:52 +08:00
|
|
|
const dir = path.join(__dirname, `../${process.env.TEST_FOLDER}`);
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
|
|
fs.mkdirSync(dir);
|
2020-05-19 03:40:05 +08:00
|
|
|
}
|
2020-05-22 00:45:52 +08:00
|
|
|
const testResultsFolder = `${dir}/test-${today}-${testFolderName}`;
|
|
|
|
if (!fs.existsSync(testResultsFolder)) {
|
|
|
|
fs.mkdirSync(testResultsFolder);
|
2020-05-19 03:40:05 +08:00
|
|
|
}
|
2020-05-20 00:26:10 +08:00
|
|
|
const screenshots = `${testResultsFolder}/screenshots`;
|
2020-05-22 00:45:52 +08:00
|
|
|
if (!fs.existsSync(screenshots)) {
|
|
|
|
fs.mkdirSync(screenshots);
|
2020-05-19 03:40:05 +08:00
|
|
|
}
|
|
|
|
if (relief) await helper.sleep(1000);
|
2020-05-22 00:45:52 +08:00
|
|
|
const filename = `${testFileName}.png`;
|
|
|
|
await this.page.screenshot({ path: `${screenshots}/${filename}` });
|
2020-05-19 03:40:05 +08:00
|
|
|
this.screenshotIndex++;
|
2021-02-26 23:52:17 +08:00
|
|
|
return testResultsFolder;
|
2020-05-19 03:40:05 +08:00
|
|
|
}
|
2018-11-23 03:15:52 +08:00
|
|
|
}
|
|
|
|
|
2020-06-16 01:21:44 +08:00
|
|
|
async logger() {
|
|
|
|
if (process.env.DEBUG === 'true') {
|
2021-02-17 04:57:10 +08:00
|
|
|
const date = moment(new Date()).format('DD-MMM-YYYY HH:mm:ss');
|
2020-06-16 01:21:44 +08:00
|
|
|
const args = Array.prototype.slice.call(arguments);
|
|
|
|
args.unshift(`${date} `);
|
|
|
|
console.log(...args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-23 03:15:52 +08:00
|
|
|
async paste(element) {
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitAndClick(element);
|
2018-11-23 03:15:52 +08:00
|
|
|
await this.page.keyboard.down('ControlLeft');
|
|
|
|
await this.page.keyboard.press('KeyV');
|
|
|
|
await this.page.keyboard.up('ControlLeft');
|
2018-11-21 07:51:40 +08:00
|
|
|
}
|
2018-11-23 22:43:35 +08:00
|
|
|
|
2021-09-22 21:11:56 +08:00
|
|
|
async waitForSelector(element, timeout = ELEMENT_WAIT_TIME) {
|
2021-09-22 22:36:58 +08:00
|
|
|
await this.page.waitForSelector(element, { timeout });
|
2018-11-23 22:43:35 +08:00
|
|
|
}
|
2020-02-15 04:52:59 +08:00
|
|
|
|
2020-05-22 00:45:52 +08:00
|
|
|
async getMetrics(testFolderName) {
|
2020-05-08 04:55:40 +08:00
|
|
|
const pageMetricsObj = {};
|
2021-02-26 23:52:17 +08:00
|
|
|
const today = moment(new Date()).format('DD-MM-YYYY');
|
2020-05-22 00:45:52 +08:00
|
|
|
const dir = path.join(__dirname, `../${process.env.TEST_FOLDER}`);
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
|
|
fs.mkdirSync(dir);
|
2020-05-19 03:40:05 +08:00
|
|
|
}
|
2020-05-22 00:45:52 +08:00
|
|
|
const testExecutionResultsName = `${dir}/test-${today}-${testFolderName}`;
|
|
|
|
if (!fs.existsSync(testExecutionResultsName)) {
|
|
|
|
fs.mkdirSync(testExecutionResultsName);
|
2020-05-19 03:40:05 +08:00
|
|
|
}
|
2020-05-22 00:45:52 +08:00
|
|
|
const metricsFolder = `${testExecutionResultsName}/metrics`;
|
|
|
|
if (!fs.existsSync(metricsFolder)) {
|
|
|
|
fs.mkdirSync(metricsFolder);
|
2020-02-15 04:52:59 +08:00
|
|
|
}
|
2021-09-22 21:11:56 +08:00
|
|
|
await this.waitForSelector(e.anyUser);
|
2020-05-08 04:55:40 +08:00
|
|
|
const totalNumberOfUsersMongo = await this.page.evaluate(() => {
|
2021-04-02 08:54:55 +08:00
|
|
|
const collection = require('/imports/api/users-persistent-data/index.js');
|
|
|
|
const users = collection.default._collection.find({}, {}, {}, {}, {}, { loggedOut: 'false' }).count();
|
2020-05-08 04:55:40 +08:00
|
|
|
return users;
|
|
|
|
});
|
2021-09-22 11:51:29 +08:00
|
|
|
const totalNumberOfUsersDom = await this.page.evaluate(getElementLength, e.anyUser);
|
2021-08-14 01:35:00 +08:00
|
|
|
await this.logger({ totalNumberOfUsersDom, totalNumberOfUsersMongo });
|
2020-02-15 04:52:59 +08:00
|
|
|
const metric = await this.page.metrics();
|
2020-05-08 04:55:40 +08:00
|
|
|
pageMetricsObj.totalNumberOfUsersMongoObj = totalNumberOfUsersMongo;
|
|
|
|
pageMetricsObj.totalNumberOfUsersDomObj = totalNumberOfUsersDom;
|
|
|
|
pageMetricsObj[`metricObj-${this.meetingId}`] = metric;
|
2021-02-26 23:52:17 +08:00
|
|
|
const metricsFile = path.join(__dirname, `../${process.env.TEST_FOLDER}/test-${today}-${testFolderName}/metrics/metrics-${this.effectiveParams.fullName}-[${this.meetingId}].json`);
|
2021-08-14 01:35:00 +08:00
|
|
|
const createFile = async () => {
|
2020-02-19 01:03:50 +08:00
|
|
|
try {
|
2020-05-22 00:45:52 +08:00
|
|
|
fs.appendFileSync(metricsFile, `${JSON.stringify(pageMetricsObj)},\n`);
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
await this.logger(err);
|
2020-02-15 04:52:59 +08:00
|
|
|
}
|
2020-02-18 02:40:05 +08:00
|
|
|
};
|
2021-08-14 01:35:00 +08:00
|
|
|
await createFile();
|
2020-02-15 04:52:59 +08:00
|
|
|
}
|
2018-10-13 02:46:26 +08:00
|
|
|
}
|
2018-08-27 23:00:42 +08:00
|
|
|
|
2023-04-04 04:23:26 +08:00
|
|
|
module.exports = exports = Page;
|