diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 064a535f..b6a5f161 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 58906196..fa96c182 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 f57d5ca2..6fdff430 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 () => {