|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { browserTest as it, expect } from '../config/browserTest'; |
| 18 | + |
| 19 | +it('should throw when apiRequestFailsOnErrorStatus is set to true inside BrowserContext options', async ({ browser, server }) => { |
| 20 | + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/34204' }); |
| 21 | + const context = await browser.newContext({ apiRequestFailsOnErrorStatus: true }); |
| 22 | + server.setRoute('/empty.html', (req, res) => { |
| 23 | + res.writeHead(404, { 'Content-Length': 10, 'Content-Type': 'text/plain' }); |
| 24 | + res.end('Not found.'); |
| 25 | + }); |
| 26 | + const error = await context.request.fetch(server.EMPTY_PAGE).catch(e => e); |
| 27 | + expect(error.message).toContain('404 Not Found'); |
| 28 | + await context.close(); |
| 29 | +}); |
| 30 | + |
| 31 | +it('should not throw when failOnStatusCode is set to false inside BrowserContext options', async ({ browser, server }) => { |
| 32 | + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/34204' }); |
| 33 | + const context = await browser.newContext({ apiRequestFailsOnErrorStatus: false }); |
| 34 | + server.setRoute('/empty.html', (req, res) => { |
| 35 | + res.writeHead(404, { 'Content-Length': 10, 'Content-Type': 'text/plain' }); |
| 36 | + res.end('Not found.'); |
| 37 | + }); |
| 38 | + const error = await context.request.fetch(server.EMPTY_PAGE).catch(e => e); |
| 39 | + expect(error.message).toBeUndefined(); |
| 40 | + await context.close(); |
| 41 | +}); |
| 42 | + |
| 43 | +it('should throw when apiRequestFailsOnErrorStatus is set to true inside browserType.launchPersistentContext options', async ({ browserType, server, createUserDataDir }) => { |
| 44 | + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/34204' }); |
| 45 | + const userDataDir = await createUserDataDir(); |
| 46 | + const context = await browserType.launchPersistentContext(userDataDir, { apiRequestFailsOnErrorStatus: true }); |
| 47 | + server.setRoute('/empty.html', (req, res) => { |
| 48 | + res.writeHead(404, { 'Content-Length': 10, 'Content-Type': 'text/plain' }); |
| 49 | + res.end('Not found.'); |
| 50 | + }); |
| 51 | + const error = await context.request.fetch(server.EMPTY_PAGE).catch(e => e); |
| 52 | + expect(error.message).toContain('404 Not Found'); |
| 53 | + await context.close(); |
| 54 | +}); |
| 55 | + |
| 56 | +it('should not throw when apiRequestFailsOnErrorStatus is set to false inside browserType.launchPersistentContext options', async ({ browserType, server, createUserDataDir }) => { |
| 57 | + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/34204' }); |
| 58 | + const userDataDir = await createUserDataDir(); |
| 59 | + const context = await browserType.launchPersistentContext(userDataDir, { apiRequestFailsOnErrorStatus: false }); |
| 60 | + server.setRoute('/empty.html', (req, res) => { |
| 61 | + res.writeHead(404, { 'Content-Length': 10, 'Content-Type': 'text/plain' }); |
| 62 | + res.end('Not found.'); |
| 63 | + }); |
| 64 | + const error = await context.request.fetch(server.EMPTY_PAGE).catch(e => e); |
| 65 | + expect(error.message).toBeUndefined(); |
| 66 | + await context.close(); |
| 67 | +}); |
0 commit comments