From 9a2d32e64208af6379b3e2334598b649c9274d6e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 10 Jul 2018 19:26:47 +0200 Subject: [PATCH] accept terms when joining --- helpers.js | 18 ++++++++++++++++++ start.js | 2 +- tests/join.js | 18 +++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/helpers.js b/helpers.js index 3e2467e622..d57595f377 100644 --- a/helpers.js +++ b/helpers.js @@ -87,6 +87,23 @@ async function waitAndQuerySelector(page, selector, timeout = 500) { return await page.$(selector); } +function waitForNewPage(timeout = 500) { + return new Promise((resolve, reject) => { + const timeoutHandle = setTimeout(() => { + browser.removeEventListener('targetcreated', callback); + reject(new Error(`timeout of ${timeout}ms for waitForNewPage elapsed`)); + }, timeout); + + const callback = async (target) => { + clearTimeout(timeoutHandle); + const page = await target.page(); + resolve(page); + }; + + browser.once('targetcreated', callback); + }); +} + // other helpers function randomInt(max) { @@ -110,6 +127,7 @@ module.exports = { printElements, replaceInputText, waitAndQuerySelector, + waitForNewPage, randomInt, riotUrl, delay, diff --git a/start.js b/start.js index 0cc80f2fde..8a3ceb354b 100644 --- a/start.js +++ b/start.js @@ -37,7 +37,7 @@ async function runTests() { const room = 'test'; process.stdout.write(`* joining room ${room} ... `); - await join(page, room); + await join(page, room, true); process.stdout.write('done\n'); await browser.close(); diff --git a/tests/join.js b/tests/join.js index ea16a93936..79990af3a2 100644 --- a/tests/join.js +++ b/tests/join.js @@ -17,7 +17,7 @@ limitations under the License. const helpers = require('../helpers'); const assert = require('assert'); -module.exports = async function join(page, roomName) { +module.exports = async function join(page, roomName, acceptTerms = false) { //TODO: brittle selector const directoryButton = await helpers.waitAndQuerySelector(page, '.mx_RoleButton[aria-label="Room directory"]'); await directoryButton.click(); @@ -31,5 +31,21 @@ module.exports = async function join(page, roomName) { const joinLink = await helpers.waitAndQuerySelector(page, '.mx_RoomPreviewBar_join_text a'); await joinLink.click(); + if (acceptTerms) { + const reviewTermsButton = await helpers.waitAndQuerySelector(page, '.mx_QuestionDialog button.mx_Dialog_primary'); + const termsPagePromise = helpers.waitForNewPage(); + await reviewTermsButton.click(); + const termsPage = await termsPagePromise; + const acceptButton = await termsPage.$('input[type=submit]'); + await acceptButton.click(); + await helpers.delay(500); //TODO yuck, timers + //try to join again after accepting the terms + + //TODO need to do this because joinLink is detached after switching target + const joinLink2 = await helpers.waitAndQuerySelector(page, '.mx_RoomPreviewBar_join_text a'); + await joinLink2.click(); + } + + await page.waitForSelector('.mx_MessageComposer'); } \ No newline at end of file