From 321e8618d2e1aa75f59847b5662f003923d5ce9b Mon Sep 17 00:00:00 2001 From: Luis E <35935591+luisecm@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:15:38 -0600 Subject: [PATCH] update(test): fix chats tests on CI (#131) --- playwright.config.ts | 2 +- playwright/PageObjects/FriendsScreen.ts | 18 +- playwright/fixtures/setup.ts | 171 ++++++++---- .../specs/03-friends-two-instances.spec.ts | 54 +++- playwright/specs/22-chats-tests.spec.ts | 255 +++--------------- 5 files changed, 218 insertions(+), 282 deletions(-) diff --git a/playwright.config.ts b/playwright.config.ts index 5f67103a..d13d97e9 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -17,7 +17,7 @@ export default defineConfig({ /* Fail the build on CI if you accidentally left test.only in the source code. */ forbidOnly: !!process.env.CI, /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, + retries: process.env.CI ? 2 : 1, /* Opt out of parallel tests on CI. */ workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ diff --git a/playwright/PageObjects/FriendsScreen.ts b/playwright/PageObjects/FriendsScreen.ts index 4bd41c7c..be5923cc 100644 --- a/playwright/PageObjects/FriendsScreen.ts +++ b/playwright/PageObjects/FriendsScreen.ts @@ -246,15 +246,15 @@ export class FriendsScreen extends MainPage { } async validateBlockedUserExists() { - await this.textNoBlockedUsers.waitFor({ - state: "detached", - }); + await this.page + .getByTestId("button-friend-unblock") + .waitFor({ state: "visible" }); } async validateIncomingRequestExists() { - await this.textNoIncomingRequests.waitFor({ - state: "detached", - }); + await this.page + .getByTestId("button-friend-accept") + .waitFor({ state: "visible" }); } async validateNoBlockedUsersExist() { @@ -286,9 +286,9 @@ export class FriendsScreen extends MainPage { } async validateOutgoingRequestExists() { - await this.textNoOutgoingRequests.waitFor({ - state: "detached", - }); + await this.page + .getByTestId("button-friend-cancel") + .waitFor({ state: "visible" }); } async validateToastCannotAddYourself() { diff --git a/playwright/fixtures/setup.ts b/playwright/fixtures/setup.ts index fdd459db..de59fdb9 100644 --- a/playwright/fixtures/setup.ts +++ b/playwright/fixtures/setup.ts @@ -1,9 +1,9 @@ import { test as base, - BrowserContext, chromium, - Page, - Browser, + firefox, + type BrowserContext, + type Page, } from "@playwright/test"; import { faker } from "@faker-js/faker"; import { AuthNewAccount } from "../PageObjects/AuthNewAccount"; @@ -33,28 +33,18 @@ import { SettingsRealms } from "playwright/PageObjects/Settings/SettingsRealms"; type MyFixtures = { authNewAccount: AuthNewAccount; firstUserContext: { - browser: Browser; context: BrowserContext; page: Page; - authNewAccount: AuthNewAccount; - createOrImport: CreateOrImportPage; - loginPinPage: LoginPinPage; - saveRecoverySeed: SaveRecoverySeedPage; - chatsMainPage: ChatsMainPage; - username: string; - status: string; }; secondUserContext: { - browser: Browser; context: BrowserContext; page: Page; - authNewAccount: AuthNewAccount; - createOrImport: CreateOrImportPage; - loginPinPage: LoginPinPage; - saveRecoverySeed: SaveRecoverySeedPage; - chatsMainPage: ChatsMainPage; - username: string; - status: string; + }; + chatUserContexts: { + contextOne: BrowserContext; + pageOne: Page; + contextTwo: BrowserContext; + pageTwo: Page; }; chatsMainPage: ChatsMainPage; createOrImport: CreateOrImportPage; @@ -99,7 +89,6 @@ export const test = base.extend({ const authNewAccount = new AuthNewAccount(page); const loginPinPage = new LoginPinPage(page); const saveRecoverySeed = new SaveRecoverySeedPage(page); - const chatsMainPage = new ChatsMainPage(page); const username: string = "ChatUserA"; const status: string = faker.lorem.sentence(3); @@ -124,26 +113,16 @@ export const test = base.extend({ // Click on I Saved It await saveRecoverySeed.clickOnSavedIt(); - // Go to Friends - await chatsMainPage.goToFriends(); - // Pass the context, browser, and page to the test await use({ - browser, context, page, - authNewAccount, - createOrImport, - loginPinPage, - saveRecoverySeed, - chatsMainPage, - username, - status, }); // Close the context and browser after the test is done + await context.clearCookies(); + await context.clearPermissions(); await context.close(); - await browser.close(); }, secondUserContext: async ({}, use) => { @@ -155,7 +134,6 @@ export const test = base.extend({ const authNewAccount = new AuthNewAccount(page); const loginPinPage = new LoginPinPage(page); const saveRecoverySeed = new SaveRecoverySeedPage(page); - const chatsMainPage = new ChatsMainPage(page); const username: string = "ChatUserB"; const status: string = faker.lorem.sentence(3); @@ -180,26 +158,125 @@ export const test = base.extend({ // Click on I Saved It await saveRecoverySeed.clickOnSavedIt(); - // Go to Friends - await chatsMainPage.goToFriends(); - // Pass the context, browser, and page to the test await use({ - browser, context, page, - authNewAccount, - createOrImport, - loginPinPage, - saveRecoverySeed, - chatsMainPage, - username, - status, }); // Close the context and browser after the test is done + await context.clearCookies(); + await context.clearPermissions(); await context.close(); - await browser.close(); + }, + + chatUserContexts: async ({}, use) => { + // Declare all constants required for the precondition steps + const browserOne = await chromium.launch(); + const browserTwo = await firefox.launch(); + const contextOne = await browserOne.newContext(); + const contextTwo = await browserTwo.newContext(); + const pageOne = await contextOne.newPage(); + const pageTwo = await contextOne.newPage(); + const authNewAccountFirst = new AuthNewAccount(pageOne); + const authNewAccountSecond = new AuthNewAccount(pageTwo); + const chatsMainPageFirst = new ChatsMainPage(pageOne); + const chatsMainPageSecond = new ChatsMainPage(pageTwo); + const createOrImportFirst = new CreateOrImportPage(pageOne); + const createOrImportSecond = new CreateOrImportPage(pageTwo); + const friendsScreenFirst = new FriendsScreen(pageOne); + const friendsScreenSecond = new FriendsScreen(pageTwo); + const loginPinPageFirst = new LoginPinPage(pageOne); + const loginPinPageSecond = new LoginPinPage(pageTwo); + const saveRecoverySeedFirst = new SaveRecoverySeedPage(pageOne); + const saveRecoverySeedSecond = new SaveRecoverySeedPage(pageTwo); + const username: string = "ChatUserA"; + const usernameTwo: string = "ChatUserB"; + const status: string = faker.lorem.sentence(3); + + // Grant clipboard permissions to context one + await contextOne.grantPermissions(["clipboard-read", "clipboard-write"]); + + // Start browsers + await createOrImportFirst.navigateTo(); + await createOrImportSecond.navigateTo(); + + // Click on Create New Account + await createOrImportFirst.clickCreateNewAccount(); + await createOrImportSecond.clickCreateNewAccount(); + + // Enter username and Status and click on create account + await authNewAccountFirst.validateLoadingHeader(); + await authNewAccountFirst.typeOnUsername(username); + await authNewAccountFirst.typeOnStatus(status); + await authNewAccountFirst.clickOnCreateAccount(); + await authNewAccountSecond.validateLoadingHeader(); + await authNewAccountSecond.typeOnUsername(usernameTwo); + await authNewAccountSecond.typeOnStatus(status); + await authNewAccountSecond.clickOnCreateAccount(); + + // Enter Pin + await loginPinPageFirst.waitUntilPageIsLoaded(); + await loginPinPageFirst.enterDefaultPin(); + await loginPinPageSecond.waitUntilPageIsLoaded(); + await loginPinPageSecond.enterDefaultPin(); + + // Click on I Saved It + await saveRecoverySeedFirst.clickOnSavedIt(); + await saveRecoverySeedSecond.clickOnSavedIt(); + + // Go to Friends Screen + await chatsMainPageFirst.goToFriends(); + await chatsMainPageSecond.goToFriends(); + + // Copy DID and save it into a constant + await friendsScreenFirst.copyDIDFromContextMenu(); + const handle = await pageOne.evaluateHandle(() => + navigator.clipboard.readText(), + ); + const didKeyFirstUser = await handle.jsonValue(); + + // Copy DID and save it into a constant + await friendsScreenSecond.copyDIDFromContextMenu(); + + // Now, add the first user as a friend + await friendsScreenSecond.addFriend(didKeyFirstUser); + + // H6 - Toast Notification with Your request is making it's way! should appear after sending a friend request + await friendsScreenSecond.validateToastRequestSent(); + + // With First User, go to requests list and accept friend request + await friendsScreenFirst.goToChat(); + await chatsMainPageFirst.addSomeone.waitFor({ state: "visible" }); + await friendsScreenFirst.goToFriends(); + await friendsScreenFirst.goToRequestList(); + await friendsScreenFirst.validateIncomingRequestExists(); + await friendsScreenFirst.acceptFriendRequest(usernameTwo); + + // With First User, go to All Friends and click on Chat Button + await friendsScreenFirst.goToAllFriendsList(); + await friendsScreenFirst.chatWithFriend(usernameTwo); + + // With Second User, go to All Friends and click on Chat Button + await friendsScreenSecond.goToRequestList(); + await friendsScreenSecond.goToAllFriendsList(); + await friendsScreenSecond.chatWithFriend(username); + + // Pass the context, browser, and page to the test + await use({ + contextOne, + pageOne, + contextTwo, + pageTwo, + }); + + // Close the context and browser after the test is done + await contextOne.clearCookies(); + await contextOne.clearPermissions(); + await contextOne.close(); + await contextTwo.clearCookies(); + await contextTwo.clearPermissions(); + await contextTwo.close(); }, createOrImport: async ({ page }, use) => { @@ -222,7 +299,9 @@ export const test = base.extend({ // Declare all constants required for the precondition steps const page = await context.newPage(); await use(page); - await page.close(); + await context.clearCookies(); + await context.clearPermissions(); + await context.close(); }, saveRecoverySeed: async ({ page }, use) => { diff --git a/playwright/specs/03-friends-two-instances.spec.ts b/playwright/specs/03-friends-two-instances.spec.ts index 003b90b4..a36da5d5 100644 --- a/playwright/specs/03-friends-two-instances.spec.ts +++ b/playwright/specs/03-friends-two-instances.spec.ts @@ -1,5 +1,9 @@ import { FriendsScreen } from "playwright/PageObjects/FriendsScreen"; import { test, expect } from "../fixtures/setup"; +import { ChatsMainPage } from "playwright/PageObjects/ChatsMain"; + +const username = "ChatUserA"; +const usernameTwo = "ChatUserB"; test.describe("Friends tests", () => { test("H15 - User should be removed from friends list after clicking unfriend", async ({ @@ -10,10 +14,14 @@ test.describe("Friends tests", () => { const context1 = firstUserContext.context; const page1 = firstUserContext.page; const page2 = secondUserContext.page; - const username = firstUserContext.username; - const usernameTwo = secondUserContext.username; const friendsScreenFirst = new FriendsScreen(page1); const friendsScreenSecond = new FriendsScreen(page2); + const chatsMainPageFirst = new ChatsMainPage(page1); + const chatsMainPageSecond = new ChatsMainPage(page2); + + // With both users go to Friends Screen + await chatsMainPageFirst.goToFriends(); + await chatsMainPageSecond.goToFriends(); // H15 - User should be removed from friends list after clicking unfriend // Grant clipboard permissions, Copy DID and save it into a constant @@ -73,10 +81,14 @@ test.describe("Friends tests", () => { const context1 = firstUserContext.context; const page1 = firstUserContext.page; const page2 = secondUserContext.page; - const username = firstUserContext.username; - const usernameTwo = secondUserContext.username; const friendsScreenFirst = new FriendsScreen(page1); const friendsScreenSecond = new FriendsScreen(page2); + const chatsMainPageFirst = new ChatsMainPage(page1); + const chatsMainPageSecond = new ChatsMainPage(page2); + + // With both users go to Friends Screen + await chatsMainPageFirst.goToFriends(); + await chatsMainPageSecond.goToFriends(); // Grant clipboard permissions, Copy DID and save it into a constant await context1.grantPermissions(["clipboard-read", "clipboard-write"]); @@ -144,10 +156,14 @@ test.describe("Friends tests", () => { const context1 = firstUserContext.context; const page1 = firstUserContext.page; const page2 = secondUserContext.page; - const username = firstUserContext.username; - const usernameTwo = secondUserContext.username; const friendsScreenFirst = new FriendsScreen(page1); const friendsScreenSecond = new FriendsScreen(page2); + const chatsMainPageFirst = new ChatsMainPage(page1); + const chatsMainPageSecond = new ChatsMainPage(page2); + + // With both users go to Friends Screen + await chatsMainPageFirst.goToFriends(); + await chatsMainPageSecond.goToFriends(); // Grant clipboard permissions, Copy DID and save it into a constant await context1.grantPermissions(["clipboard-read", "clipboard-write"]); @@ -191,9 +207,14 @@ test.describe("Friends tests", () => { const context1 = firstUserContext.context; const page1 = firstUserContext.page; const page2 = secondUserContext.page; - const usernameTwo = secondUserContext.username; const friendsScreenFirst = new FriendsScreen(page1); const friendsScreenSecond = new FriendsScreen(page2); + const chatsMainPageFirst = new ChatsMainPage(page1); + const chatsMainPageSecond = new ChatsMainPage(page2); + + // With both users go to Friends Screen + await chatsMainPageFirst.goToFriends(); + await chatsMainPageSecond.goToFriends(); // Grant clipboard permissions, Copy DID and save it into a constant await context1.grantPermissions(["clipboard-read", "clipboard-write"]); @@ -211,7 +232,6 @@ test.describe("Friends tests", () => { // H7 - Skipped validation Toast Notification with Username sent a request. should appear after receiving a friend request await friendsScreenSecond.validateToastRequestSent(); - //await friendsScreenFirst.validateToastRequestReceived("ChatUserB"); await friendsScreenFirst.waitForToastNotificationToDisappear(); await friendsScreenSecond.waitForToastNotificationToDisappear(); @@ -233,8 +253,7 @@ test.describe("Friends tests", () => { await friendsScreenSecond.validateNoOutgoingRequestsExist(); }); - // Failing test on CI - test.skip("H21 - User can send a friend request and cancel request before other user replies to it", async ({ + test("H21 - User can send a friend request and cancel request before other user replies to it", async ({ firstUserContext, secondUserContext, }) => { @@ -242,9 +261,14 @@ test.describe("Friends tests", () => { const context1 = firstUserContext.context; const page1 = firstUserContext.page; const page2 = secondUserContext.page; - const username = firstUserContext.username; const friendsScreenFirst = new FriendsScreen(page1); const friendsScreenSecond = new FriendsScreen(page2); + const chatsMainPageFirst = new ChatsMainPage(page1); + const chatsMainPageSecond = new ChatsMainPage(page2); + + // With both users go to Friends Screen + await chatsMainPageFirst.goToFriends(); + await chatsMainPageSecond.goToFriends(); // H21 - User can send a friend request and cancel request before other user replies to it // Grant clipboard permissions, Copy DID and save it into a constant @@ -262,19 +286,21 @@ test.describe("Friends tests", () => { await friendsScreenSecond.addFriend(didKeyFirstUser); await friendsScreenSecond.validateToastRequestSent(); await friendsScreenSecond.waitForToastNotificationToDisappear(); - await friendsScreenSecond.goToRequestList(); - await friendsScreenSecond.validateOutgoingRequestExists(); - // With First User, go to requests list and validate friend request was received + // With First User, go to requests list and accept friend request await friendsScreenFirst.waitForToastNotificationToDisappear(); await friendsScreenFirst.goToRequestList(); await friendsScreenFirst.validateIncomingRequestExists(); // With Second User, cancel the outgoing request + await friendsScreenSecond.goToRequestList(); + await friendsScreenSecond.validateOutgoingRequestExists(); await friendsScreenSecond.cancelFriendRequest(username); await friendsScreenSecond.validateNoOutgoingRequestsExist(); // With First User, validate incoming request no longer exists + await friendsScreenFirst.goToBlockedList(); + await friendsScreenFirst.goToRequestList(); await friendsScreenFirst.validateNoIncomingRequestsExist(); }); }); diff --git a/playwright/specs/22-chats-tests.spec.ts b/playwright/specs/22-chats-tests.spec.ts index ce02c36e..cfd1c2b6 100644 --- a/playwright/specs/22-chats-tests.spec.ts +++ b/playwright/specs/22-chats-tests.spec.ts @@ -1,71 +1,30 @@ -import { FriendsScreen } from "playwright/PageObjects/FriendsScreen"; import { test, expect } from "../fixtures/setup"; import { faker } from "@faker-js/faker"; import { FilesPage } from "playwright/PageObjects/FilesScreen"; +import { ChatsMainPage } from "playwright/PageObjects/ChatsMain"; + +const usernameTwo = "ChatUserB"; test.describe("Chats Tests - Two instances", () => { - // Tests need adjustments to pass flakiness detected on CI - test.skip("B1 to B6, B16 and B17, B35 to B37 - Landing to Chats Page elements and basic send/receive text message flow", async ({ - firstUserContext, - secondUserContext, + test("B1 to B6, B16 and B17, B35 to B37 - Landing to Chats Page elements and basic send/receive text message flow", async ({ + chatUserContexts, }) => { // Declare constants required from the fixtures - const context1 = firstUserContext.context; - const context2 = secondUserContext.context; - const page1 = firstUserContext.page; - const page2 = secondUserContext.page; - const username = firstUserContext.username; - const usernameTwo = secondUserContext.username; - const chatsMainPageFirst = firstUserContext.chatsMainPage; - const chatsMainPageSecond = secondUserContext.chatsMainPage; - const friendsScreenFirst = new FriendsScreen(page1); - const friendsScreenSecond = new FriendsScreen(page2); - - // Grant clipboard permissions, Copy DID and save it into a constant - await context1.grantPermissions(["clipboard-read", "clipboard-write"]); - await friendsScreenFirst.copyDIDFromContextMenu(); - const handle = await page1.evaluateHandle(() => - navigator.clipboard.readText(), - ); - const didKeyFirstUser = await handle.jsonValue(); - - // Grant clipboard permissions, Copy DID and save it into a constant - await context2.grantPermissions(["clipboard-read", "clipboard-write"]); - await friendsScreenSecond.copyDIDFromContextMenu(); - const handleTwo = await page2.evaluateHandle(() => - navigator.clipboard.readText(), - ); - const didKeySecondUser = await handleTwo.jsonValue(); - - // Copy DID and save it into a constant - await friendsScreenSecond.copyDIDFromContextMenu(); - - // Now, add the first user as a friend - await friendsScreenSecond.addFriend(didKeyFirstUser); - - // Toast Notification with Your request is making it's way! should appear after sending a friend request - await friendsScreenSecond.validateToastRequestSent(); - - // Workaround for friends requests - Both users should send themselves friend request - await friendsScreenFirst.addFriend(didKeySecondUser); - await friendsScreenFirst.validateToastRequestSent(); - - // With First User, go to All Friends and click on Chat Button - await friendsScreenFirst.goToAllFriendsList(); - await friendsScreenFirst.chatWithFriend(usernameTwo); - - // With Second User, go to All Friends and click on Chat Button - await friendsScreenSecond.goToAllFriendsList(); - await friendsScreenSecond.chatWithFriend(username); + const page1 = chatUserContexts.pageOne; + const page2 = chatUserContexts.pageTwo; + const chatsMainPageFirst = new ChatsMainPage(page1); + const chatsMainPageSecond = new ChatsMainPage(page2); // B3 - Messages are secured by end-to-end encryption, sent over a peer-to-peer network should be displayed at the top of every chat - await expect(chatsMainPageSecond.chatEncryptedMessage).toBeAttached(); + await chatsMainPageSecond.chatEncryptedMessage.waitFor({ + state: "visible", + }); await expect(chatsMainPageSecond.chatEncryptedMessageText).toHaveText( "Messages are secured by end-to-end encryption, sent over a peer-to-peer network.", ); - // B4 - Amount of coin should be displayed at top right toolbar - await expect(chatsMainPageSecond.coinAmountIndicator).toHaveText("0"); + // B4 - Amount of coin should be displayed at top right toolbar - Button is hidden now + // await expect(chatsMainPageSecond.coinAmountIndicator).toHaveText("0"); // B5 - Highlighted border should appear around call button when clicked await chatsMainPageSecond.buttonChatCall.focus(); @@ -151,66 +110,17 @@ test.describe("Chats Tests - Two instances", () => { .waitFor({ state: "visible" }); }); - // Tests need adjustments to pass flakiness detected on CI - test.skip("B7, B57, B58 - Favorites tests", async ({ - firstUserContext, - secondUserContext, - }) => { + test("B7, B57, B58 - Favorites tests", async ({ chatUserContexts }) => { // Declare constants required from the fixtures - const context1 = firstUserContext.context; - const context2 = secondUserContext.context; - const page1 = firstUserContext.page; - const page2 = secondUserContext.page; - const username = firstUserContext.username; - const usernameTwo = secondUserContext.username; - const chatsMainPageFirst = firstUserContext.chatsMainPage; + const page1 = chatUserContexts.pageOne; + const chatsMainPageFirst = new ChatsMainPage(page1); const filesPageFirst = new FilesPage(page1); - const friendsScreenFirst = new FriendsScreen(page1); - const friendsScreenSecond = new FriendsScreen(page2); - - // Grant clipboard permissions, Copy DID and save it into a constant - await context1.grantPermissions(["clipboard-read", "clipboard-write"]); - await friendsScreenFirst.copyDIDFromContextMenu(); - const handle = await page1.evaluateHandle(() => - navigator.clipboard.readText(), - ); - const didKeyFirstUser = await handle.jsonValue(); - - // Grant clipboard permissions, Copy DID and save it into a constant - await context2.grantPermissions(["clipboard-read", "clipboard-write"]); - await friendsScreenSecond.copyDIDFromContextMenu(); - const handleTwo = await page2.evaluateHandle(() => - navigator.clipboard.readText(), - ); - const didKeySecondUser = await handleTwo.jsonValue(); - - // Copy DID and save it into a constant - await friendsScreenSecond.copyDIDFromContextMenu(); - - // Now, add the first user as a friend - await friendsScreenSecond.addFriend(didKeyFirstUser); - - // Toast Notification with Your request is making it's way! should appear after sending a friend request - await friendsScreenSecond.validateToastRequestSent(); - - // Workaround for friends requests - Both users should send themselves friend request - await friendsScreenFirst.addFriend(didKeySecondUser); - await friendsScreenFirst.validateToastRequestSent(); - - // With First User, go to All Friends and click on Chat Button - await friendsScreenFirst.goToAllFriendsList(); - - // With Second User, go to All Friends and click on Chat Button - await friendsScreenSecond.goToAllFriendsList(); - - // With first user, go to chat conversation with remote user - await friendsScreenFirst.chatWithFriend(usernameTwo); - - // With second user, go to chat conversation with remote user - await friendsScreenSecond.chatWithFriend(username); // B7 - Favorite button should should be highlighted after clicked and grey when unclicked // First when button is not clicked + await chatsMainPageFirst.chatEncryptedMessage.waitFor({ + state: "visible", + }); await expect(chatsMainPageFirst.buttonChatFavorite).toHaveCSS( "background-color", "rgb(33, 38, 58)", @@ -242,63 +152,20 @@ test.describe("Chats Tests - Two instances", () => { await chatsMainPageFirst.validateNoFavoritesAreVisible(); }); - // Tests need adjustments to pass flakiness detected on CI - test.skip("C11, C12, C16, C17 and C19 - Chat Sidebar tests", async ({ - firstUserContext, - secondUserContext, + test("C11, C12, C16, C17 and C19 - Chat Sidebar tests", async ({ + chatUserContexts, }) => { // Declare constants required from the fixtures - const context1 = firstUserContext.context; - const context2 = secondUserContext.context; - const page1 = firstUserContext.page; - const page2 = secondUserContext.page; - const username = firstUserContext.username; - const usernameTwo = secondUserContext.username; - const chatsMainPageFirst = firstUserContext.chatsMainPage; - const chatsMainPageSecond = secondUserContext.chatsMainPage; - const friendsScreenFirst = new FriendsScreen(page1); - const friendsScreenSecond = new FriendsScreen(page2); - - // Testing timestamp with Clock API - await page1.clock.install(); - - // Grant clipboard permissions, Copy DID and save it into a constant - await context1.grantPermissions(["clipboard-read", "clipboard-write"]); - await friendsScreenFirst.copyDIDFromContextMenu(); - const handle = await page1.evaluateHandle(() => - navigator.clipboard.readText(), - ); - const didKeyFirstUser = await handle.jsonValue(); - - // Grant clipboard permissions, Copy DID and save it into a constant - await context2.grantPermissions(["clipboard-read", "clipboard-write"]); - await friendsScreenSecond.copyDIDFromContextMenu(); - const handleTwo = await page2.evaluateHandle(() => - navigator.clipboard.readText(), - ); - const didKeySecondUser = await handleTwo.jsonValue(); - - // Copy DID and save it into a constant - await friendsScreenSecond.copyDIDFromContextMenu(); - - // Now, add the first user as a friend - await friendsScreenSecond.addFriend(didKeyFirstUser); - - // Toast Notification with Your request is making it's way! should appear after sending a friend request - await friendsScreenSecond.validateToastRequestSent(); - - // Workaround for friends requests - Both users should send themselves friend request - await friendsScreenFirst.addFriend(didKeySecondUser); - await friendsScreenFirst.validateToastRequestSent(); - - // With first user, go to chat conversation with remote user - await friendsScreenFirst.chatWithFriend(usernameTwo); - - // With second user, go to chat conversation with remote user and send a message - await friendsScreenSecond.chatWithFriend(username); + const page1 = chatUserContexts.pageOne; + const page2 = chatUserContexts.pageTwo; + const chatsMainPageFirst = new ChatsMainPage(page1); + const chatsMainPageSecond = new ChatsMainPage(page2); // Validate chat preview is displayed on sidebar - Default values when no messages have been sent // C11 - ProfilePicFrame should display for any friends that have one + await chatsMainPageFirst.chatEncryptedMessage.waitFor({ + state: "visible", + }); const chatPreviewImageURL = await chatsMainPageFirst.chatPreviewPictureImage.getAttribute("src"); const topbarImageURL = @@ -449,60 +316,24 @@ test.describe("Chats Tests - Two instances", () => { // Test code for B54 }); - // Tests need adjustments to pass flakiness detected on CI - test.skip("B56 - Chats Tests - Multiple messages testing", async ({ - firstUserContext, - secondUserContext, + test("B56 - Chats Tests - Multiple messages testing", async ({ + chatUserContexts, }) => { // Declare constants required from the fixtures - const context1 = firstUserContext.context; - const context2 = secondUserContext.context; - const page1 = firstUserContext.page; - const page2 = secondUserContext.page; - const username = firstUserContext.username; - const usernameTwo = secondUserContext.username; - const chatsMainPageFirst = firstUserContext.chatsMainPage; - const chatsMainPageSecond = secondUserContext.chatsMainPage; - const friendsScreenFirst = new FriendsScreen(page1); - const friendsScreenSecond = new FriendsScreen(page2); - - // Grant clipboard permissions, Copy DID and save it into a constant - await context1.grantPermissions(["clipboard-read", "clipboard-write"]); - await friendsScreenFirst.copyDIDFromContextMenu(); - const handle = await page1.evaluateHandle(() => - navigator.clipboard.readText(), - ); - const didKeyFirstUser = await handle.jsonValue(); - - // Grant clipboard permissions, Copy DID and save it into a constant - await context2.grantPermissions(["clipboard-read", "clipboard-write"]); - await friendsScreenSecond.copyDIDFromContextMenu(); - const handleTwo = await page2.evaluateHandle(() => - navigator.clipboard.readText(), - ); - const didKeySecondUser = await handleTwo.jsonValue(); - - // Copy DID and save it into a constant - await friendsScreenSecond.copyDIDFromContextMenu(); - - // Now, add the first user as a friend - await friendsScreenSecond.addFriend(didKeyFirstUser); - - // Toast Notification with Your request is making it's way! should appear after sending a friend request - await friendsScreenSecond.validateToastRequestSent(); - - // Workaround for friends requests - Both users should send themselves friend request - await friendsScreenFirst.addFriend(didKeySecondUser); - await friendsScreenFirst.validateToastRequestSent(); - - // With first user, go to chat conversation with remote user - await friendsScreenFirst.chatWithFriend(usernameTwo); - - // With second user, go to chat conversation with remote user and send a message - await friendsScreenSecond.chatWithFriend(username); + const page1 = chatUserContexts.pageOne; + const page2 = chatUserContexts.pageTwo; + const chatsMainPageFirst = new ChatsMainPage(page1); + const chatsMainPageSecond = new ChatsMainPage(page2); + + // Validate chat pages are loaded on both sides + await chatsMainPageFirst.chatEncryptedMessage.waitFor({ + state: "visible", + }); + await chatsMainPageSecond.chatEncryptedMessage.waitFor({ + state: "visible", + }); // Validate second user is in chats page and send 20 messages - for (let i = 0; i < 20; i++) { const randomSentence = faker.lorem.sentence(3); await chatsMainPageSecond.sendMessage(randomSentence);