2020-02-08 02:03:06 +08:00
const Page = require ( '../core/page' ) ;
2020-02-10 21:47:24 +08:00
const params = require ( '../params' ) ;
2020-02-20 01:28:27 +08:00
const util = require ( '../chat/util' ) ;
2021-05-26 00:05:11 +08:00
const utilUser = require ( './util' ) ;
2021-03-09 05:11:36 +08:00
const utilCustomParams = require ( '../customparameters/util' ) ;
2021-03-08 07:53:58 +08:00
const pe = require ( '../core/elements' ) ;
const ne = require ( '../notifications/elements' ) ;
const ple = require ( '../polling/elemens' ) ;
2021-03-30 18:49:07 +08:00
const we = require ( '../whiteboard/elements' ) ;
2021-05-26 00:05:11 +08:00
const ue = require ( './elements' ) ;
const cu = require ( '../customparameters/elements' ) ;
const pre = require ( '../presentation/elements' ) ;
2021-03-08 07:53:58 +08:00
const { ELEMENT _WAIT _TIME , ELEMENT _WAIT _LONGER _TIME } = require ( '../core/constants' ) ;
const { sleep } = require ( '../core/helper' ) ;
2020-02-08 02:03:06 +08:00
2020-02-13 04:18:41 +08:00
class MultiUsers {
2020-02-08 02:03:06 +08:00
constructor ( ) {
2020-02-13 04:18:41 +08:00
this . page1 = new Page ( ) ;
this . page2 = new Page ( ) ;
2020-02-22 02:06:05 +08:00
this . page3 = new Page ( ) ;
2020-02-08 02:03:06 +08:00
}
2020-02-13 04:18:41 +08:00
// Join BigBlueButton meeting
2021-02-26 23:52:17 +08:00
async init ( meetingId , testFolderName ) {
await this . page1 . init ( Page . getArgs ( ) , meetingId , params , undefined , testFolderName ) ;
await this . page2 . init ( Page . getArgs ( ) , this . page1 . meetingId , { ... params , fullName : 'User2' } , undefined , testFolderName ) ;
2020-02-08 02:03:06 +08:00
}
2021-03-30 18:49:07 +08:00
// Join BigBlueButton meeting
async initUser3 ( testFolderName ) {
await this . page3 . init ( Page . getArgs ( ) , this . page1 . meetingId , { ... params , fullName : 'User3' } , undefined , testFolderName ) ;
}
2020-02-11 06:09:17 +08:00
// Run the test for the page
async checkForOtherUser ( ) {
2020-02-13 04:18:41 +08:00
const firstCheck = await this . page1 . page . evaluate ( ( ) => document . querySelectorAll ( '[data-test="userListItem"]' ) . length > 0 ) ;
const secondCheck = await this . page2 . page . evaluate ( ( ) => document . querySelectorAll ( '[data-test="userListItem"]' ) . length > 0 ) ;
return {
firstCheck ,
secondCheck ,
} ;
}
2020-02-20 01:28:27 +08:00
async multiUsersPublicChat ( ) {
2021-02-17 04:57:10 +08:00
const chat0 = await this . page1 . page . evaluate ( ( ) => document . querySelectorAll ( 'p[data-test="chatUserMessageText"]' ) . length ) ;
2020-02-20 01:28:27 +08:00
await util . sendPublicChatMessage ( this . page1 , this . page2 ) ;
2021-02-17 04:57:10 +08:00
const chat1 = await this . page1 . page . evaluate ( ( ) => document . querySelectorAll ( 'p[data-test="chatUserMessageText"]' ) . length ) ;
return chat0 !== chat1 ;
2020-02-20 01:28:27 +08:00
}
async multiUsersPrivateChat ( ) {
await util . openPrivateChatMessage ( this . page1 , this . page2 ) ;
2021-02-17 04:57:10 +08:00
const chat0 = await this . page1 . page . evaluate ( ( ) => document . querySelectorAll ( 'p[data-test="chatUserMessageText"]' ) . length ) ;
2020-02-20 01:28:27 +08:00
await util . sendPrivateChatMessage ( this . page1 , this . page2 ) ;
2021-03-30 18:49:07 +08:00
await sleep ( 2000 ) ;
2021-02-17 04:57:10 +08:00
const chat1 = await this . page1 . page . evaluate ( ( ) => document . querySelectorAll ( 'p[data-test="chatUserMessageText"]' ) . length ) ;
return chat0 !== chat1 ;
2020-02-20 01:28:27 +08:00
}
2020-02-13 04:18:41 +08:00
async test ( ) {
2020-02-19 01:18:55 +08:00
const checks = await this . checkForOtherUser ( ) ;
2020-02-13 04:18:41 +08:00
return checks . firstCheck !== false && checks . secondCheck !== false ;
2020-02-08 02:03:06 +08:00
}
2020-02-11 06:09:17 +08:00
2021-03-08 07:53:58 +08:00
async randomPoll ( testName ) {
try {
await this . page1 . startRecording ( testName ) ;
await this . page1 . closeAudioModal ( ) ;
2021-03-09 05:11:36 +08:00
await this . page2 . startRecording ( testName ) ;
2021-03-08 07:53:58 +08:00
await this . page2 . closeAudioModal ( ) ;
await this . page1 . waitForSelector ( pe . actions , ELEMENT _WAIT _TIME ) ;
await this . page1 . click ( pe . actions , true ) ;
await this . page1 . waitForSelector ( ne . polling , ELEMENT _WAIT _TIME ) ;
await this . page1 . click ( ne . polling , true ) ;
await this . page1 . waitForSelector ( ple . pollQuestionArea , ELEMENT _WAIT _TIME ) ;
await this . page1 . page . focus ( ple . pollQuestionArea ) ;
await this . page1 . page . keyboard . type ( ple . pollQuestion ) ;
const chosenRandomNb = await this . page1 . page . evaluate ( ( ) => {
const responseTypesDiv = document . querySelector ( 'div[data-test="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 ;
} ) ;
2021-03-09 05:11:36 +08:00
const customs = {
0 : ple . uncertain ,
1 : 0 ,
2 : 'ABSTENTION' ,
3 : 'All good!' ,
} ;
2021-03-08 07:53:58 +08:00
switch ( chosenRandomNb ) {
case 0 :
2021-03-09 05:11:36 +08:00
// Adding a poll option
2021-03-08 07:53:58 +08:00
console . log ( { chosenRandomNb } , ' <= True / False' ) ;
await this . page1 . waitForSelector ( ple . responseChoices , ELEMENT _WAIT _TIME ) ;
await this . page1 . waitForSelector ( ple . addItem , ELEMENT _WAIT _TIME ) ;
await this . page1 . click ( ple . addItem , true ) ;
await this . page1 . click ( ple . pollOptionItem , true ) ;
await this . page1 . tab ( 2 ) ;
2021-03-09 05:11:36 +08:00
await this . page1 . page . keyboard . type ( customs [ 0 ] ) ;
2021-03-08 07:53:58 +08:00
break ;
case 1 :
2021-03-09 05:11:36 +08:00
// Deleting a poll option
2021-03-08 07:53:58 +08:00
console . log ( { chosenRandomNb } , ' <= A / B / C / D' ) ;
await this . page1 . waitForSelector ( ple . deletePollOption , ELEMENT _WAIT _TIME ) ;
2021-03-09 05:11:36 +08:00
await this . page1 . clickNItem ( ple . deletePollOption , true , customs [ 1 ] ) ;
2021-03-08 07:53:58 +08:00
break ;
case 2 :
2021-03-09 05:11:36 +08:00
// Editing a poll option
2021-03-08 07:53:58 +08:00
console . log ( { chosenRandomNb } , ' <= Yes / No / Abstention' ) ;
2021-03-09 05:11:36 +08:00
await this . page1 . waitForSelector ( ple . responseChoices , ELEMENT _WAIT _TIME ) ;
await this . page1 . clickNItem ( ple . pollOptionItem , true , 2 ) ;
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 ) ;
2021-03-08 07:53:58 +08:00
break ;
case 3 :
2021-03-09 05:11:36 +08:00
// Do nothing to let Users write their single response answer
2021-03-08 07:53:58 +08:00
console . log ( { chosenRandomNb } , ' <= User Response' ) ;
2021-03-09 05:11:36 +08:00
await this . page1 . waitForSelector ( ple . responseChoices , ELEMENT _WAIT _TIME ) ;
await sleep ( 2000 ) ;
2021-03-08 07:53:58 +08:00
break ;
}
2021-03-09 05:11:36 +08:00
const condition = chosenRandomNb === 0 || chosenRandomNb === 1 || chosenRandomNb === 2 ;
2021-03-08 07:53:58 +08:00
await this . page1 . waitForSelector ( ple . startPoll , ELEMENT _WAIT _TIME ) ;
await this . page1 . click ( ple . startPoll , true ) ;
await this . page2 . waitForSelector ( ple . pollingContainer , ELEMENT _WAIT _TIME ) ;
2021-03-09 05:11:36 +08:00
console . log ( { condition } ) ;
switch ( condition ) {
case true :
await this . page2 . clickNItem ( ple . pollAnswerOptionBtn , true , 2 ) ;
break ;
case false :
await this . page2 . page . focus ( ple . pollAnswerOptionInput ) ;
await this . page2 . page . keyboard . type ( customs [ 3 ] ) ;
await this . page2 . waitForSelector ( ple . pollSubmitAnswer , ELEMENT _WAIT _TIME ) ;
await this . page2 . click ( ple . pollSubmitAnswer , true ) ;
break ;
}
2021-03-08 07:53:58 +08:00
await this . page1 . waitForSelector ( ple . publishLabel , ELEMENT _WAIT _TIME ) ;
await this . page1 . click ( ple . publishLabel , true ) ;
2021-03-09 05:11:36 +08:00
await sleep ( 2000 ) ;
const receivedAnswerFound = await this . page1 . page . evaluate ( utilCustomParams . countTestElements , ple . receivedAnswer ) ;
await sleep ( 2000 ) ;
return receivedAnswerFound ;
2021-03-08 07:53:58 +08:00
} catch ( e ) {
console . log ( e ) ;
return false ;
}
}
2021-03-30 18:49:07 +08:00
async testWhiteboardAccess ( ) {
await this . page1 . closeAudioModal ( ) ;
await this . page2 . closeAudioModal ( ) ;
await this . page3 . closeAudioModal ( ) ;
await this . page1 . waitForSelector ( we . whiteboard , ELEMENT _WAIT _TIME ) ;
await this . page1 . clickNItem ( we . userListItem , true , 1 ) ;
await this . page1 . clickNItem ( we . changeWhiteboardAccess , true , 1 ) ;
await sleep ( 2000 ) ;
const resp = await this . page1 . page . evaluate ( async ( ) => await document . querySelector ( '[data-test="multiWhiteboardTool"]' ) . children [ 0 ] . innerText === '1' ) ;
return resp ;
}
2021-04-07 08:09:43 +08:00
// Raise Hand
async raiseHandTest ( ) {
await this . page1 . closeAudioModal ( ) ;
await this . page2 . closeAudioModal ( ) ;
await this . page2 . waitForSelector ( we . raiseHandLabel , ELEMENT _WAIT _TIME ) ;
await this . page2 . click ( we . raiseHandLabel , true ) ;
await sleep ( 2000 ) ;
const resp = await this . page2 . page . evaluate ( utilCustomParams . countTestElements , we . lowerHandLabel ) ;
return resp ;
}
// Lower Hand
async lowerHandTest ( ) {
await this . page2 . waitForSelector ( we . lowerHandLabel , ELEMENT _WAIT _TIME ) ;
await this . page2 . click ( we . lowerHandLabel , true ) ;
await sleep ( 2000 ) ;
const resp = await this . page2 . page . evaluate ( utilCustomParams . countTestElements , we . raiseHandLabel ) ;
return resp ;
}
// Get Avatars Colors from Userlist and Notification toast
async getAvatarColorAndCompareWithUserListItem ( ) {
2021-05-26 00:05:11 +08:00
const avatarInToastElementColor = await this . page1 . page . $eval ( we . avatarsWrapperAvatar , ( elem ) => getComputedStyle ( elem ) . backgroundColor ) ;
const avatarInUserListColor = await this . page1 . page . $eval ( '[data-test="userListItem"] > div [data-test="userAvatar"]' , ( elem ) => getComputedStyle ( elem ) . backgroundColor ) ;
2021-04-07 08:09:43 +08:00
return avatarInToastElementColor === avatarInUserListColor ;
}
2021-04-07 08:39:18 +08:00
async userOfflineWithInternetProblem ( ) {
try {
await this . page1 . closeAudioModal ( ) ;
await this . page2 . closeAudioModal ( ) ;
await this . page2 . page . evaluate ( ( ) => window . dispatchEvent ( new CustomEvent ( 'socketstats' , { detail : { rtt : 2000 } } ) ) ) ;
2021-05-26 00:05:11 +08:00
await this . page2 . page . setOfflineMode ( true ) ;
2021-04-07 08:39:18 +08:00
await sleep ( 3000 ) ;
await this . page2 . close ( ) ;
await sleep ( 5000 ) ;
await utilUser . connectionStatus ( this . page1 ) ;
await sleep ( 5000 ) ;
const connectionStatusItemEmpty = await this . page1 . page . evaluate ( utilUser . countTestElements , ue . connectionStatusItemEmpty ) === false ;
const connectionStatusOfflineUser = await this . page1 . page . evaluate ( utilUser . countTestElements , ue . connectionStatusOfflineUser ) === true ;
return connectionStatusOfflineUser && connectionStatusItemEmpty ;
} catch ( e ) {
console . log ( e ) ;
return false ;
}
}
2021-05-26 00:05:11 +08:00
async userlistNotAppearOnMobile ( ) {
try {
await this . page1 . closeAudioModal ( ) ;
await this . page2 . closeAudioModal ( ) ;
const userlistPanel = await this . page1 . page . evaluate ( utilUser . countTestElements , ue . chatButton ) === false ;
const chatPanel = await this . page2 . page . evaluate ( utilUser . countTestElements , ue . chatButton ) === false ;
return userlistPanel && chatPanel ;
} catch ( e ) {
console . log ( e ) ;
return false ;
}
}
async whiteboardNotAppearOnMobile ( ) {
try {
await this . page1 . closeAudioModal ( ) ;
await this . page2 . closeAudioModal ( ) ;
await this . page1 . click ( ue . userListButton , true ) ;
await this . page2 . click ( ue . userListButton , true ) ;
await this . page2 . click ( ue . chatButton , true ) ;
const onUserListPanel = await this . page1 . isNotVisible ( cu . hidePresentation , ELEMENT _WAIT _TIME ) === true ;
const onChatPanel = await this . page2 . page . evaluate ( utilUser . countTestElements , cu . hidePresentation ) === false ;
console . log ( { onUserListPanel , onChatPanel } ) ;
await sleep ( 2000 ) ;
return onUserListPanel && onChatPanel ;
} catch ( e ) {
console . log ( e ) ;
return false ;
}
}
async chatPanelNotAppearOnMobile ( ) {
try {
await this . page1 . closeAudioModal ( ) ;
await this . page2 . closeAudioModal ( ) ;
await this . page2 . click ( ue . userListButton , true ) ;
await this . page2 . click ( ue . chatButton , true ) ;
const whiteboard = await this . page1 . page . evaluate ( utilUser . countTestElements , ue . chatButton ) === false ;
const onChatPanel = await this . page2 . isNotVisible ( ue . chatButton , ELEMENT _WAIT _TIME ) === true ;
console . log ( { whiteboard , onChatPanel } ) ;
await sleep ( 2000 ) ;
return whiteboard && onChatPanel ;
} catch ( e ) {
console . log ( e ) ;
return false ;
}
}
2020-02-11 06:09:17 +08:00
// Close all Pages
2020-06-17 23:29:43 +08:00
async close ( page1 , page2 ) {
await page1 . close ( ) ;
await page2 . close ( ) ;
2020-02-11 06:09:17 +08:00
}
2020-03-21 04:31:58 +08:00
2020-03-23 20:15:10 +08:00
async closePage ( page ) {
await page . close ( ) ;
2020-03-21 04:31:58 +08:00
}
2020-02-08 02:03:06 +08:00
}
module . exports = exports = MultiUsers ;