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

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-03-21 23:04:43 +08:00
const { expect } = require("@playwright/test");
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;
}
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,
};
}
2021-12-01 13:36:20 +08:00
exports.checkElement = checkElement;
2021-12-04 01:01:36 +08:00
exports.checkElementLengthEqualTo = checkElementLengthEqualTo;
2022-03-21 23:04:43 +08:00
exports.checkTextContent = checkTextContent;
2023-03-08 23:33:05 +08:00
exports.constructClipObj = constructClipObj;