From ade6ad89f489c825db7c7faf84d8e808978740c8 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Mon, 5 Jun 2023 18:11:30 +0200 Subject: [PATCH] test: update bidi tests for firefox (#10316) --- test/TestExpectations.json | 18 ------------------ test/src/mocha-utils.ts | 31 +++++++++++++++++++++++++++++++ test/src/navigation.spec.ts | 17 ++++++++++------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 064a535fc41..b6a5f1618e1 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -1283,24 +1283,6 @@ "parameters": ["firefox", "webDriverBiDi"], "expectations": ["FAIL", "PASS"] }, - { - "testIdPattern": "[navigation.spec] navigation Page.goto should fail when navigating to bad SSL after redirects", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["firefox", "webDriverBiDi"], - "expectations": ["FAIL"] - }, - { - "testIdPattern": "[navigation.spec] navigation Page.goto should fail when navigating to bad url", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["FAIL"] - }, - { - "testIdPattern": "[navigation.spec] navigation Page.goto should fail when navigating to bad url", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["firefox", "webDriverBiDi"], - "expectations": ["FAIL"] - }, { "testIdPattern": "[navigation.spec] navigation Page.goto should fail when server returns 204", "platforms": ["darwin", "linux", "win32"], diff --git a/test/src/mocha-utils.ts b/test/src/mocha-utils.ts index 58906196d31..fa96c182c39 100644 --- a/test/src/mocha-utils.ts +++ b/test/src/mocha-utils.ts @@ -250,6 +250,37 @@ export const mochaHooks = { }, }; +declare module 'expect' { + interface Matchers { + atLeastOneToContain(expected: string[]): R; + } +} + +expect.extend({ + atLeastOneToContain: (actual: string, expected: string[]) => { + for (const test of expected) { + try { + expect(actual).toContain(test); + return { + pass: true, + message: () => { + return ''; + }, + }; + } catch (err) {} + } + + return { + pass: false, + message: () => { + return `"${actual}" didn't contain any of the strings ${JSON.stringify( + expected + )}`; + }, + }; + }, +}); + export const expectCookieEquals = ( cookies: Protocol.Network.Cookie[], expectedCookies: Array> diff --git a/test/src/navigation.spec.ts b/test/src/navigation.spec.ts index f57d5ca2fc3..6fdff4307b2 100644 --- a/test/src/navigation.spec.ts +++ b/test/src/navigation.spec.ts @@ -142,17 +142,17 @@ describe('navigation', function () { expect(response!.status()).toBe(200); }); it('should fail when navigating to bad url', async () => { - const {page, isChrome} = getTestState(); + const {page} = getTestState(); let error!: Error; await page.goto('asdfasdf').catch(error_ => { return (error = error_); }); - if (isChrome) { - expect(error.message).toContain('Cannot navigate to invalid URL'); - } else { - expect(error.message).toContain('Invalid url'); - } + + expect(error.message).atLeastOneToContain([ + 'Cannot navigate to invalid URL', // Firefox WebDriver BiDi. + 'invalid argument', // Others. + ]); }); const EXPECTED_SSL_CERT_MESSAGE_REGEX = @@ -200,7 +200,10 @@ describe('navigation', function () { if (isChrome) { expect(error.message).toMatch(EXPECTED_SSL_CERT_MESSAGE_REGEX); } else { - expect(error.message).toContain('SSL_ERROR_UNKNOWN'); + expect(error.message).atLeastOneToContain([ + 'MOZILLA_PKIX_ERROR_SELF_SIGNED_CERT', // Firefox WebDriver BiDi. + 'SSL_ERROR_UNKNOWN ', // Others. + ]); } }); it('should fail when main resources failed to load', async () => {