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) {
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`);
session.log.step(`receives message "${message.body}" 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);
// 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();
assert.equal(body, message.body);
assert.equal(sender, message.sender);
session.log.done();
}