Merge pull request #8891 from daminebenq/webcams-test-fixes
Webcams test fixes
This commit is contained in:
commit
54fa9c8ddb
@ -159,7 +159,7 @@ class VideoListItem extends Component {
|
||||
>
|
||||
{
|
||||
!videoIsReady
|
||||
&& <div className={styles.connecting} />
|
||||
&& <div data-test="webcamConnecting" className={styles.connecting} />
|
||||
}
|
||||
<div
|
||||
className={styles.videoContainer}
|
||||
|
@ -1,13 +1,13 @@
|
||||
const Share = require('./webcam/share');
|
||||
const Check = require('./webcam/check');
|
||||
const LoadingTime = require('./webcam/loadtime');
|
||||
const Page = require('./core/page');
|
||||
|
||||
describe('Webcam', () => {
|
||||
test('Shares webcam', async () => {
|
||||
const test = new Share();
|
||||
let response;
|
||||
try {
|
||||
await test.init();
|
||||
await test.init(Page.getArgsWithVideo());
|
||||
response = await test.test();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
@ -17,25 +17,11 @@ describe('Webcam', () => {
|
||||
expect(response).toBe(true);
|
||||
});
|
||||
|
||||
test('Check Webcam loading time', async () => {
|
||||
const test = new LoadingTime();
|
||||
let response;
|
||||
try {
|
||||
await test.init();
|
||||
response = await test.test();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
} finally {
|
||||
await test.close();
|
||||
}
|
||||
expect(response).toBeLessThan(parseInt(process.env.CAMERA_SHARE_FAILED_WAIT_TIME));
|
||||
});
|
||||
|
||||
test('Checks content of webcam', async () => {
|
||||
const test = new Check();
|
||||
let response;
|
||||
try {
|
||||
await test.init();
|
||||
await test.init(Page.getArgsWithVideo());
|
||||
response = await test.test();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
@ -7,11 +7,9 @@ class Check extends Share {
|
||||
}
|
||||
|
||||
async test() {
|
||||
await util.startAndCheckForWebcams(this.page1);
|
||||
await util.startAndCheckForWebcams(this.page2);
|
||||
const responseUser1 = await util.webcamContentCheck(this.page1);
|
||||
const responseUser2 = await util.webcamContentCheck(this.page2);
|
||||
return responseUser1 && responseUser2;
|
||||
await util.enableWebcam(this.page);
|
||||
const respUser = await util.webcamContentCheck(this.page);
|
||||
return respUser === true;
|
||||
}
|
||||
}
|
||||
module.exports = exports = Check;
|
||||
|
@ -2,5 +2,4 @@ exports.joinVideo = 'button[data-test="joinVideo"]';
|
||||
exports.videoPreview = 'video[data-test="videoPreview"]';
|
||||
exports.startSharingWebcam = 'button[data-test="startSharingWebcam"]';
|
||||
exports.videoContainer = 'video[data-test="videoContainer"]';
|
||||
exports.webcamConnectingStatus = '[data-test="webcamConnectingStatus"]';
|
||||
exports.presentationFullscreenButton = '[data-test="presentationFullscreenButton"]';
|
||||
exports.webcamConnecting = '[data-test="webcamConnecting"]';
|
||||
|
@ -1,19 +0,0 @@
|
||||
const Share = require('./share');
|
||||
const util = require('./util');
|
||||
|
||||
class LoadingTime extends Share {
|
||||
constructor() {
|
||||
super('check-webcam-loading-time');
|
||||
}
|
||||
|
||||
async test() {
|
||||
await util.enableWebcam(this.page1);
|
||||
await util.enableWebcam(this.page2);
|
||||
const now = new Date().getMilliseconds();
|
||||
await util.waitForWebcamsLoading(this.page1);
|
||||
await util.waitForWebcamsLoading(this.page2);
|
||||
const end = new Date().getMilliseconds();
|
||||
return end - now;
|
||||
}
|
||||
}
|
||||
module.exports = exports = LoadingTime;
|
@ -1,29 +1,15 @@
|
||||
const Page = require('../core/page');
|
||||
const util = require('./util');
|
||||
const params = require('../params');
|
||||
|
||||
class Share {
|
||||
class Share extends Page{
|
||||
constructor() {
|
||||
this.page1 = new Page();
|
||||
this.page2 = new Page();
|
||||
}
|
||||
|
||||
async init(meetingId) {
|
||||
await this.page1.init(Page.getArgsWithVideo(), meetingId, { ...params, fullName: 'Streamer1' });
|
||||
await this.page2.init(Page.getArgsWithVideo(), this.page1.meetingId, { ...params, fullName: 'Streamer2' });
|
||||
super('webcam-test');
|
||||
}
|
||||
|
||||
async test() {
|
||||
await util.enableWebcam(this.page1);
|
||||
await util.enableWebcam(this.page2);
|
||||
const responseUser1 = await util.evaluateCheck(this.page1);
|
||||
const responseUser2 = await util.evaluateCheck(this.page2);
|
||||
return responseUser1 && responseUser2;
|
||||
}
|
||||
|
||||
async close() {
|
||||
await this.page1.close();
|
||||
await this.page2.close();
|
||||
await util.enableWebcam(this.page);
|
||||
const response = await util.evaluateCheck(this.page);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,10 @@ const we = require('./elements');
|
||||
async function enableWebcam(test) {
|
||||
// Enabling webcam
|
||||
await test.waitForSelector(we.joinVideo);
|
||||
await test.click(we.joinVideo, true);
|
||||
await test.click(we.joinVideo);
|
||||
await test.waitForSelector(we.videoPreview);
|
||||
await test.waitForSelector(we.startSharingWebcam);
|
||||
await test.click(we.startSharingWebcam, true);
|
||||
await test.click(we.startSharingWebcam);
|
||||
}
|
||||
|
||||
async function getTestElement(element) {
|
||||
@ -15,8 +15,7 @@ async function getTestElement(element) {
|
||||
|
||||
async function evaluateCheck(test) {
|
||||
await test.waitForSelector(we.videoContainer);
|
||||
await test.waitForSelector(we.webcamConnectingStatus);
|
||||
const videoContainer = await test.page.evaluate(getTestElement, we.presentationFullscreenButton);
|
||||
const videoContainer = await test.evaluate(getTestElement, we.presentationFullscreenButton);
|
||||
const response = videoContainer !== null;
|
||||
return response;
|
||||
}
|
||||
@ -27,35 +26,41 @@ async function startAndCheckForWebcams(test) {
|
||||
return response;
|
||||
}
|
||||
|
||||
async function checkCameras() {
|
||||
const videos = document.querySelectorAll('video');
|
||||
const lastVideoColor = document.lastVideoColor || {};
|
||||
document.lastVideoColor = lastVideoColor;
|
||||
|
||||
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);
|
||||
const pixel = context.getImageData(50, 50, 1, 1).data;
|
||||
const pixelString = new Array(pixel).join(' ').toString();
|
||||
|
||||
if (lastVideoColor[v]) {
|
||||
if (lastVideoColor[v] == pixelString) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return lastVideoColor[v] !== pixelString === true;
|
||||
}
|
||||
}
|
||||
|
||||
async function webcamContentCheck(test) {
|
||||
await test.waitForSelector(we.videoContainer);
|
||||
await test.waitForFunction(() => !document.querySelector('[data-test="webcamConnecting"]'));
|
||||
|
||||
const repeats = 5;
|
||||
let check;
|
||||
for (let i = repeats; i >= 0; i--) {
|
||||
await test.page.waitFor(parseInt(process.env.LOOP_INTERVAL));
|
||||
return check = await test.page.evaluate(checkCameras);
|
||||
for (let i = repeats; i >= 1; i--) {
|
||||
console.log(`loop ${i}`);
|
||||
const checkCameras = function (i) {
|
||||
const videos = document.querySelectorAll('video');
|
||||
const lastVideoColor = document.lastVideoColor || {};
|
||||
document.lastVideoColor = lastVideoColor;
|
||||
|
||||
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);
|
||||
const pixel = context.getImageData(50, 50, 1, 1).data;
|
||||
const pixelString = new Array(pixel).join(' ').toString();
|
||||
|
||||
if (lastVideoColor[v]) {
|
||||
if (lastVideoColor[v] == pixelString) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
lastVideoColor[v] = pixelString;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
check = await test.evaluate(checkCameras, i);
|
||||
await test.waitFor(parseInt(process.env.LOOP_INTERVAL));
|
||||
}
|
||||
return check === true;
|
||||
}
|
||||
|
||||
exports.startAndCheckForWebcams = startAndCheckForWebcams;
|
||||
|
Loading…
Reference in New Issue
Block a user