fix Chat test suite and use variable on evaluate functions

This commit is contained in:
Anton 2021-08-02 15:31:44 -03:00
parent 2f43ee7efa
commit c1c19abe4b
4 changed files with 20 additions and 11 deletions

View File

@ -13,7 +13,7 @@ class Send extends Page {
await util.openChat(this);
// 0 messages
const chat0 = await this.page.evaluate(() => document.querySelectorAll('p[data-test="chatUserMessageText"]').length === 0);
const chat0 = await this.page.evaluate((chatSelector) => document.querySelectorAll(chatSelector).length === 0, e.chatUserMessageText);
if (process.env.GENERATE_EVIDENCES === 'true') {
await this.screenshot(`${testName}`, `01-before-chat-message-send-[${this.meetingId}]`);
}
@ -26,9 +26,10 @@ class Send extends Page {
if (process.env.GENERATE_EVIDENCES === 'true') {
await this.screenshot(`${testName}`, `03-after-chat-message-send-[${this.meetingId}]`);
}
await this.waitForSelector(e.chatUserMessageText);
// 1 message
const chat1 = await this.page.evaluate(() => document.querySelectorAll('p[data-test="chatUserMessageText"]').length === 1);
const chat1 = await this.page.evaluate((chatSelector) => document.querySelectorAll(chatSelector).length === 1, e.chatUserMessageText);
return chat0 === chat1;
}
}

View File

@ -22,7 +22,9 @@ async function openPrivateChatMessage(page1, page2) {
Object.values(arguments).forEach(async argument => await argument.waitForSelector(ule.userListItem, ELEMENT_WAIT_TIME));
await page1.page.evaluate(clickOnTheOtherUser, ule.userListItem);
await page2.page.evaluate(clickOnTheOtherUser, ule.userListItem);
await page1.page.waitForSelector(e.activeChat, ELEMENT_WAIT_TIME);
await page1.page.evaluate(clickThePrivateChatButton, e.activeChat);
await page2.page.waitForSelector(e.activeChat, ELEMENT_WAIT_TIME);
await page2.page.evaluate(clickThePrivateChatButton, e.activeChat);
}

View File

@ -62,7 +62,7 @@ class Notifications extends MultiUsers {
await this.page1.screenshot(`${testName}`, `05-page01-public-chat-message-sent-${testName}`);
await this.page1.waitForSelector(ne.smallToastMsg, ELEMENT_WAIT_TIME);
await this.page1.waitForSelector(ne.hasUnreadMessages, ELEMENT_WAIT_TIME);
const lastToast = await util.getOtherToastValue(this.page1);
const lastToast = await util.getLastToastValue(this.page1);
await this.page1.screenshot(`${testName}`, `06-page01-public-chat-toast-${testName}`);
return expectedToastValue === lastToast;
}
@ -82,7 +82,7 @@ class Notifications extends MultiUsers {
await this.page1.screenshot(`${testName}`, `05-page01-private-chat-message-sent-${testName}`);
await this.page1.waitForSelector(ne.smallToastMsg, ELEMENT_WAIT_TIME);
await this.page1.waitForSelector(ne.hasUnreadMessages, ELEMENT_WAIT_TIME);
const lastToast = await util.getOtherToastValue(this.page1);
const lastToast = await util.getLastToastValue(this.page1);
await this.page1.screenshot(`${testName}`, `06-page01-public-chat-toast-${testName}`);
return expectedToastValue === lastToast;
}

View File

@ -1,4 +1,4 @@
const ne = require('../notifications/elements');
const ne = require('./elements');
const ule = require('../user/elements');
const ce = require('../chat/elements');
const e = require('../core/elements');
@ -40,19 +40,19 @@ async function waitForToast(test) {
async function getLastToastValue(test) {
await test.waitForSelector(ne.smallToastMsg, ELEMENT_WAIT_TIME);
const toast = test.page.evaluate(async () => {
const lastToast = await document.querySelectorAll('div[data-test="toastSmallMsg"]')[0].innerText;
const toast = test.page.evaluate(async (toastMsgSelector) => {
const lastToast = await document.querySelectorAll(toastMsgSelector)[0].innerText;
return lastToast;
});
}, ne.smallToastMsg);
return toast;
}
async function getOtherToastValue(test) {
await test.waitForSelector(ne.smallToastMsg, ELEMENT_WAIT_TIME);
const toast = test.page.evaluate(async () => {
const lastToast = await document.querySelectorAll('div[data-test="toastSmallMsg"]')[1].innerText;
const toast = test.page.evaluate(async (toastMsgSelector) => {
const lastToast = await document.querySelectorAll(toastMsgSelector)[1].innerText;
return lastToast;
});
}, ne.smallToastMsg);
return toast;
}
@ -82,6 +82,12 @@ async function privateChatMessageToast(page2) {
// Open private Chat with the other User
await page2.page.evaluate(clickOnElement, ule.userListItem);
await page2.page.evaluate(clickThePrivateChatButton, ce.activeChat);
// wait for the private chat to be ready
await page2.page.waitForFunction(
(chatSelector) => document.querySelectorAll(chatSelector).length == 2,
{ timeout: ELEMENT_WAIT_TIME },
ce.chatButton
);
// send a private message
await page2.page.type(ce.privateChat, ce.message1);
await page2.click(ce.sendButton, true);