make receiving a bit more robust

This commit is contained in:
Bruno Windels 2018-08-08 12:35:36 +02:00
parent 1fd379b3d2
commit c5f064e389

View file

@ -18,25 +18,25 @@ const assert = require('assert');
async function getMessageFromTile(eventTile) { 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) { module.exports = async function receiveMessage(session, message) {
session.log.step(`waits to receive message from ${message.sender} in room`); session.log.step(`receives message "${message.body}" from ${message.sender} in room`);
// wait for a response to come in that contains the message // wait for a response to come in that contains the message
// crude, but effective // crude, but effective
await session.page.waitForResponse(async (response) => { await session.page.waitForResponse(async (response) => {
const body = await response.text(); const body = await response.text();
return body.indexOf(message.body) !== -1; return body.indexOf(message.body) !== -1;
}); });
// wait a bit for the incoming event to be rendered
await session.delay(100);
let lastTile = await session.query(".mx_EventTile_last");
const senderElement = await lastTile.$(".mx_SenderProfile_name");
const bodyElement = await lastTile.$(".mx_EventTile_body");
const sender = await(await senderElement.getProperty("innerText")).jsonValue();
const body = await(await bodyElement.getProperty("innerText")).jsonValue();
let lastTile = await session.waitAndQuery(".mx_EventTile_last"); assert.equal(body, message.body);
let lastMessage = await getMessageFromTile(lastTile); assert.equal(sender, message.sender);
assert.equal(lastMessage.body, message.body);
assert.equal(lastMessage.sender, message.sender);
session.log.done(); session.log.done();
} }