add Chat: private message test

This commit is contained in:
Anton 2022-01-19 17:02:54 -03:00
parent 5e2e095381
commit f606391f69
3 changed files with 48 additions and 1 deletions

View File

@ -1,5 +1,6 @@
const { test } = require('@playwright/test');
const { Chat } = require('./chat');
const { PrivateChat } = require('./privateChat');
test.describe.parallel('Chat', () => {
test('Send public message', async ({ browser, page }) => {
@ -7,7 +8,13 @@ test.describe.parallel('Chat', () => {
await chat.init(true, true);
await chat.sendPublicMessage();
});
test('Send private message', async ({ browser, context, page }) => {
const privateChat = new PrivateChat(browser, context);
await privateChat.initPages(page);
await privateChat.sendPrivateMessage();
});
test('Clear chat', async ({ browser, page }) => {
const chat = new Chat(browser, page);
await chat.init(true, true);

View File

@ -0,0 +1,39 @@
const { MultiUsers } = require('../user/multiusers');
const e = require('../core/elements');
const { sleep } = require('../core/helpers');
const { checkElementLengthEqualTo } = require('../core/util');
const { ELEMENT_WAIT_TIME } = require('../core/constants');
class PrivateChat extends MultiUsers {
constructor(browser, context) {
super(browser, context);
}
async sendPrivateMessage() {
await this.modPage.waitAndClick(e.userListItem);
await this.modPage.waitAndClick(e.activeChat);
await this.modPage.waitForSelector(e.hidePrivateChat);
await sleep(500); // prevent a race condition when running on a deployed server
// modPage send message
await this.modPage.type(e.chatBox, e.message1);
await this.modPage.waitAndClick(e.sendButton);
await this.userPage.page.waitForFunction(
checkElementLengthEqualTo,
[e.chatButton, 2],
{ timeout: ELEMENT_WAIT_TIME },
);
await this.userPage.waitAndClickElement(e.chatButton, 1);
await this.userPage.waitForSelector(e.hidePrivateChat);
// check sent messages
await this.modPage.hasText(e.chatUserMessageText, e.message1);
await this.userPage.hasText(e.chatUserMessageText, e.message1);
// userPage send message
await this.userPage.type(e.chatBox, e.message2);
await this.userPage.waitAndClick(e.sendButton);
// check sent messages
await this.modPage.hasText(e.privateChat, e.message2);
await this.userPage.hasText(e.privateChat, e.message2);
}
}
exports.PrivateChat = PrivateChat;

View File

@ -58,6 +58,7 @@ exports.chatSave = 'li[data-test="chatSave"]';
exports.chatCopy = 'li[data-test="chatCopy"]';
exports.chatTitle = 'div[data-test="chatTitle"]';
exports.activeChat = 'li[data-test="activeChat"]';
exports.privateChat = 'div[data-test="privateChat"]';
exports.hidePrivateChat = 'button[aria-label^="Hide Private Chat with"]';
exports.typingIndicator = 'span[data-test="typingIndicator"]';
exports.chatUserMessageText = 'p[data-test="chatUserMessageText"]';