From 4a4b1f65aa2d418d8c616b2501b25ceb49f74a5e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 11 Sep 2018 18:28:50 +0200 Subject: [PATCH] wait for the message to be sent --- src/scenario.js | 9 +++++++-- src/session.js | 23 ++++++++++++++++++++--- src/tests/e2e-device.js | 31 ------------------------------- src/tests/send-message.js | 4 +++- start.js | 6 ++++-- synapse/install.sh | 4 +++- 6 files changed, 37 insertions(+), 40 deletions(-) delete mode 100644 src/tests/e2e-device.js diff --git a/src/scenario.js b/src/scenario.js index b468cad823..3145c9471a 100644 --- a/src/scenario.js +++ b/src/scenario.js @@ -25,13 +25,13 @@ const receiveMessage = require('./tests/receive-message'); const createRoom = require('./tests/create-room'); const changeRoomSettings = require('./tests/room-settings'); const acceptServerNoticesInviteAndConsent = require('./tests/server-notices-consent'); -const getE2EDeviceFromSettings = require('./tests/e2e-device'); +const {enableLazyLoading, getE2EDeviceFromSettings} = require('./tests/settings'); const verifyDeviceForUser = require("./tests/verify-device"); module.exports = async function scenario(createSession, createRestSession) { async function createUser(username) { const session = await createSession(username); - await signup(session, session.username, 'testtest'); + await signup(session, session.username, 'testtest', session.hsUrl); await acceptServerNoticesInviteAndConsent(session); return session; } @@ -83,3 +83,8 @@ async function createE2ERoomAndTalk(alice, bob) { await sendMessage(bob, bobMessage); await receiveMessage(alice, {sender: "bob", body: bobMessage, encrypted: true}); } + +async function aLLtest(alice, bob) { + await enableLazyLoading(alice); + +} diff --git a/src/session.js b/src/session.js index bcccc9d6cc..60cbfa9099 100644 --- a/src/session.js +++ b/src/session.js @@ -58,9 +58,10 @@ class Logger { } module.exports = class RiotSession { - constructor(browser, page, username, riotserver) { + constructor(browser, page, username, riotserver, hsUrl) { this.browser = browser; this.page = page; + this.hsUrl = hsUrl; this.riotserver = riotserver; this.username = username; this.consoleLog = new LogBuffer(page, "console", (msg) => `${msg.text()}\n`); @@ -72,14 +73,14 @@ module.exports = class RiotSession { this.log = new Logger(this.username); } - static async create(username, puppeteerOptions, riotserver) { + static async create(username, puppeteerOptions, riotserver, hsUrl) { const browser = await puppeteer.launch(puppeteerOptions); const page = await browser.newPage(); await page.setViewport({ width: 1280, height: 800 }); - return new RiotSession(browser, page, username, riotserver); + return new RiotSession(browser, page, username, riotserver, hsUrl); } async tryGetInnertext(selector) { @@ -161,6 +162,22 @@ module.exports = class RiotSession { return await this.queryAll(selector); } + waitForReload(timeout = 5000) { + return new Promise((resolve, reject) => { + const timeoutHandle = setTimeout(() => { + this.browser.removeEventListener('domcontentloaded', callback); + reject(new Error(`timeout of ${timeout}ms for waitForReload elapsed`)); + }, timeout); + + const callback = async () => { + clearTimeout(timeoutHandle); + resolve(); + }; + + this.page.once('domcontentloaded', callback); + }); + } + waitForNewPage(timeout = 5000) { return new Promise((resolve, reject) => { const timeoutHandle = setTimeout(() => { diff --git a/src/tests/e2e-device.js b/src/tests/e2e-device.js deleted file mode 100644 index 4be6677396..0000000000 --- a/src/tests/e2e-device.js +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright 2018 New Vector Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -const assert = require('assert'); - -module.exports = async function getE2EDeviceFromSettings(session) { - session.log.step(`gets e2e device/key from settings`); - const settingsButton = await session.query('.mx_BottomLeftMenu_settings'); - await settingsButton.click(); - const deviceAndKey = await session.waitAndQueryAll(".mx_UserSettings_section.mx_UserSettings_cryptoSection code", 1000); - assert.equal(deviceAndKey.length, 2); - const id = await (await deviceAndKey[0].getProperty("innerText")).jsonValue(); - const key = await (await deviceAndKey[1].getProperty("innerText")).jsonValue(); - const closeButton = await session.query(".mx_RoomHeader_cancelButton"); - await closeButton.click(); - session.log.done(); - return {id, key}; -} diff --git a/src/tests/send-message.js b/src/tests/send-message.js index eb70f5ce23..5bf289b03a 100644 --- a/src/tests/send-message.js +++ b/src/tests/send-message.js @@ -25,5 +25,7 @@ module.exports = async function sendMessage(session, message) { const text = await session.innerText(composer); assert.equal(text.trim(), message.trim()); await composer.press("Enter"); + // wait for the message to appear sent + await session.waitAndQuery(".mx_EventTile_last:not(.mx_EventTile_sending)"); session.log.done(); -} \ No newline at end of file +} diff --git a/start.js b/start.js index 5f6681519b..62ec29d6a1 100644 --- a/start.js +++ b/start.js @@ -26,6 +26,8 @@ program .option('--riot-url [url]', "riot url to test", "http://localhost:5000") .parse(process.argv); +const hsUrl = 'http://localhost:5005'; + async function runTests() { let sessions = []; console.log("running tests ..."); @@ -43,7 +45,7 @@ async function runTests() { const restCreator = new RestSessionCreator( 'synapse/installations/consent', - 'http://localhost:5005', + hsUrl, __dirname ); @@ -52,7 +54,7 @@ async function runTests() { } async function createSession(username) { - const session = await RiotSession.create(username, options, program.riotUrl); + const session = await RiotSession.create(username, options, program.riotUrl, hsUrl); sessions.push(session); return session; } diff --git a/synapse/install.sh b/synapse/install.sh index 3d8172a9f6..a438ea5dc2 100755 --- a/synapse/install.sh +++ b/synapse/install.sh @@ -31,9 +31,11 @@ python -m synapse.app.homeserver \ --generate-config \ --report-stats=no # apply configuration +REGISTRATION_SHARED_SECRET=$(uuidgen) cp -r $BASE_DIR/config-templates/$CONFIG_TEMPLATE/. ./ sed -i "s#{{SYNAPSE_ROOT}}#$(pwd)/#g" homeserver.yaml sed -i "s#{{SYNAPSE_PORT}}#${PORT}#g" homeserver.yaml sed -i "s#{{FORM_SECRET}}#$(uuidgen)#g" homeserver.yaml -sed -i "s#{{REGISTRATION_SHARED_SECRET}}#$(uuidgen)#g" homeserver.yaml +sed -i "s#{{REGISTRATION_SHARED_SECRET}}#${REGISTRATION_SHARED_SECRET}#g" homeserver.yaml sed -i "s#{{MACAROON_SECRET_KEY}}#$(uuidgen)#g" homeserver.yaml +echo REGISTRATION_SHARED_SECRET=$REGISTRATION_SHARED_SECRET=