bigbluebutton-Github/bigbluebutton-tests/puppeteer/user/multiusers.js

366 lines
13 KiB
JavaScript
Raw Normal View History

const Page = require('../core/page');
const util = require('../chat/util');
const utilUser = require('./util');
const e = require('../core/elements');
2021-08-21 04:33:57 +08:00
const { ELEMENT_WAIT_TIME } = require('../core/constants');
const { getElementLength, checkElementLengthEqualTo, checkElementLengthDifferentTo } = require('../core/util');
class MultiUsers {
constructor() {
this.page1 = new Page();
this.page2 = new Page();
2021-09-23 05:03:12 +08:00
this.userPage = new Page();
}
// Join BigBlueButton meeting
2021-09-30 20:36:08 +08:00
async init(testFolderName) {
await this.initMod1(testFolderName);
await this.page2.init(true, true, testFolderName, 'Mod2', this.page1.meetingId);
2021-09-23 05:03:12 +08:00
}
2021-09-30 20:36:08 +08:00
async initMod1(testFolderName) {
await this.page1.init(true, true, testFolderName, 'Mod1')
}
// Join BigBlueButton meeting
2021-09-30 20:36:08 +08:00
async initUserPage(shouldCloseAudioModal, testFolderName) {
await this.userPage.init(false, shouldCloseAudioModal, testFolderName, 'Attendee', this.page1.meetingId);
}
// Run the test for the page
async checkForOtherUser() {
const firstCheck = await this.page1.page.evaluate(getElementLength, e.userListItem) > 0;
const secondCheck = await this.page1.page.evaluate(getElementLength, e.userListItem) > 0;
return {
firstCheck,
secondCheck,
};
}
2021-09-23 01:05:34 +08:00
async multiUsersPublicChat(testName) {
try {
const chat0 = await this.page1.page.evaluate(getElementLength, e.chatUserMessageText);
2021-09-23 01:05:34 +08:00
await util.sendPublicChatMessage(this.page1, this.page2, testName);
const chat1 = await this.page1.page.evaluate(getElementLength, e.chatUserMessageText);
2021-09-23 01:05:34 +08:00
return chat0 !== chat1;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
2021-09-23 01:05:34 +08:00
async multiUsersPrivateChat(testName) {
try {
await util.openPrivateChatMessage(this.page1, this.page2);
const chat0 = await this.page1.page.evaluate(checkElementLengthEqualTo, e.chatUserMessageText, 0);
2021-09-23 01:05:34 +08:00
await util.sendPrivateChatMessage(this.page1, this.page2, testName);
const receivedMessages = await this.page1.hasElement(e.chatUserMessageText, true) && await this.page2.hasElement(e.chatUserMessageText, true);
return chat0 && receivedMessages;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
async test() {
try {
const checks = await this.checkForOtherUser();
return checks.firstCheck !== false && checks.secondCheck !== false;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
async randomPoll(testName) {
try {
await this.page1.startRecording(testName);
2021-03-09 05:11:36 +08:00
await this.page2.startRecording(testName);
2021-09-30 20:36:08 +08:00
await this.page1.waitAndClick(e.actions);
await this.page1.waitAndClick(e.polling);
await this.page1.waitForSelector(e.pollQuestionArea);
await this.page1.page.focus(e.pollQuestionArea);
await this.page1.page.keyboard.type(e.pollQuestion);
2021-08-20 04:22:31 +08:00
const chosenRandomNb = await this.page1.page.evaluate((responseTypes) => {
const responseTypesDiv = document.querySelector(responseTypes);
const buttons = responseTypesDiv.querySelectorAll('button');
const countButtons = buttons.length;
const randomNb = Math.floor(Math.random() * countButtons) + 1;
const chosenRandomNb = randomNb - 1;
responseTypesDiv.querySelectorAll('button')[chosenRandomNb].click();
return chosenRandomNb;
}, e.responseTypes);
2021-03-09 05:11:36 +08:00
const customs = {
0: e.uncertain,
2021-03-09 05:11:36 +08:00
1: 0,
2: 'ABSTENTION',
3: 'All good!',
};
switch (chosenRandomNb) {
case 0:
2021-03-09 05:11:36 +08:00
// Adding a poll option
await this.page1.waitForSelector(e.responseChoices);
await this.page1.waitAndClick(e.addItem);
await this.page1.waitAndClick(e.pollOptionItem);
await this.page1.tab(2);
2021-03-09 05:11:36 +08:00
await this.page1.page.keyboard.type(customs[0]);
break;
case 1:
2021-03-09 05:11:36 +08:00
// Deleting a poll option
await this.page1.waitForSelector(e.deletePollOption);
await this.page1.clickNItem(e.deletePollOption, customs[1]);
break;
case 2:
2021-03-09 05:11:36 +08:00
// Editing a poll option
await this.page1.waitForSelector(e.responseChoices);
await this.page1.clickNItem(e.pollOptionItem, 2);
2021-03-09 05:11:36 +08:00
await this.page1.hold('Control');
await this.page1.press('KeyA');
await this.page1.release('Control');
await this.page1.page.keyboard.type(customs[2]);
await this.page1.tab(1);
break;
case 3:
2021-03-09 05:11:36 +08:00
// Do nothing to let Users write their single response answer
await this.page1.waitForSelector(e.responseChoices);
break;
}
2021-03-09 05:11:36 +08:00
const condition = chosenRandomNb === 0 || chosenRandomNb === 1 || chosenRandomNb === 2;
await this.page1.waitAndClick(e.startPoll);
await this.page2.waitForSelector(e.pollingContainer);
2021-03-09 05:11:36 +08:00
switch (condition) {
case true:
await this.page2.clickNItem(e.pollAnswerOptionBtn, 2);
2021-03-09 05:11:36 +08:00
break;
case false:
await this.page2.page.focus(e.pollAnswerOptionInput);
2021-03-09 05:11:36 +08:00
await this.page2.page.keyboard.type(customs[3]);
await this.page2.waitAndClick(e.pollSubmitAnswer);
2021-03-09 05:11:36 +08:00
break;
}
const receivedAnswerFound = await this.page1.hasElement(e.receivedAnswer, true);
await this.page1.waitAndClick(e.publishLabel, ELEMENT_WAIT_TIME, true);
await this.page1.waitForSelector(e.restartPoll);
const isPollResultsPublished = await this.page1.hasElement(e.pollResults, true);
return receivedAnswerFound && isPollResultsPublished;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
2021-09-23 05:03:12 +08:00
async askModeratorGuestPolicy(testName) {
try {
2021-09-30 20:36:08 +08:00
await this.initMod1(testName);
await this.page1.screenshot(`${testName}`, `01-after-closing-audio-modal-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
await this.page1.waitAndClick(e.manageUsers);
2021-09-30 20:36:08 +08:00
await this.page1.screenshot(`${testName}`, `02-opened-users-managing-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
await this.page1.waitAndClick(e.guestPolicyLabel);
2021-09-30 20:36:08 +08:00
await this.page1.screenshot(`${testName}`, `03-opened-guest-policy-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
await this.page1.waitAndClick(e.askModerator);
2021-09-30 20:36:08 +08:00
await this.page1.screenshot(`${testName}`, `04-clicked-askModerator-[${this.page1.meetingId}]`);
await this.initUserPage(false, testName);
2021-09-23 05:03:12 +08:00
await this.page1.bringToFront();
const responseLoggedIn = await this.page1.hasElement(e.waitingUsersBtn);
2021-09-30 20:36:08 +08:00
await this.page1.screenshot(`${testName}`, `05-after-viewer-acceptance-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
return responseLoggedIn;
} catch (err) {
await this.page1.logger(err);
return false;
}
}
async alwaysAcceptGuestPolicy(testName) {
try {
2021-09-30 20:36:08 +08:00
await this.initMod1(testName);
await this.page1.screenshot(`${testName}`, `01-after-closing-audio-modal-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
await this.page1.waitAndClick(e.manageUsers);
2021-09-30 20:36:08 +08:00
await this.page1.screenshot(`${testName}`, `02-opened-users-managing-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
await this.page1.waitAndClick(e.guestPolicyLabel);
2021-09-30 20:36:08 +08:00
await this.page1.screenshot(`${testName}`, `03-opened-guest-policy-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
await this.page1.waitAndClick(e.alwaysAccept);
2021-09-30 20:36:08 +08:00
await this.page1.screenshot(`${testName}`, `04-clicked-alwaysAccept-[${this.page1.meetingId}]`);
await this.initUserPage(false, testName);
2021-09-23 05:03:12 +08:00
const responseLoggedIn = await this.userPage.hasElement(e.whiteboard);
2021-09-30 20:36:08 +08:00
await this.userPage.screenshot(`${testName}`, `05-after-viewer-connection-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
return responseLoggedIn;
} catch (err) {
await this.page1.logger(err);
return false;
}
}
async alwaysDenyGuestPolicy(testName) {
try {
2021-09-30 20:36:08 +08:00
await this.initMod1(testName);
await this.page1.screenshot(`${testName}`, `01-after-closing-audio-modal-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
await this.page1.waitAndClick(e.manageUsers);
2021-09-30 20:36:08 +08:00
await this.page1.screenshot(`${testName}`, `02-opened-users-managing-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
await this.page1.waitAndClick(e.guestPolicyLabel);
2021-09-30 20:36:08 +08:00
await this.page1.screenshot(`${testName}`, `03-opened-guest-policy-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
await this.page1.waitAndClick(e.alwaysDeny);
2021-09-30 20:36:08 +08:00
await this.page1.screenshot(`${testName}`, `04-clicked-alwaysAccept-[${this.page1.meetingId}]`);
await this.initUserPage(false, testName);
2021-09-23 05:03:12 +08:00
const responseLoggedIn = await this.userPage.hasElement(e.joinMeetingDemoPage);
2021-09-30 20:36:08 +08:00
await this.userPage.screenshot(`${testName}`, `05-after-viewer-gets-denied-[${this.page1.meetingId}]`);
2021-09-23 05:03:12 +08:00
return responseLoggedIn;
} catch (err) {
await this.page1.logger(err);
return false;
}
}
async testWhiteboardAccess() {
try {
await this.page1.waitForSelector(e.whiteboard);
2021-09-23 05:03:12 +08:00
await this.page1.waitAndClick(e.userListItem);
await this.page1.waitAndClick(e.changeWhiteboardAccess);
await this.page1.waitForSelector(e.multiWhiteboardTool);
const resp = await this.page1.page.evaluate((multiWhiteboardTool) => {
return document.querySelector(multiWhiteboardTool).children[0].innerText === '1';
}, e.multiWhiteboardTool);
return resp === true;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
// Raise Hand
async raiseHandTest() {
try {
await this.page2.waitAndClick(e.raiseHandLabel);
const resp = await this.page2.hasElement(e.lowerHandLabel, true);
return resp === true;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
// Lower Hand
async lowerHandTest() {
try {
await this.page2.waitAndClick(e.lowerHandLabel);
await this.page2.waitAndClick(e.lowerHandLabel, ELEMENT_WAIT_TIME, true);
const resp = await this.page2.hasElement(e.raiseHandLabel, true);
return resp === true;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page2.logger(err);
return false;
}
}
// Get Avatars Colors from Userlist and Notification toast
async getAvatarColorAndCompareWithUserListItem() {
try {
const avatarInToastElementColor = await this.page1.page.$eval(e.avatarsWrapperAvatar, (elem) => getComputedStyle(elem).backgroundColor);
const avatarInUserListColor = await this.page1.page.$eval(`${e.userListItem} > div ${e.userAvatar}`, (elem) => getComputedStyle(elem).backgroundColor);
return avatarInToastElementColor === avatarInUserListColor;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
async userOfflineWithInternetProblem() {
try {
await this.page2.page.evaluate(() => window.dispatchEvent(new CustomEvent('socketstats', { detail: { rtt: 2000 } })));
await this.page2.page.setOfflineMode(true);
await this.page2.close();
await utilUser.connectionStatus(this.page1);
const connectionStatusItemEmpty = await this.page1.wasRemoved(e.connectionStatusItemEmpty);
const connectionStatusOfflineUser = await this.page1.hasElement(e.connectionStatusOfflineUser, true);
return connectionStatusItemEmpty && connectionStatusOfflineUser;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
async userlistNotAppearOnMobile() {
try {
const userlistPanel = await this.page1.page.evaluate(checkElementLengthEqualTo, e.chatButtonKey, 0);
const chatPanel = await this.page2.page.evaluate(checkElementLengthEqualTo, e.chatButtonKey, 0);
return userlistPanel && chatPanel;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
async whiteboardNotAppearOnMobile() {
try {
await this.page1.waitAndClick(e.userListButton);
await this.page2.waitAndClick(e.userListButton);
await this.page2.waitAndClick(e.chatButtonKey);
2021-09-22 22:36:58 +08:00
const onUserListPanel = await this.page1.isNotVisible(e.hidePresentation);
const onChatPanel = await this.page2.isNotVisible(e.hidePresentation);
return onUserListPanel && onChatPanel;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
async chatPanelNotAppearOnMobile() {
try {
await this.page2.waitAndClick(e.userListButton);
await this.page2.waitAndClick(e.chatButtonKey);
const whiteboard = await this.page1.page.evaluate(checkElementLengthEqualTo, e.chatButtonKey, 0);
2021-09-22 22:36:58 +08:00
const onChatPanel = await this.page2.isNotVisible(e.chatButtonKey);
return whiteboard && onChatPanel;
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
// Close all Pages
2020-06-17 23:29:43 +08:00
async close(page1, page2) {
try {
await page1.close();
await page2.close();
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
}
2020-03-21 04:31:58 +08:00
2020-03-23 20:15:10 +08:00
async closePage(page) {
try {
await page.close();
2021-08-26 22:13:18 +08:00
} catch (err) {
await this.page1.logger(err);
return false;
}
2020-03-21 04:31:58 +08:00
}
}
2021-09-30 20:36:08 +08:00
module.exports = exports = MultiUsers;