Skip to content

Commit a1ecdae

Browse files
committed
test(WPB-22129): fix login test util
Waiting for the navigation to the app on login caused issues in cases where the history info was shown in between, causing the test to timeout without interaction.
1 parent dfc3fe3 commit a1ecdae

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

test/e2e_tests/pageManager/webapp/pages/login.page.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import type {Page, Locator} from '@playwright/test';
2121

2222
import type {User} from 'test/e2e_tests/data/user';
2323

24-
import {webAppPath} from '../..';
25-
2624
export class LoginPage {
2725
readonly page: Page;
2826

@@ -46,11 +44,5 @@ export class LoginPage {
4644
await this.emailInput.fill(user.email);
4745
await this.passwordInput.fill(user.password);
4846
await this.signInButton.click();
49-
50-
/**
51-
* Since the login may take up to 40s we manually wait for it to finish here instead of increasing the timeout on all actions / assertions after this util
52-
* This is an exception to the general best practice of using playwrights web assertions. (See: https://playwright.dev/docs/best-practices#use-web-first-assertions)
53-
*/
54-
await this.page.waitForURL(new RegExp(`^${webAppPath}$`), {timeout: 40_000, waitUntil: 'networkidle'});
5547
}
5648
}

test/e2e_tests/specs/Authentication/authentication.spec.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ test.describe('Authentication', () => {
4848
test(
4949
'I want to be asked to share telemetry data when I log in',
5050
{tag: ['@TC-8780', '@regression']},
51-
async ({pageManager, createUser}) => {
51+
async ({page, pageManager, createUser}) => {
5252
const {pages, modals} = pageManager.webapp;
5353
const user = await createUser({disableTelemetry: false});
5454

5555
await pageManager.openLoginPage();
5656
await pages.login().login(user);
57+
await page.waitForURL(webAppPath, {timeout: 30_000, waitUntil: 'networkidle'});
5758

5859
await expect(modals.dataShareConsent().modalTitle).toBeVisible();
5960
},
@@ -76,7 +77,7 @@ test.describe('Authentication', () => {
7677
test(
7778
'Verify current browser is set as temporary device',
7879
{tag: ['@TC-3460', '@regression']},
79-
async ({pageManager, createUser}) => {
80+
async ({page, pageManager, createUser}) => {
8081
const user = await createUser();
8182
const {pages, components} = pageManager.webapp;
8283

@@ -85,6 +86,7 @@ test.describe('Authentication', () => {
8586
await pages.login().publicComputerCheckbox.click();
8687
await pages.login().login(user);
8788
await pages.historyInfo().clickConfirmButton();
89+
await page.waitForURL(webAppPath, {timeout: 30_000, waitUntil: 'networkidle'});
8890
});
8991

9092
let proteusId: string;
@@ -104,6 +106,7 @@ test.describe('Authentication', () => {
104106
await test.step('Log in again on non public computer', async () => {
105107
await pageManager.openLoginPage();
106108
await pages.login().login(user);
109+
await page.waitForURL(webAppPath, {timeout: 30_000, waitUntil: 'networkidle'});
107110
});
108111

109112
await test.step("Open device settings and ensure the public computer isn't active and the ID was re-generated", async () => {
@@ -136,7 +139,7 @@ test.describe('Authentication', () => {
136139
test(
137140
`I want to keep my history after refreshing the page on ${deviceType} device`,
138141
{tag: [tag, '@regression']},
139-
async ({pageManager, createTeam}) => {
142+
async ({page, pageManager, createTeam}) => {
140143
const {pages} = pageManager.webapp;
141144
const team = await createTeam('Test Team', {withMembers: 1});
142145
const userA = team.owner;
@@ -153,6 +156,7 @@ test.describe('Authentication', () => {
153156
await pages.login().login(userA);
154157
}
155158

159+
await page.waitForURL(webAppPath, {timeout: 30_000, waitUntil: 'networkidle'});
156160
await connectWithUser(pageManager, userB);
157161
});
158162

@@ -192,7 +196,7 @@ test.describe('Authentication', () => {
192196
test(
193197
'Make sure user does not see data of user of previous sessions on same browser',
194198
{tag: ['@TC-1311', '@regression']},
195-
async ({pageManager, createTeam}) => {
199+
async ({page, pageManager, createTeam}) => {
196200
const {pages, components} = pageManager.webapp;
197201
const team = await createTeam('Test Team', {withMembers: 1});
198202
const userA = team.owner;
@@ -203,6 +207,7 @@ test.describe('Authentication', () => {
203207
await pages.login().publicComputerCheckbox.click();
204208
await pages.login().login(userA);
205209
await pages.historyInfo().clickConfirmButton();
210+
await page.waitForURL(webAppPath, {timeout: 30_000, waitUntil: 'networkidle'});
206211
});
207212

208213
await test.step('Connect with and send message to userB', async () => {
@@ -221,6 +226,7 @@ test.describe('Authentication', () => {
221226
await pageManager.openLoginPage();
222227
await pages.login().login(userA);
223228
await pages.historyInfo().clickConfirmButton();
229+
await page.waitForURL(webAppPath, {timeout: 30_000, waitUntil: 'networkidle'});
224230
});
225231

226232
await test.step('Verify previously sent message is gone', async () => {
@@ -241,8 +247,7 @@ test.describe('Authentication', () => {
241247
pages: device2Pages,
242248
modals: device2Modals,
243249
components: device2Components,
244-
} = PageManager.from(await createPage(withLogin(user))).webapp;
245-
await device2Pages.historyInfo().clickConfirmButton();
250+
} = PageManager.from(await createPage(withLogin(user, {confirmNewHistory: true}))).webapp;
246251

247252
await device2Components.conversationSidebar().clickPreferencesButton();
248253
await device2Pages.settings().devicesButton.click();

test/e2e_tests/specs/Edit/edit.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ test.describe('Edit', () => {
7272
const deviceA = (await PageManager.from(createPage(withLogin(userA), withConnectedUser(userB)))).webapp.pages;
7373

7474
// Device 2 is intentionally created after device 1 to ensure the history info warning is confirmed
75-
const deviceB = (await PageManager.from(createPage(withLogin(userA)))).webapp.pages;
76-
await deviceB.historyInfo().clickConfirmButton();
75+
const deviceB = (await PageManager.from(createPage(withLogin(userA, {confirmNewHistory: true})))).webapp.pages;
7776
await deviceB.conversationList().openConversation(userB.fullName);
7877

7978
await deviceA.conversation().sendMessage('Message from device 1');

test/e2e_tests/test.fixtures.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {test as baseTest, type BrowserContext, type Page} from '@playwright/test
2121

2222
import {ApiManagerE2E} from './backend/apiManager.e2e';
2323
import {getUser, User} from './data/user';
24-
import {PageManager} from './pageManager';
24+
import {PageManager, webAppPath} from './pageManager';
2525
import {connectWithUser, sendConnectionRequest} from './utils/userActions';
2626

2727
type PagePlugin = (page: Page) => void | Promise<void>;
@@ -144,11 +144,21 @@ export const test = baseTest.extend<Fixtures>({
144144

145145
/** PagePlugin to log in as the given user */
146146
export const withLogin =
147-
(user: User | Promise<User>): PagePlugin =>
147+
(user: User | Promise<User>, options?: {confirmNewHistory?: boolean}): PagePlugin =>
148148
async page => {
149149
const pageManager = PageManager.from(page);
150150
await pageManager.openLoginPage();
151151
await pageManager.webapp.pages.login().login(await user);
152+
153+
if (options?.confirmNewHistory) {
154+
await pageManager.webapp.pages.historyInfo().clickConfirmButton();
155+
}
156+
157+
/**
158+
* Since the login may take up to 40s we manually wait for it to finish here instead of increasing the timeout on all actions / assertions after this util
159+
* This is an exception to the general best practice of using playwrights web assertions. (See: https://playwright.dev/docs/best-practices#use-web-first-assertions)
160+
*/
161+
await page.waitForURL(new RegExp(`^${webAppPath}$`), {timeout: 40_000, waitUntil: 'networkidle'});
152162
};
153163

154164
/**

0 commit comments

Comments
 (0)