Skip to content

Commit 354e6fa

Browse files
authored
test: do not depend on the api name prefix of error messages (#44162)
1 parent 1aa8478 commit 354e6fa

39 files changed

Lines changed: 91 additions & 94 deletions

‎tests/library/browsercontext-fetch.spec.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ it('FE-092 should throw on network error', async ({ context, server }) => {
110110
req.socket.destroy();
111111
});
112112
const error = await context.request.get(server.PREFIX + '/test').catch(e => e);
113-
expect(error.message).toContain('apiRequestContext.get: socket hang up');
113+
expect(error.message).toContain('socket hang up');
114114
});
115115

116116
it('FE-093 should throw on network error after redirect', async ({ context, server }) => {
@@ -119,7 +119,7 @@ it('FE-093 should throw on network error after redirect', async ({ context, serv
119119
req.socket.destroy();
120120
});
121121
const error = await context.request.get(server.PREFIX + '/redirect').catch(e => e);
122-
expect(error.message).toContain('apiRequestContext.get: socket hang up');
122+
expect(error.message).toContain('socket hang up');
123123
});
124124

125125
it('FE-094 should throw on network error when sending body', async ({ context, server }) => {
@@ -133,7 +133,7 @@ it('FE-094 should throw on network error when sending body', async ({ context, s
133133
req.socket.destroy();
134134
});
135135
const error = await context.request.get(server.PREFIX + '/test').catch(e => e);
136-
expect(error.message).toContain('apiRequestContext.get: aborted');
136+
expect(error.message).toContain('aborted');
137137
});
138138

139139
it('FE-095 should throw on network error when sending body after redirect', async ({ context, server }) => {
@@ -148,7 +148,7 @@ it('FE-095 should throw on network error when sending body after redirect', asyn
148148
req.socket.destroy();
149149
});
150150
const error = await context.request.get(server.PREFIX + '/redirect').catch(e => e);
151-
expect(error.message).toContain('apiRequestContext.get: aborted');
151+
expect(error.message).toContain('aborted');
152152
});
153153

154154
it('FE-096 should add session cookies to request', async ({ context, server }) => {
@@ -1018,7 +1018,7 @@ it('FE-148 should support timeout option', async function({ context, server }) {
10181018
});
10191019

10201020
const error = await context.request.get(server.PREFIX + '/slow', { timeout: 10 }).catch(e => e);
1021-
expect(error.message).toContain(`apiRequestContext.get: Timeout 10ms exceeded`);
1021+
expect(error.message).toContain(`Timeout 10ms exceeded`);
10221022
});
10231023

10241024
it('FE-149 should support a timeout of 0', async function({ context, server }) {
@@ -1049,7 +1049,7 @@ it('FE-150 should respect timeout after redirects', async function({ context, se
10491049

10501050
context.setDefaultTimeout(100);
10511051
const error = await context.request.get(server.PREFIX + '/redirect').catch(e => e);
1052-
expect(error.message).toContain(`apiRequestContext.get: Timeout 100ms exceeded`);
1052+
expect(error.message).toContain(`Timeout 100ms exceeded`);
10531053
});
10541054

10551055
it('FE-151 should not hang on a brotli encoded Range request', async ({ context, server, nodeVersion }) => {

‎tests/library/browsercontext-storage-state.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ it('ST-003 should report good error if the url is not valid', async ({ contextFa
112112
]
113113
}
114114
}).catch(e => e);
115-
expect(error.message).toContain('browser.newContext: Error setting storage state:');
115+
expect(error.message).toContain('Error setting storage state:');
116116
expect(error.message).toContain('foo');
117117
});
118118

‎tests/library/browsertype-connect.spec.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ for (const kind of ['launchServer', 'run-server'] as const) {
141141
});
142142
});
143143
const error = await connect(`ws://localhost:${server.PORT}/ws`).catch(e => e);
144-
expect(error.message).toContain('browserType.connect: Oh my!');
144+
expect(error.message).toContain('Oh my!');
145145
});
146146

147147
test('BT-038 should be able to reconnect to a browser', async ({ connect, startRemoteServer, server }) => {
@@ -245,14 +245,14 @@ for (const kind of ['launchServer', 'run-server'] as const) {
245245
const e = await connect(`ws://localhost:${server.PORT}/ws-slow`, {
246246
timeout: 1000,
247247
}).catch(e => e);
248-
expect(e.message).toContain('browserType.connect: Timeout 1000ms exceeded');
248+
expect(e.message).toContain('Timeout 1000ms exceeded');
249249
});
250250

251251
test('BT-045 should timeout in connect while connecting', async ({ connect, server }) => {
252252
const e = await connect(`ws://localhost:${server.PORT}/ws`, {
253253
timeout: 100,
254254
}).catch(e => e);
255-
expect(e.message).toContain('browserType.connect: Timeout 100ms exceeded');
255+
expect(e.message).toContain('Timeout 100ms exceeded');
256256
});
257257

258258
test('BT-046 should send extra headers with connect request', async ({ connect, server }) => {

‎tests/library/browsertype-launch.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ it('BT-010 should reject if launched browser fails immediately', async ({ mode,
6666
if (channel === 'webkit-wsl')
6767
expect(error.message).toContain('Failed to launch');
6868
else
69-
expect(error.message).toMatch(/browserType\.launch(.|\n)*(spawn UNKNOWN|spawn EFTYPE|Browser logs:)/gim);
69+
expect(error.message).toMatch(/(spawn UNKNOWN|spawn EFTYPE|Browser logs:)/gim);
7070
});
7171

7272
it('BT-011 should reject if executable path is invalid', async ({ browserType, mode }) => {
@@ -80,7 +80,7 @@ it('BT-012 should handle timeout', async ({ browserType, mode }) => {
8080

8181
const options: any = { timeout: 5000, __testHookBeforeCreateBrowser: () => new Promise(f => setTimeout(f, 6000)) };
8282
const error = await browserType.launch(options).catch(e => e);
83-
expect(error!.message).toContain(`browserType.launch: Timeout 5000ms exceeded.`);
83+
expect(error!.message).toContain(`Timeout 5000ms exceeded.`);
8484
expect(error!.message).toContain(`<launching>`);
8585
expect(error!.message).toContain(`<launched> pid=`);
8686
});

‎tests/library/chromium/connect-over-cdp.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ test('CD-020 should report an expected error when the endpointURL returns a non-
587587
});
588588
await expect(browserType.connectOverCDP({
589589
endpointURL: server.PREFIX,
590-
})).rejects.toThrowError(`browserType.connectOverCDP: Unexpected status 404 when connecting to ${server.PREFIX}/json/version/`);
590+
})).rejects.toThrowError(`Unexpected status 404 when connecting to ${server.PREFIX}/json/version/`);
591591
});
592592

593593
test('CD-021 should report an expected error when the endpoint URL JSON webSocketDebuggerUrl is undefined', async ({ browserType, server }) => {
@@ -598,7 +598,7 @@ test('CD-021 should report an expected error when the endpoint URL JSON webSocke
598598
});
599599
await expect(browserType.connectOverCDP({
600600
endpointURL: server.PREFIX,
601-
})).rejects.toThrowError('browserType.connectOverCDP: Invalid URL');
601+
})).rejects.toThrowError('Invalid URL');
602602
});
603603

604604
test('CD-022 should connect to an existing cdp session when passed as a first argument', async ({ browserType }, testInfo) => {

‎tests/library/defaultbrowsercontext-2.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ it('DC-030 should have passed URL when launching with ignoreDefaultArgs: true',
195195
it('DC-031 should handle timeout', async ({ browserType, createUserDataDir }) => {
196196
const options: any = { timeout: 5000, __testHookBeforeCreateBrowser: () => new Promise(f => setTimeout(f, 6000)) };
197197
const error = await browserType.launchPersistentContext(await createUserDataDir(), options).catch(e => e);
198-
expect(error.message).toContain(`browserType.launchPersistentContext: Timeout 5000ms exceeded.`);
198+
expect(error.message).toContain(`Timeout 5000ms exceeded.`);
199199
});
200200

201201
it('DC-032 should handle exception', async ({ browserType, createUserDataDir }) => {

‎tests/library/download.spec.ts‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,8 @@ it.describe('download event', () => {
431431
download.saveAs(testInfo.outputPath('download.txt')).catch(e => e),
432432
page.context().close(),
433433
]);
434-
expect(downloadError.message).toBe('download.path: canceled');
435-
expect([
436-
'download.saveAs: File not found on disk. Check download.failure() for details.',
437-
'download.saveAs: canceled',
438-
]).toContain(saveError.message);
434+
expect(downloadError.message).toContain('canceled');
435+
expect(['File not found on disk. Check download.failure() for details.', 'canceled'].some(m => saveError.message.includes(m))).toBe(true);
439436
});
440437

441438
it('DO-024 should close the context without awaiting the download', async ({ browser, server, browserName, platform, channel }, testInfo) => {
@@ -463,14 +460,8 @@ it.describe('download event', () => {
463460
]);
464461
// The exact error message is racy, because sometimes browser is fast enough
465462
// to cancel the download.
466-
expect([
467-
'download.path: canceled',
468-
'download.path: ' + kTargetClosedErrorMessage,
469-
]).toContain(downloadError.message);
470-
expect([
471-
'download.saveAs: canceled',
472-
'download.saveAs: ' + kTargetClosedErrorMessage,
473-
]).toContain(saveError.message);
463+
expect(['canceled', kTargetClosedErrorMessage].some(m => downloadError.message.includes(m))).toBe(true);
464+
expect(['canceled', kTargetClosedErrorMessage].some(m => saveError.message.includes(m))).toBe(true);
474465
});
475466

476467
it('DO-025 should throw if browser dies', async ({ server, browserType, browserName, platform, channel }, testInfo) => {
@@ -495,8 +486,8 @@ it.describe('download event', () => {
495486
download.saveAs(testInfo.outputPath('download.txt')).catch(e => e),
496487
(browser as any)._channel.killForTests(),
497488
]);
498-
expect(downloadError.message).toBe('download.path: ' + kTargetClosedErrorMessage);
499-
expect(saveError.message).toContain('download.saveAs: ' + kTargetClosedErrorMessage);
489+
expect(downloadError.message).toContain(kTargetClosedErrorMessage);
490+
expect(saveError.message).toContain(kTargetClosedErrorMessage);
500491
await browser.close();
501492
});
502493

‎tests/library/global-fetch.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ it('FE-004 should support global timeout option', async ({ playwright, server })
7070
const request = await playwright.request.newContext({ timeout: 100 });
7171
server.setRoute('/empty.html', (req, res) => {});
7272
const error = await request.get(server.EMPTY_PAGE).catch(e => e);
73-
expect(error.message).toContain('apiRequestContext.get: Timeout 100ms exceeded');
73+
expect(error.message).toContain('Timeout 100ms exceeded');
7474
await request.dispose();
7575
});
7676

‎tests/library/hit-target.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ it('HT-001 should block all events when hit target is wrong', async ({ page, ser
4141
});
4242

4343
const error = await page.click('button', { timeout: 3000 }).catch(e => e);
44-
expect(error.message).toContain('page.click: Timeout 3000ms exceeded.');
44+
expect(error.message).toContain('Timeout 3000ms exceeded.');
4545

4646
// Give it some time, just in case.
4747
await page.waitForTimeout(1000);
@@ -108,7 +108,7 @@ it('HT-004 should block all events when hit target is wrong and element detaches
108108
});
109109

110110
const error = await page.click('button', { timeout: 3000 }).catch(e => e);
111-
expect(error.message).toContain('page.click: Timeout 3000ms exceeded.');
111+
expect(error.message).toContain('Timeout 3000ms exceeded.');
112112

113113
// Give it some time, just in case.
114114
await page.waitForTimeout(1000);

‎tests/library/inspector/pause.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ it('IN-002 should not reset timeouts', async ({ page, recorderPageGetter, closeR
4242

4343
server.setRoute('/empty.html', () => {});
4444
const error = await page.goto(server.EMPTY_PAGE).catch(e => e);
45-
expect(error.message).toContain('page.goto: Timeout 1000ms exceeded.');
45+
expect(error.message).toContain('Timeout 1000ms exceeded.');
4646
});
4747

4848
it('IN-003 should collapse log entries to a single line', async ({ page, recorderPageGetter }) => {

0 commit comments

Comments
 (0)