-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat: add failOnStatusCode option to API request context #34346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e396554
feat: add failOnStatusCode option to API request context
JacksonLei123 7925615
Merge branch 'microsoft:main' into main
JacksonLei123 3dd6e86
fix: fixing eslint errors
JacksonLei123 40d8f2c
Merge branch 'main' of https://github.com/JacksonLei123/playwright
JacksonLei123 c1d510a
feat: update protocol.yml file to include fetchFailOnStatusCode flag.…
JacksonLei123 9d15722
Merge branch 'microsoft:main' into main
JacksonLei123 b2b8e32
fix: remove edits to auto-generated files
JacksonLei123 905f921
Merge branch 'main' of https://github.com/JacksonLei123/playwright
JacksonLei123 7044db8
fix: add version in apiRequestClass context
JacksonLei123 98155ab
feat: remove fetchFailOnStatusCode protocol change
JacksonLei123 3756a24
re add fetchFailOnStatusCode flag in protocol.yml file
JacksonLei123 30d9e05
feat: add generated files from build
JacksonLei123 b42bf79
Update tests/library/global-fetch.spec.ts
JacksonLei123 ee59e0f
fix: lint fixes from suggested commit
JacksonLei123 592829c
feat: update flag to be named apiRequestFailsOnErrorStatus
JacksonLei123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
tests/library/browsercontext-fetchFailOnStatusCode.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { browserTest as it, expect } from '../config/browserTest'; | ||
|
||
it('should throw when apiRequestFailsOnErrorStatus is set to true inside BrowserContext options', async ({ browser, server }) => { | ||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/34204' }); | ||
const context = await browser.newContext({ apiRequestFailsOnErrorStatus: true }); | ||
server.setRoute('/empty.html', (req, res) => { | ||
res.writeHead(404, { 'Content-Length': 10, 'Content-Type': 'text/plain' }); | ||
res.end('Not found.'); | ||
}); | ||
const error = await context.request.fetch(server.EMPTY_PAGE).catch(e => e); | ||
expect(error.message).toContain('404 Not Found'); | ||
await context.close(); | ||
}); | ||
|
||
it('should not throw when failOnStatusCode is set to false inside BrowserContext options', async ({ browser, server }) => { | ||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/34204' }); | ||
const context = await browser.newContext({ apiRequestFailsOnErrorStatus: false }); | ||
server.setRoute('/empty.html', (req, res) => { | ||
res.writeHead(404, { 'Content-Length': 10, 'Content-Type': 'text/plain' }); | ||
res.end('Not found.'); | ||
}); | ||
const error = await context.request.fetch(server.EMPTY_PAGE).catch(e => e); | ||
expect(error.message).toBeUndefined(); | ||
await context.close(); | ||
}); | ||
|
||
it('should throw when apiRequestFailsOnErrorStatus is set to true inside browserType.launchPersistentContext options', async ({ browserType, server, createUserDataDir }) => { | ||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/34204' }); | ||
const userDataDir = await createUserDataDir(); | ||
const context = await browserType.launchPersistentContext(userDataDir, { apiRequestFailsOnErrorStatus: true }); | ||
server.setRoute('/empty.html', (req, res) => { | ||
res.writeHead(404, { 'Content-Length': 10, 'Content-Type': 'text/plain' }); | ||
res.end('Not found.'); | ||
}); | ||
const error = await context.request.fetch(server.EMPTY_PAGE).catch(e => e); | ||
expect(error.message).toContain('404 Not Found'); | ||
await context.close(); | ||
}); | ||
|
||
it('should not throw when apiRequestFailsOnErrorStatus is set to false inside browserType.launchPersistentContext options', async ({ browserType, server, createUserDataDir }) => { | ||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/34204' }); | ||
const userDataDir = await createUserDataDir(); | ||
const context = await browserType.launchPersistentContext(userDataDir, { apiRequestFailsOnErrorStatus: false }); | ||
server.setRoute('/empty.html', (req, res) => { | ||
res.writeHead(404, { 'Content-Length': 10, 'Content-Type': 'text/plain' }); | ||
res.end('Not found.'); | ||
}); | ||
const error = await context.request.fetch(server.EMPTY_PAGE).catch(e => e); | ||
expect(error.message).toBeUndefined(); | ||
await context.close(); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should probably be renamed in accord with the new name of the property.