accept terms when joining

pull/21833/head
Bruno Windels 2018-07-10 19:26:47 +02:00
parent 9c5e43a693
commit 9a2d32e642
3 changed files with 36 additions and 2 deletions

View File

@ -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,

View File

@ -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();

View File

@ -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');
}