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

58 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-03-21 23:04:43 +08:00
const { expect } = require("@playwright/test");
const { exec } = require('child_process');
2022-03-21 23:04:43 +08:00
2021-11-26 02:23:58 +08:00
// Common
2021-12-01 22:02:26 +08:00
function checkElement([element, index = 0]) {
/* Because this function is passed to a page.evaluate, it can only
* take a single argument; that's why we pass it an array. It's so
* easy to pass it a string by mistake that we check to make sure
* the second argument is an integer and not a character from a
* destructured string.
*/
if (typeof index != "number") {
throw Error("Assert failed: index not a number");
}
2021-11-26 02:23:58 +08:00
return document.querySelectorAll(element)[index] !== undefined;
}
// Length
2021-12-01 13:36:20 +08:00
function checkElementLengthEqualTo([element, count]) {
return document.querySelectorAll(element).length == count;
}
function getElementLength(element) {
return document.querySelectorAll(element).length;
}
2022-03-21 23:04:43 +08:00
// Text
async function checkTextContent(baseContent, checkData) {
2022-03-29 21:53:07 +08:00
if (typeof checkData === 'string') checkData = new Array(checkData);
2022-03-21 23:04:43 +08:00
const check = checkData.every(word => baseContent.includes(word));
await expect(check).toBeTruthy();
}
2023-03-08 23:33:05 +08:00
function constructClipObj(wbBox) {
return {
x: wbBox.x,
y: wbBox.y,
width: wbBox.width,
height: wbBox.height,
};
2023-03-08 23:33:05 +08:00
}
async function runScript(script, { handleError, handleOutput, timeout }) {
return new Promise((res, rej) => {
return exec(script, { timeout }, (err, stdout, stderr) => {
res(handleError ? handleError(stderr) : handleOutput ? handleOutput(stdout) : null)
})
})
}
2021-12-01 13:36:20 +08:00
exports.checkElement = checkElement;
2021-12-04 01:01:36 +08:00
exports.checkElementLengthEqualTo = checkElementLengthEqualTo;
exports.getElementLength = getElementLength;
2022-03-21 23:04:43 +08:00
exports.checkTextContent = checkTextContent;
2023-03-08 23:33:05 +08:00
exports.constructClipObj = constructClipObj;
exports.runScript = runScript;