make receiveMessage more robust by checking first if the message is not already in the timeline

This commit is contained in:
Bruno Windels 2018-09-13 12:04:18 +02:00
parent 239e6a4bce
commit 9f4cf776c5

View file

@ -46,6 +46,21 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
session.log.step(`receives message "${expectedMessage.body}" from ${expectedMessage.sender}`); session.log.step(`receives message "${expectedMessage.body}" from ${expectedMessage.sender}`);
// 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
async function assertLastMessage() {
const lastTile = await getLastEventTile(session);
const lastMessage = await getMessageFromEventTile(lastTile);
await assertMessage(lastMessage, expectedMessage);
}
// first try to see if the message is already the last message in the timeline
let isExpectedMessage = false;
try {
assertLastMessage();
isExpectedMessage = true;
} catch(ex) {}
if (!isExpectedMessage) {
await session.page.waitForResponse(async (response) => { await session.page.waitForResponse(async (response) => {
if (response.request().url().indexOf("/sync") === -1) { if (response.request().url().indexOf("/sync") === -1) {
return false; return false;
@ -60,9 +75,9 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
}); });
// wait a bit for the incoming event to be rendered // wait a bit for the incoming event to be rendered
await session.delay(1000); await session.delay(1000);
const lastTile = await getLastEventTile(session); await assertLastMessage();
const foundMessage = await getMessageFromEventTile(lastTile); }
assertMessage(foundMessage, expectedMessage);
session.log.done(); session.log.done();
} }