Skip to content

Commit 294ee5d

Browse files
authored
test(e2e): close leaked browser contexts in omnichannel livechat specs (RocketChat#41078)
1 parent e929d2d commit 294ee5d

3 files changed

Lines changed: 32 additions & 20 deletions

File tree

apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-queue-management-autoselection.spec.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { BrowserContext } from '@playwright/test';
2+
13
import { createFakeVisitor } from '../../mocks/data';
24
import { IS_EE } from '../config/constants';
35
import { createAuxContext } from '../fixtures/createAuxContext';
@@ -17,6 +19,7 @@ test.describe('OC - Livechat - Queue Management', () => {
1719

1820
let poHomeOmnichannel: HomeOmnichannel;
1921
let poLiveChat: OmnichannelLiveChat;
22+
let liveChatContext: BrowserContext;
2023

2124
const waitingQueueMessage = 'This is a message from Waiting Queue';
2225

@@ -37,8 +40,8 @@ test.describe('OC - Livechat - Queue Management', () => {
3740
});
3841

3942
test.beforeEach(async ({ browser, api }) => {
40-
const context = await browser.newContext();
41-
const page2 = await context.newPage();
43+
liveChatContext = await browser.newContext();
44+
const page2 = await liveChatContext.newPage();
4245

4346
poLiveChat = new OmnichannelLiveChat(page2, api);
4447
await poLiveChat.page.goto('/livechat');
@@ -56,19 +59,20 @@ test.describe('OC - Livechat - Queue Management', () => {
5659

5760
test.describe('OC - Queue Management - Auto Selection', () => {
5861
let poLiveChat2: OmnichannelLiveChat;
62+
let liveChat2Context: BrowserContext;
5963

6064
test.beforeEach(async ({ browser, api }) => {
61-
const context = await browser.newContext();
62-
const page = await context.newPage();
65+
liveChat2Context = await browser.newContext();
66+
const page = await liveChat2Context.newPage();
6367
poLiveChat2 = new OmnichannelLiveChat(page, api);
6468
await poLiveChat2.page.goto('/livechat');
6569
});
6670

6771
test.afterEach(async () => {
6872
await poLiveChat2.closeChat();
69-
await poLiveChat2.page.close();
73+
await liveChat2Context.close();
7074
await poLiveChat.closeChat();
71-
await poLiveChat.page.close();
75+
await liveChatContext.close();
7276
});
7377

7478
test('Update user position on Queue', async () => {

apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-queue-management.spec.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { BrowserContext } from '@playwright/test';
2+
13
import { createFakeVisitor } from '../../mocks/data';
24
import { IS_EE } from '../config/constants';
35
import { createAuxContext } from '../fixtures/createAuxContext';
@@ -17,6 +19,7 @@ test.describe('OC - Livechat - Queue Management', () => {
1719

1820
let poHomeOmnichannel: HomeOmnichannel;
1921
let poLiveChat: OmnichannelLiveChat;
22+
let liveChatContext: BrowserContext;
2023

2124
const waitingQueueMessage = 'This is a message from Waiting Queue';
2225
const queuePosition1 = 'Your spot is #1';
@@ -35,8 +38,8 @@ test.describe('OC - Livechat - Queue Management', () => {
3538
});
3639

3740
test.beforeEach(async ({ browser, api }) => {
38-
const context = await browser.newContext();
39-
const page2 = await context.newPage();
41+
liveChatContext = await browser.newContext();
42+
const page2 = await liveChatContext.newPage();
4043

4144
poLiveChat = new OmnichannelLiveChat(page2, api);
4245
await poLiveChat.page.goto('/livechat');
@@ -54,7 +57,7 @@ test.describe('OC - Livechat - Queue Management', () => {
5457

5558
test.afterEach(async () => {
5659
await poLiveChat.closeChat();
57-
await poLiveChat.page.close();
60+
await liveChatContext.close();
5861
});
5962

6063
test('OC - Queue Management - Waiting Queue Message enabled', async () => {
@@ -72,17 +75,18 @@ test.describe('OC - Livechat - Queue Management', () => {
7275

7376
test.describe('OC - Queue Management - Update Queue Position', () => {
7477
let poLiveChat2: OmnichannelLiveChat;
78+
let liveChat2Context: BrowserContext;
7579

7680
test.beforeEach(async ({ browser, api }) => {
77-
const context = await browser.newContext();
78-
const page = await context.newPage();
81+
liveChat2Context = await browser.newContext();
82+
const page = await liveChat2Context.newPage();
7983
poLiveChat2 = new OmnichannelLiveChat(page, api);
8084
await poLiveChat2.page.goto('/livechat');
8185
});
8286

8387
test.afterEach(async () => {
8488
await poLiveChat2.closeChat();
85-
await poLiveChat2.page.close();
89+
await liveChat2Context.close();
8690
});
8791

8892
test('Update user position on Queue', async () => {
@@ -125,6 +129,7 @@ test.describe('OC - Contact Manager Routing', () => {
125129

126130
let poHomeOmnichannel: HomeOmnichannel;
127131
let poLiveChat: OmnichannelLiveChat;
132+
let liveChatContext: BrowserContext;
128133

129134
// User2 will be the contact manager
130135
let poHomeOmnichannelUser2: HomeOmnichannel;
@@ -152,8 +157,8 @@ test.describe('OC - Contact Manager Routing', () => {
152157
});
153158

154159
test.beforeEach(async ({ browser, api }) => {
155-
const context = await browser.newContext();
156-
const page = await context.newPage();
160+
liveChatContext = await browser.newContext();
161+
const page = await liveChatContext.newPage();
157162

158163
poLiveChat = new OmnichannelLiveChat(page, api);
159164
await poLiveChat.page.goto('/livechat');
@@ -173,7 +178,7 @@ test.describe('OC - Contact Manager Routing', () => {
173178

174179
test.afterEach(async () => {
175180
await poLiveChat.closeChat();
176-
await poLiveChat.page.close();
181+
await liveChatContext.close();
177182
});
178183

179184
test('should route inquiry only to the contact manager', async () => {

apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-tab-communication.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { BrowserContext } from '@playwright/test';
2+
13
import { createFakeVisitor } from '../../mocks/data';
24
import { createAuxContext } from '../fixtures/createAuxContext';
35
import { Users } from '../fixtures/userStates';
@@ -9,6 +11,7 @@ import { test, expect } from '../utils/test';
911
test.describe('OC - Livechat - Cross Tab Communication', () => {
1012
let pageLivechat1: OmnichannelLiveChat;
1113
let pageLivechat2: OmnichannelLiveChat;
14+
let livechatContext: BrowserContext;
1215

1316
let poHomeOmnichannel: HomeOmnichannel;
1417
let agent: Awaited<ReturnType<typeof createAgent>>;
@@ -21,9 +24,9 @@ test.describe('OC - Livechat - Cross Tab Communication', () => {
2124
});
2225

2326
test.beforeEach(async ({ browser, api }) => {
24-
const context = await browser.newContext();
25-
const p1 = await context.newPage();
26-
const p2 = await context.newPage();
27+
livechatContext = await browser.newContext();
28+
const p1 = await livechatContext.newPage();
29+
const p2 = await livechatContext.newPage();
2730

2831
pageLivechat1 = new OmnichannelLiveChat(p1, api);
2932
pageLivechat2 = new OmnichannelLiveChat(p2, api);
@@ -33,8 +36,8 @@ test.describe('OC - Livechat - Cross Tab Communication', () => {
3336
});
3437

3538
test.afterEach(async () => {
36-
await pageLivechat1.page.close();
37-
await pageLivechat2.page.close();
39+
// Both pages share the same context; closing it disposes both pages
40+
await livechatContext.close();
3841
});
3942

4043
test.afterAll(async () => {

0 commit comments

Comments
 (0)