Refactored base page and started chat saving test

This commit is contained in:
Pedro Beschorner Marin 2018-11-22 17:15:52 -02:00
parent 7a18655230
commit fc31a0d394
14 changed files with 126 additions and 82 deletions

View File

@ -1,5 +1,7 @@
node_modules/
screenshots/*
!screenshots/screenshots.txt
downloads/*
!downloads/downloads.txt
.directory
.env

View File

@ -2,9 +2,9 @@ const Page = require('./page');
const Send = require('./chat/send');
const Clear = require('./chat/clear');
const Copy = require('./chat/copy');
const Save = require('./chat/save');
describe('Chat', () => {
test('Send message', async () => {
const test = new Send();
let response;
@ -47,4 +47,17 @@ describe('Chat', () => {
expect(response).toBe(true);
});
test('Save chat', async () => {
const test = new Save();
let response;
try {
await test.init(Page.getArgs());
response = await test.test();
} catch (e) {
console.log(e);
} finally {
await test.close();
}
expect(response).toBe(true);
});
});

View File

@ -1,33 +1,36 @@
// Test: Cleaning a chat message
const Page = require('../page');
const helper = require('../helper');
const e = require('./elements');
const util = require('./util');
class Clear extends Page {
constructor() {
super('chat-clear');
}
async test() {
await util.openChat(this);
await this.type(e.chatBox, 'Hello world!');
await this.type(e.chatBox, e.message);
await this.click(e.sendButton);
await this.screenshot('clear-chat0.png', true);
await this.screenshot(true);
// Must be:
// [{ "name": "User1\nXX:XX XM", "message": "Hello world!" }]
const chat0 = await util.getTestElements(this);
const before = await util.getTestElements(this);
await this.click(e.chatOptions);
await this.click(e.chatClear, true);
await this.screenshot('clear-chat1.png', true);
await this.screenshot(true);
// Must be:
// []
const chat1 = await util.getTestElements(this);
const after = await util.getTestElements(this);
const response =
chat0[0].message == 'Hello world!' &&
chat1.length == 0;
before[0].message == e.message &&
after.length == 0;
return response;
}

View File

@ -1,30 +1,30 @@
// Test: Cleaning a chat message
const Page = require('../page');
const helper = require('../helper');
const e = require('./elements');
const util = require('./util');
class Copy extends Page {
constructor() {
super('chat-copy');
}
async test() {
await util.openChat(this);
await this.click(e.chatOptions);
await this.click(e.chatCopy, true);
await this.click(e.chatBox);
// Pasting in chat because I could't get puppeteer clipboard
await this.page.keyboard.down('ControlLeft');
await this.page.keyboard.press('KeyV');
await this.page.keyboard.up('ControlLeft');
await this.paste(e.chatBox);
await this.click(e.sendButton, true);
await this.screenshot('copy-chat.png', true);
await this.screenshot(true);
// Must be:
// [{ "name": "User1\nXX:XX XM", "message": "[XX:XX] THE_MEETING_WELCOME_MESSAGE }]
const chat = await util.getTestElements(this);
const after = await util.getTestElements(this);
const response = chat.length != 0;
const response = after.length != 0;
return response;
}

View File

@ -6,3 +6,5 @@ exports.chatOptions = '[aria-label="Chat Options"]';
exports.chatClear = 'i._imports_ui_components_dropdown_list__styles__itemIcon.icon-bbb-delete';
exports.chatCopy = 'i._imports_ui_components_dropdown_list__styles__itemIcon.icon-bbb-copy';
exports.chatSave = 'i._imports_ui_components_dropdown_list__styles__itemIcon.icon-bbb-save_notes';
exports.message = 'Hello World!';

View File

@ -0,0 +1,26 @@
// Test: Cleaning a chat message
const Page = require('../page');
const e = require('./elements');
const util = require('./util');
class Save extends Page {
constructor() {
super('chat-save');
}
async test() {
await util.openChat(this);
await this.click(e.chatOptions);
await this.click(e.chatSave, true);
await this.screenshot(true);
await this.screenshot(true);
await this.screenshot(true);
return true;
}
}
module.exports = exports = Save;

View File

@ -1,11 +1,14 @@
// Test: Sending a chat message
const Page = require('../page');
const helper = require('../helper');
const e = require('./elements');
const util = require('./util');
class Send extends Page {
constructor() {
super('chat-send');
}
async test() {
await util.openChat(this);
@ -13,9 +16,9 @@ class Send extends Page {
// []
const chat0 = await util.getTestElements(this);
await this.type(e.chatBox, 'Hello world!');
await this.type(e.chatBox, e.message);
await this.click(e.sendButton);
await this.screenshot('test-chat.png', true);
await this.screenshot(true);
// Must be:
// [{ "name": "User1\nXX:XX XM", "message": "Hello world!" }]
@ -23,7 +26,7 @@ class Send extends Page {
const response =
chat0.length == 0 &&
chat1[0].message == 'Hello world!';
chat1[0].message == e.message;
return response;
}

View File

@ -1,8 +1,6 @@
const e = require('./elements');
async function openChat(test) {
await test.createBBBMeeting();
await test.joinWithoutAudio();
await test.click(e.chatButton);
await test.page.waitFor(e.chatBox);
await test.page.waitFor(e.chatMessages);

View File

@ -0,0 +1 @@
This is where downloads from the BigBlueButton tests will be saved.

View File

@ -3,10 +3,11 @@ const helper = require('./helper');
const e = require('./elements');
class DrawTestPage extends Page {
async test() {
await this.createBBBMeeting();
await this.joinWithoutAudio();
constructor() {
super('whiteboard-draw');
}
async test() {
await this.click(e.tools);
await this.click(e.rectangle);
await this.page.waitFor(e.whiteboard);
@ -20,7 +21,7 @@ class DrawTestPage extends Page {
await this.page.mouse.move(wbBox.x + 0.7 * wbBox.width, wbBox.y + 0.7 * wbBox.height);
await this.page.mouse.up();
await this.screenshot('test-draw.png', true);
await this.screenshot(true);
const shapes1 = await this.getTestElements();
console.log('\nShapes before drawing box:');

View File

@ -3,31 +3,32 @@ const helper = require('./helper');
const e = require('./elements');
class StatusTestPage extends Page {
async test() {
await this.createBBBMeeting();
await this.joinWithoutAudio();
constructor() {
super('user-status');
}
await this.screenshot('test-status-0.png', true);
async test() {
await this.screenshot(true);
const status0 = await this.getTestElements();
await this.click(e.firstUser);
await this.click(e.setStatus, true);
await this.click(e.applaud, true);
await this.screenshot('test-status-1.png', true);
await this.screenshot(true);
const status1 = await this.getTestElements();
await this.click(e.firstUser);
await this.click(e.setStatus, true);
await this.click(e.away, true);
await this.screenshot('test-status-2.png', true);
await this.screenshot(true);
const status2 = await this.getTestElements();
await this.click(e.firstUser);
await this.click(e.clearStatus, true);
await this.screenshot('test-status-3.png', true);
await this.screenshot(true);
const status3 = await this.getTestElements();
console.log('\nStatus at start of meeting:');

View File

@ -3,24 +3,25 @@ const helper = require('./helper');
const e = require('./elements');
class SlideSwitchTestPage extends Page {
async test() {
await this.createBBBMeeting();
await this.joinWithoutAudio();
constructor() {
super('presentation-slide');
}
async test() {
await this.page.waitFor(e.whiteboard);
await this.page.waitFor(e.presentationToolbarWrapper);
await this.screenshot('test-switch-slides-0.png', true);
await this.screenshot(true);
const svg0 = await this.getTestElements();
await this.click(e.nextSlide, true);
await this.screenshot('test-switch-slides-1.png', true);
await this.screenshot(true);
const svg1 = await this.getTestElements();
await this.click(e.prevSlide, true);
await this.screenshot('test-switch-slides-2.png', true);
await this.screenshot(true);
const svg2 = await this.getTestElements();
console.log('\nStarting slide:');

View File

@ -3,10 +3,11 @@ const helper = require('./helper');
const e = require('./elements');
class UploadTestPage extends Page {
async test() {
await this.createBBBMeeting();
await this.joinWithoutAudio();
constructor() {
super('presentation-upload');
}
async test() {
await this.page.waitFor(e.whiteboard);
await this.page.waitFor(e.skipSlide);
@ -22,7 +23,7 @@ class UploadTestPage extends Page {
await this.click(e.start);
await this.elementRemoved(e.start);
await this.screenshot('test-upload.png', true);
await this.screenshot(true);
const slides1 = await this.getTestElements();
console.log('\nSlides before presentation upload:');

View File

@ -4,15 +4,30 @@ const params = require('./params');
const e = require('./elements');
class Page {
// Initializes the page
constructor(name) {
this.name = name;
this.screenshotIndex = 0;
this.meetingId;
}
// Join BigBlueButton meeting
async init(args) {
this.browser = await puppeteer.launch(args);
this.page = await this.browser.newPage();
await this.setDownloadBehavior(__dirname + '/downloads');
this.meetingId = await helper.createMeeting(params);
const joinURL = helper.getJoinURL(this.meetingId, params, true);
await this.page.goto(joinURL);
await this.page.waitForSelector(e.audioDialog, { timeout: 60000 });
await this.click(e.closeAudio, true);
}
// Navigates to a page
async goto(page) {
this.page.goto(page);
async setDownloadBehavior(downloadPath) {
const downloadBehavior = { behavior: 'allow', downloadPath: downloadPath };
await this.page._client.send('Page.setDownloadBehavior', downloadBehavior);
}
// Run the test for the page
@ -33,38 +48,6 @@ class Page {
return { headless: true, args: ['--no-sandbox', '--use-fake-ui-for-media-stream'] };
}
// Creates a BigBlueButton meeting
async createBBBMeeting() {
const meetingID = await helper.createMeeting(params);
await this.joinBBBMeeting(meetingID);
return meetingID;
}
// Navigates the page to join a BigBlueButton meeting
async joinBBBMeeting(meetingID) {
const joinURL = helper.getJoinURL(meetingID, params, true);
await this.goto(joinURL);
await this.page.waitForSelector(e.audioDialog, { timeout: 60000 });
}
// Joins a BigBlueButton as a listener
async joinAudioListenOnly() {
await this.click(e.listenButton);
console.log('Joined meeting as listener');
}
// Joins a BigBlueButton meeting with a microphone
async joinAudioMicrophone() {
await this.click(e.microphoneButton);
await this.click(e.echoYes, true);
console.log('Joined meeting with microphone');
}
// Joins a BigBlueButton meeting without audio
async joinWithoutAudio() {
await this.click(e.closeAudio, true);
}
// Returns a Promise that resolves when an element does not exist/is removed from the DOM
elementRemoved(element) {
return this.page.waitFor(element => !document.querySelector(element), {}, element);
@ -121,9 +104,18 @@ class Page {
await this.page.type(element, text);
}
async screenshot(path, relief = false) {
async screenshot(relief = false) {
if (relief) await helper.sleep(1000);
await this.page.screenshot({ path: 'screenshots/' + path });
const path = 'screenshots/' + this.name + '-' + this.screenshotIndex + '.png';
await this.page.screenshot({ path: path });
this.screenshotIndex++;
}
async paste(element) {
await this.click(element);
await this.page.keyboard.down('ControlLeft');
await this.page.keyboard.press('KeyV');
await this.page.keyboard.up('ControlLeft');
}
}