2020-06-09 03:40:28 +08:00
|
|
|
const path = require('path');
|
2021-08-20 04:22:31 +08:00
|
|
|
const e = require('../core/elements');
|
2021-10-18 22:23:00 +08:00
|
|
|
const c = require('./constants');
|
2021-09-23 01:17:56 +08:00
|
|
|
const { ELEMENT_WAIT_LONGER_TIME } = require('../core/constants');
|
2021-10-18 22:23:00 +08:00
|
|
|
const { checkElementLengthEqualTo, checkElementLengthDifferentTo, checkElementText, checkElement } = require('../core/util');
|
2020-06-09 03:40:28 +08:00
|
|
|
|
2020-05-13 21:53:14 +08:00
|
|
|
async function autoJoinTest(test) {
|
2021-08-20 04:22:31 +08:00
|
|
|
try {
|
2021-09-22 11:51:29 +08:00
|
|
|
const resp = await test.page.evaluate(checkElementLengthEqualTo, e.audioModal, 0);
|
2021-08-20 04:22:31 +08:00
|
|
|
return resp === true;
|
2021-09-03 02:31:24 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2021-08-20 04:22:31 +08:00
|
|
|
return false;
|
|
|
|
}
|
2020-05-13 21:53:14 +08:00
|
|
|
}
|
|
|
|
|
2020-05-13 23:26:30 +08:00
|
|
|
async function listenOnlyMode(test) {
|
2021-08-20 04:22:31 +08:00
|
|
|
// maybe not used
|
2020-05-13 23:26:30 +08:00
|
|
|
try {
|
2021-09-22 11:51:29 +08:00
|
|
|
const resp = await test.page.evaluate(async (connectionSelector, echoYesButton) => {
|
2021-08-20 04:22:31 +08:00
|
|
|
await document.querySelectorAll(connectionSelector)[0];
|
2021-09-22 11:51:29 +08:00
|
|
|
return document.querySelectorAll(echoYesButton).length !== 0;
|
|
|
|
}, e.connectingStatus, e.echoYesButton);
|
2021-08-20 04:22:31 +08:00
|
|
|
return resp === true;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2020-05-13 23:26:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 00:54:56 +08:00
|
|
|
async function forceListenOnly(test) {
|
|
|
|
try {
|
2021-09-22 11:51:29 +08:00
|
|
|
const checkEchoYes = await test.page.evaluate(checkElementLengthEqualTo, e.echoYesButton, 0);
|
2021-08-21 04:33:57 +08:00
|
|
|
if (!checkEchoYes) return false;
|
2021-09-22 11:51:29 +08:00
|
|
|
const resp = await test.page.evaluate(checkElementText, e.toastContainer, 'You have joined the audio conference');
|
2021-08-21 04:33:57 +08:00
|
|
|
|
2021-08-20 04:22:31 +08:00
|
|
|
return resp === true;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2021-08-20 04:22:31 +08:00
|
|
|
return false
|
2020-05-14 00:54:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:49:03 +08:00
|
|
|
async function skipCheck(test) {
|
2021-08-20 04:22:31 +08:00
|
|
|
// maybe not used
|
2020-05-15 22:49:03 +08:00
|
|
|
try {
|
2021-09-22 21:11:56 +08:00
|
|
|
await test.waitForSelector(e.toastContainer);
|
2021-08-21 04:33:57 +08:00
|
|
|
const resp1 = await test.page.evaluate(checkElementLengthDifferentTo, e.toastContainer, 0);
|
2021-09-22 21:11:56 +08:00
|
|
|
await test.waitForSelector(e.muteMicrophoneBtn);
|
2021-09-22 11:51:29 +08:00
|
|
|
const resp2 = await test.page.evaluate(checkElementLengthDifferentTo, e.muteMicrophoneBtn, 0);
|
2020-06-16 01:21:44 +08:00
|
|
|
return resp1 === true && resp2 === true;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2021-08-20 04:22:31 +08:00
|
|
|
return false;
|
2020-05-15 22:49:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-02 02:42:56 +08:00
|
|
|
function hexToRgb(hex) {
|
|
|
|
const bigint = parseInt(hex, 16);
|
|
|
|
const r = (bigint >> 16) & 255;
|
|
|
|
const g = (bigint >> 8) & 255;
|
|
|
|
const b = bigint & 255;
|
|
|
|
return `rgb(${r}, ${g}, ${b})`;
|
|
|
|
}
|
|
|
|
|
2020-06-09 03:40:28 +08:00
|
|
|
async function zoomIn(test) {
|
|
|
|
try {
|
2021-08-20 04:22:31 +08:00
|
|
|
await test.page.evaluate((zoomIn) => {
|
2020-06-09 03:40:28 +08:00
|
|
|
setInterval(() => {
|
2021-08-20 04:22:31 +08:00
|
|
|
document.querySelector(zoomIn).scrollBy(0, 10);
|
2020-06-09 03:40:28 +08:00
|
|
|
}, 100);
|
2021-08-20 04:22:31 +08:00
|
|
|
}, e.zoomIn);
|
2020-06-09 03:40:28 +08:00
|
|
|
return true;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2020-06-09 03:40:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function zoomOut(test) {
|
|
|
|
try {
|
2021-08-20 04:22:31 +08:00
|
|
|
await test.page.evaluate((zoomIn) => {
|
2020-06-09 03:40:28 +08:00
|
|
|
setInterval(() => {
|
2021-08-20 04:22:31 +08:00
|
|
|
document.querySelector(zoomIn).scrollBy(10, 0);
|
2020-06-09 03:40:28 +08:00
|
|
|
}, 100);
|
2021-08-20 04:22:31 +08:00
|
|
|
}, e.zoomIn);
|
|
|
|
return true;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2020-06-09 03:40:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-17 04:57:10 +08:00
|
|
|
async function poll(page1, page2) {
|
2020-06-09 03:40:28 +08:00
|
|
|
try {
|
2021-09-22 21:11:56 +08:00
|
|
|
await page1.waitForSelector(e.whiteboard, ELEMENT_WAIT_LONGER_TIME);
|
|
|
|
await page1.waitAndClick(e.actions);
|
|
|
|
await page1.waitAndClick(e.polling);
|
|
|
|
await page1.waitAndClick(e.pollYesNoAbstentionBtn);
|
|
|
|
await page1.waitAndClick(e.startPoll);
|
|
|
|
await page2.waitForSelector(e.pollingContainer);
|
|
|
|
await page2.waitAndClick(e.yesBtn);
|
2021-10-20 04:12:00 +08:00
|
|
|
await page1.waitAndClick(e.publishPollingLabel);
|
2020-06-09 03:40:28 +08:00
|
|
|
return true;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2020-06-09 03:40:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function previousSlide(test) {
|
|
|
|
try {
|
2021-09-22 21:11:56 +08:00
|
|
|
await test.waitAndClick(e.prevSlide);
|
2020-06-09 03:40:28 +08:00
|
|
|
return true;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2020-06-09 03:40:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function nextSlide(test) {
|
|
|
|
try {
|
2021-09-22 21:11:56 +08:00
|
|
|
await test.waitAndClick(e.nextSlide);
|
2020-06-09 03:40:28 +08:00
|
|
|
return true;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2020-06-09 03:40:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function annotation(test) {
|
2021-09-22 21:11:56 +08:00
|
|
|
await test.waitAndClick(e.tools);
|
|
|
|
await test.waitAndClick(e.pencil);
|
|
|
|
await test.waitAndClick(e.whiteboard);
|
2021-08-20 04:22:31 +08:00
|
|
|
const annoted = await test.page.evaluate((whiteboard) => {
|
|
|
|
return document.querySelectorAll(`${whiteboard} > g > g`)[1].innerHTML !== '';
|
|
|
|
}, e.whiteboard);
|
|
|
|
return annoted === true;
|
2020-06-09 03:40:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async function presetationUpload(test) {
|
|
|
|
try {
|
2021-09-22 21:11:56 +08:00
|
|
|
await test.waitAndClick(e.actions);
|
|
|
|
await test.waitAndClick(e.uploadPresentation);
|
2021-09-22 11:51:29 +08:00
|
|
|
const elementHandle = await test.page.$(e.fileUpload);
|
2021-08-15 03:43:44 +08:00
|
|
|
await elementHandle.uploadFile(path.join(__dirname, `../media/${e.pdfFileName}.pdf`));
|
2021-09-22 21:11:56 +08:00
|
|
|
await test.waitAndClick(e.confirmBtn);
|
2020-06-09 03:40:28 +08:00
|
|
|
return true;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2020-06-09 03:40:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-03 01:46:17 +08:00
|
|
|
function encodeCustomParams(param) {
|
|
|
|
try {
|
|
|
|
let splited = param.split('=');
|
|
|
|
splited[1] = encodeURIComponent(splited[1]).replace(/%20/g, '+');
|
|
|
|
return splited.join('=');
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2021-08-03 01:46:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 22:23:00 +08:00
|
|
|
function getAllShortcutParams() {
|
|
|
|
const getParams = (shortcutArray) => {
|
|
|
|
return Object.values(shortcutArray.map(e => `"${e.param}"`));
|
|
|
|
}
|
|
|
|
return c.shortcuts.replace('$', [...getParams(c.initialShortcuts), ...getParams(c.laterShortcuts)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function checkAccesskey(test, key) {
|
|
|
|
return test.page.evaluate(checkElement, `[accesskey="${key}"]`);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function checkShortcutsArray(test, shortcut) {
|
|
|
|
for (const { param, key } of shortcut) {
|
|
|
|
const resp = await checkAccesskey(test, key);
|
|
|
|
if (!resp) {
|
|
|
|
await test.logger(`${param} shortcut failed`)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-09 03:40:28 +08:00
|
|
|
exports.zoomIn = zoomIn;
|
|
|
|
exports.zoomOut = zoomOut;
|
|
|
|
exports.poll = poll;
|
|
|
|
exports.previousSlide = previousSlide;
|
|
|
|
exports.nextSlide = nextSlide;
|
|
|
|
exports.annotation = annotation;
|
|
|
|
exports.presetationUpload = presetationUpload;
|
2020-06-02 02:42:56 +08:00
|
|
|
exports.hexToRgb = hexToRgb;
|
2020-05-13 21:53:14 +08:00
|
|
|
exports.autoJoinTest = autoJoinTest;
|
2020-05-13 23:26:30 +08:00
|
|
|
exports.listenOnlyMode = listenOnlyMode;
|
2020-05-15 22:49:03 +08:00
|
|
|
exports.forceListenOnly = forceListenOnly;
|
|
|
|
exports.skipCheck = skipCheck;
|
2021-08-03 01:46:17 +08:00
|
|
|
exports.encodeCustomParams = encodeCustomParams;
|
2021-10-18 22:23:00 +08:00
|
|
|
exports.getAllShortcutParams = getAllShortcutParams;
|
|
|
|
exports.checkAccesskey = checkAccesskey;
|
|
|
|
exports.checkShortcutsArray = checkShortcutsArray;
|