2021-11-27 04:01:41 +08:00
|
|
|
const e = require('../core/elements');
|
|
|
|
const { sleep } = require('../core/helpers');
|
2023-03-29 22:16:47 +08:00
|
|
|
const { LOOP_INTERVAL, ELEMENT_WAIT_LONGER_TIME, ELEMENT_WAIT_TIME } = require('../core/constants');
|
|
|
|
const { expect } = require('@playwright/test');
|
|
|
|
const { resolve } = require('path');
|
2021-11-27 04:01:41 +08:00
|
|
|
|
2022-05-24 05:30:30 +08:00
|
|
|
// loop 5 times, every LOOP_INTERVAL milliseconds, and check that all
|
|
|
|
// videos displayed are changing by comparing a hash of their
|
|
|
|
// displayed contents
|
|
|
|
|
2021-11-27 04:01:41 +08:00
|
|
|
async function webcamContentCheck(test) {
|
2022-02-03 08:05:26 +08:00
|
|
|
await test.waitForSelector(e.webcamVideoItem);
|
2021-11-27 04:01:41 +08:00
|
|
|
await test.wasRemoved(e.webcamConnecting, ELEMENT_WAIT_LONGER_TIME);
|
|
|
|
const repeats = 5;
|
|
|
|
let check;
|
|
|
|
for (let i = repeats; i >= 1; i--) {
|
|
|
|
console.log(`loop ${i}`);
|
2022-07-27 03:51:56 +08:00
|
|
|
const checkCameras = async () => {
|
2021-11-27 04:01:41 +08:00
|
|
|
const videos = document.querySelectorAll('video');
|
2022-05-24 05:30:30 +08:00
|
|
|
const lastVideoHash = document.lastVideoHash || {};
|
|
|
|
document.lastVideoHash = lastVideoHash;
|
|
|
|
|
2021-11-27 04:01:41 +08:00
|
|
|
for (let v = 0; v < videos.length; v++) {
|
|
|
|
const video = videos[v];
|
|
|
|
const canvas = document.createElement('canvas');
|
|
|
|
const context = canvas.getContext('2d');
|
|
|
|
context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
|
2022-05-24 05:30:30 +08:00
|
|
|
const pixel = context.getImageData(0, 0, video.videoWidth, video.videoHeight).data;
|
2022-07-27 03:51:56 +08:00
|
|
|
const pixelHash = await window.crypto.subtle.digest('SHA-1', pixel);
|
2021-11-27 04:01:41 +08:00
|
|
|
|
2022-05-24 05:30:30 +08:00
|
|
|
if (lastVideoHash[v]) {
|
|
|
|
if (lastVideoHash[v] == pixelHash) {
|
2021-11-27 04:01:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-05-24 05:30:30 +08:00
|
|
|
lastVideoHash[v] = pixelHash;
|
2021-11-27 04:01:41 +08:00
|
|
|
}
|
2021-12-08 21:09:58 +08:00
|
|
|
return true;
|
2021-11-27 04:01:41 +08:00
|
|
|
};
|
|
|
|
|
2022-07-27 03:51:56 +08:00
|
|
|
check = await test.page.evaluate(checkCameras);
|
2021-11-27 04:01:41 +08:00
|
|
|
if (!check) return false;
|
|
|
|
await sleep(LOOP_INTERVAL);
|
|
|
|
}
|
|
|
|
return check === true;
|
|
|
|
}
|
|
|
|
|
2023-03-29 22:16:47 +08:00
|
|
|
async function checkVideoUploadData(testPage, previousValue, timeout = ELEMENT_WAIT_TIME) {
|
|
|
|
const locator = testPage.getLocator(e.videoUploadRateData);
|
|
|
|
await expect(locator).not.toHaveText('0k ↑', { timeout });
|
|
|
|
const currentValue = await Number((await locator.textContent()).split('k')[0]);
|
|
|
|
await expect(currentValue).toBeGreaterThan(previousValue);
|
|
|
|
return currentValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function uploadBackgroundVideoImage(testPage) {
|
|
|
|
const [fileChooser] = await Promise.all([
|
|
|
|
testPage.page.waitForEvent('filechooser'),
|
|
|
|
testPage.waitAndClick(e.inputBackgroundButton),
|
|
|
|
]);
|
|
|
|
await fileChooser.setFiles(resolve(__dirname, '../core/media/simpsons-background.png'));
|
|
|
|
const uploadedBackgroundLocator = testPage.getLocator(e.selectCustomBackground);
|
2023-06-08 10:17:42 +08:00
|
|
|
await expect(uploadedBackgroundLocator).toHaveScreenshot('custom-background-item.png');
|
2023-03-29 22:16:47 +08:00
|
|
|
}
|
|
|
|
|
2021-12-04 01:01:36 +08:00
|
|
|
exports.webcamContentCheck = webcamContentCheck;
|
2023-03-29 22:16:47 +08:00
|
|
|
exports.checkVideoUploadData = checkVideoUploadData;
|
|
|
|
exports.uploadBackgroundVideoImage = uploadBackgroundVideoImage;
|