From 1fd379b3d25208c8d53a5b6722129401090dc0a0 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 8 Aug 2018 12:17:36 +0200 Subject: [PATCH] wait to receive message from other user --- src/scenario.js | 4 ++++ src/tests/receive-message.js | 42 ++++++++++++++++++++++++++++++++++++ src/tests/room-settings.js | 2 +- src/tests/send-message.js | 25 +++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/tests/receive-message.js create mode 100644 src/tests/send-message.js diff --git a/src/scenario.js b/src/scenario.js index 9aa0ed2ec0..14c901ba99 100644 --- a/src/scenario.js +++ b/src/scenario.js @@ -17,6 +17,8 @@ limitations under the License. const signup = require('./tests/signup'); const join = require('./tests/join'); +const sendMessage = require('./tests/send-message'); +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'); @@ -36,4 +38,6 @@ module.exports = async function scenario(createSession) { await createRoom(alice, room); await changeRoomSettings(alice, {directory: true, visibility: "public_no_guests"}); await join(bob, room); + await sendMessage(bob, "hi Alice!"); + await receiveMessage(alice, {sender: "bob", body: "hi Alice!"}); } diff --git a/src/tests/receive-message.js b/src/tests/receive-message.js new file mode 100644 index 0000000000..607bc1625e --- /dev/null +++ b/src/tests/receive-message.js @@ -0,0 +1,42 @@ +/* +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'); + + +async function getMessageFromTile(eventTile) { + const senderElement = await eventTile.$(".mx_SenderProfile_name"); + const bodyElement = await eventTile.$(".mx_EventTile_body"); + const sender = await(await senderElement.getProperty("innerText")).jsonValue(); + const body = await(await bodyElement.getProperty("innerText")).jsonValue(); + return {sender, body}; +} + +module.exports = async function receiveMessage(session, message) { + session.log.step(`waits to receive message from ${message.sender} in room`); + // wait for a response to come in that contains the message + // crude, but effective + await session.page.waitForResponse(async (response) => { + const body = await response.text(); + return body.indexOf(message.body) !== -1; + }); + + let lastTile = await session.waitAndQuery(".mx_EventTile_last"); + let lastMessage = await getMessageFromTile(lastTile); + assert.equal(lastMessage.body, message.body); + assert.equal(lastMessage.sender, message.sender); + session.log.done(); +} \ No newline at end of file diff --git a/src/tests/room-settings.js b/src/tests/room-settings.js index d7bbad3451..6001d14d34 100644 --- a/src/tests/room-settings.js +++ b/src/tests/room-settings.js @@ -32,7 +32,7 @@ module.exports = async function changeRoomSettings(session, settings) { if (typeof settings.directory === "boolean") { session.log.step(`sets directory listing to ${settings.directory}`); const checked = await session.getElementProperty(isDirectory, "checked"); - assert(typeof checked, "boolean"); + assert.equal(typeof checked, "boolean"); if (checked !== settings.directory) { await isDirectory.click(); session.log.done(); diff --git a/src/tests/send-message.js b/src/tests/send-message.js new file mode 100644 index 0000000000..8a61a15e94 --- /dev/null +++ b/src/tests/send-message.js @@ -0,0 +1,25 @@ +/* +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 sendMessage(session, message) { + session.log.step(`writes "${message}" in room`); + const composer = await session.waitAndQuery('.mx_MessageComposer'); + await composer.type(message); + await composer.press("Enter"); + session.log.done(); +} \ No newline at end of file