mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore(fetch): rename ApiRequest* to APIRequest* (#9606)
This commit is contained in:
parent
56d8481b87
commit
6d727401bf
@ -12,13 +12,13 @@ A few examples where it may come in handy:
|
||||
- Prepare server side state before visiting the web application in a test.
|
||||
- Validate server side post-conditions after running some actions in the browser.
|
||||
|
||||
All of that could be achieved via [ApiRequestContext] methods.
|
||||
All of that could be achieved via [APIRequestContext] methods.
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
## Writing API Test
|
||||
|
||||
[ApiRequestContext] can send all kinds of HTTP(S) requests over network.
|
||||
[APIRequestContext] can send all kinds of HTTP(S) requests over network.
|
||||
|
||||
The following example demonstrates how to use Playwright to test issues creation via [GitHub API](https://docs.github.com/en/rest). The test suite will do the following:
|
||||
- Create a new repository before running tests.
|
||||
@ -137,7 +137,7 @@ test.afterAll(async ({ request }) => {
|
||||
|
||||
### Using request context
|
||||
|
||||
Behind the scenes, `request` fixture will actually call [`method: ApiRequest.newContext`]. You can always do that manually if you'd like more control. Below is a standalone script that does the same as `beforeAll` and `afterAll` from above.
|
||||
Behind the scenes, `request` fixture will actually call [`method: APIRequest.newContext`]. You can always do that manually if you'd like more control. Below is a standalone script that does the same as `beforeAll` and `afterAll` from above.
|
||||
|
||||
```js
|
||||
const { request } = require('@playwright/test');
|
||||
@ -219,22 +219,22 @@ test('last created issue should be on the server', async ({ page, request }) =>
|
||||
- [`property: Playwright.request`]
|
||||
- [`property: BrowserContext.request`]
|
||||
- [`property: Page.request`]
|
||||
- [`method: ApiRequest.newContext`]
|
||||
- [`method: ApiRequestContext.delete`]
|
||||
- [`method: ApiRequestContext.fetch`]
|
||||
- [`method: ApiRequestContext.get`]
|
||||
- [`method: ApiRequestContext.post`]
|
||||
- [`method: APIRequest.newContext`]
|
||||
- [`method: APIRequestContext.delete`]
|
||||
- [`method: APIRequestContext.fetch`]
|
||||
- [`method: APIRequestContext.get`]
|
||||
- [`method: APIRequestContext.post`]
|
||||
|
||||
## Reuse authentication state
|
||||
|
||||
Web apps use cookie-based or token-based authentication, where authenticated
|
||||
state is stored as [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies).
|
||||
Playwright provides [`method: ApiRequestContext.storageState`] method that can be used to
|
||||
Playwright provides [`method: APIRequestContext.storageState`] method that can be used to
|
||||
retrieve storage state from an authenticated context and then create new contexts with that state.
|
||||
|
||||
Storage state is interchangeable between [BrowserContext] and [ApiRequestContext]. You can
|
||||
Storage state is interchangeable between [BrowserContext] and [APIRequestContext]. You can
|
||||
use it to log in via API calls and then create a new context with cookies already there.
|
||||
The following code snippet retrieves state from an authenticated [ApiRequestContext] and
|
||||
The following code snippet retrieves state from an authenticated [APIRequestContext] and
|
||||
creates a new [BrowserContext] with that state.
|
||||
|
||||
```js
|
||||
@ -254,6 +254,6 @@ const context = await browser.newContext({ storageState: 'state.json' });
|
||||
|
||||
### API reference
|
||||
- [`method: Browser.newContext`]
|
||||
- [`method: ApiRequestContext.storageState`]
|
||||
- [`method: ApiRequest.newContext`]
|
||||
- [`method: APIRequestContext.storageState`]
|
||||
- [`method: APIRequest.newContext`]
|
||||
|
||||
|
||||
@ -1,35 +1,35 @@
|
||||
# class: ApiRequest
|
||||
# class: APIRequest
|
||||
* langs: js
|
||||
|
||||
Exposes API that can be used for the Web API testing.
|
||||
|
||||
## async method: ApiRequest.newContext
|
||||
## async method: APIRequest.newContext
|
||||
* langs: js
|
||||
- returns: <[ApiRequestContext]>
|
||||
- returns: <[APIRequestContext]>
|
||||
|
||||
Creates new instances of [ApiRequestContext].
|
||||
Creates new instances of [APIRequestContext].
|
||||
|
||||
### option: ApiRequest.newContext.useragent = %%-context-option-useragent-%%
|
||||
### option: ApiRequest.newContext.extraHTTPHeaders = %%-context-option-extrahttpheaders-%%
|
||||
### option: ApiRequest.newContext.httpCredentials = %%-context-option-httpcredentials-%%
|
||||
### option: ApiRequest.newContext.proxy = %%-browser-option-proxy-%%
|
||||
### option: ApiRequest.newContext.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
### option: APIRequest.newContext.useragent = %%-context-option-useragent-%%
|
||||
### option: APIRequest.newContext.extraHTTPHeaders = %%-context-option-extrahttpheaders-%%
|
||||
### option: APIRequest.newContext.httpCredentials = %%-context-option-httpcredentials-%%
|
||||
### option: APIRequest.newContext.proxy = %%-browser-option-proxy-%%
|
||||
### option: APIRequest.newContext.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
|
||||
### option: ApiRequest.newContext.timeout
|
||||
### option: APIRequest.newContext.timeout
|
||||
- `timeout` <[float]>
|
||||
|
||||
Maximum time in milliseconds to wait for the response. Defaults to
|
||||
`30000` (30 seconds). Pass `0` to disable timeout.
|
||||
|
||||
|
||||
### option: ApiRequest.newContext.baseURL
|
||||
### option: APIRequest.newContext.baseURL
|
||||
- `baseURL` <[string]>
|
||||
|
||||
Methods like [`method: ApiRequestContext.get`] take the base URL into consideration by using the [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor for building the corresponding URL. Examples:
|
||||
Methods like [`method: APIRequestContext.get`] take the base URL into consideration by using the [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor for building the corresponding URL. Examples:
|
||||
* baseURL: `http://localhost:3000` and sending request to `/bar.html` results in `http://localhost:3000/bar.html`
|
||||
* baseURL: `http://localhost:3000/foo/` and sending request to `./bar.html` results in `http://localhost:3000/foo/bar.html`
|
||||
|
||||
### option: ApiRequest.newContext.storageState
|
||||
### option: APIRequest.newContext.storageState
|
||||
- `storageState` <[path]|[Object]>
|
||||
- `cookies` <[Array]<[Object]>>
|
||||
- `name` <[string]>
|
||||
@ -47,7 +47,7 @@ Methods like [`method: ApiRequestContext.get`] take the base URL into considerat
|
||||
- `value` <[string]>
|
||||
|
||||
Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
obtained via [`method: BrowserContext.storageState`] or [`method: ApiRequestContext.storageState`]. Either a path to the
|
||||
obtained via [`method: BrowserContext.storageState`] or [`method: APIRequestContext.storageState`]. Either a path to the
|
||||
file with saved storage, or the value returned by one of [`method: BrowserContext.storageState`] or
|
||||
[`method: ApiRequestContext.storageState`] methods.
|
||||
[`method: APIRequestContext.storageState`] methods.
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# class: ApiRequestContext
|
||||
# class: APIRequestContext
|
||||
* langs: js
|
||||
|
||||
This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare
|
||||
@ -6,132 +6,132 @@ environment or the service to your e2e test. When used on [Page] or a [BrowserCo
|
||||
the cookies from the corresponding [BrowserContext]. This means that if you log in using this API, your e2e test
|
||||
will be logged in and vice versa.
|
||||
|
||||
## async method: ApiRequestContext.delete
|
||||
## async method: APIRequestContext.delete
|
||||
- returns: <[ApiResponse]>
|
||||
|
||||
Sends HTTP(S) [DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE) request and returns its response.
|
||||
The method will populate request cookies from the context and update
|
||||
context cookies from the response. The method will automatically follow redirects.
|
||||
|
||||
### param: ApiRequestContext.delete.url = %%-fetch-param-url-%%
|
||||
### option: ApiRequestContext.delete.params = %%-fetch-option-params-%%
|
||||
### option: ApiRequestContext.delete.headers = %%-fetch-option-headers-%%
|
||||
### option: ApiRequestContext.delete.timeout = %%-fetch-option-timeout-%%
|
||||
### option: ApiRequestContext.delete.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: ApiRequestContext.delete.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
### param: APIRequestContext.delete.url = %%-fetch-param-url-%%
|
||||
### option: APIRequestContext.delete.params = %%-fetch-option-params-%%
|
||||
### option: APIRequestContext.delete.headers = %%-fetch-option-headers-%%
|
||||
### option: APIRequestContext.delete.timeout = %%-fetch-option-timeout-%%
|
||||
### option: APIRequestContext.delete.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: APIRequestContext.delete.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
|
||||
## async method: ApiRequestContext.dispose
|
||||
## async method: APIRequestContext.dispose
|
||||
|
||||
All responses returned by [`method: ApiRequestContext.get`] and similar methods are stored in the memory, so that you can later call [`method: ApiResponse.body`]. This method
|
||||
All responses returned by [`method: APIRequestContext.get`] and similar methods are stored in the memory, so that you can later call [`method: ApiResponse.body`]. This method
|
||||
discards all stored responses, and makes [`method: ApiResponse.body`] throw "Response disposed" error.
|
||||
|
||||
## async method: ApiRequestContext.fetch
|
||||
## async method: APIRequestContext.fetch
|
||||
- returns: <[ApiResponse]>
|
||||
|
||||
Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
||||
context cookies from the response. The method will automatically follow redirects.
|
||||
|
||||
### param: ApiRequestContext.fetch.urlOrRequest
|
||||
### param: APIRequestContext.fetch.urlOrRequest
|
||||
- `urlOrRequest` <[string]|[Request]>
|
||||
|
||||
Target URL or Request to get all parameters from.
|
||||
|
||||
### option: ApiRequestContext.fetch.params = %%-fetch-option-params-%%
|
||||
### option: APIRequestContext.fetch.params = %%-fetch-option-params-%%
|
||||
|
||||
### option: ApiRequestContext.fetch.method
|
||||
### option: APIRequestContext.fetch.method
|
||||
- `method` <[string]>
|
||||
|
||||
If set changes the fetch method (e.g. [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) or
|
||||
[POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)). If not specified, GET method is used.
|
||||
|
||||
### option: ApiRequestContext.fetch.headers = %%-fetch-option-headers-%%
|
||||
### option: ApiRequestContext.fetch.data = %%-fetch-option-data-%%
|
||||
### option: ApiRequestContext.fetch.form = %%-fetch-option-form-%%
|
||||
### option: ApiRequestContext.fetch.multipart = %%-fetch-option-multipart-%%
|
||||
### option: ApiRequestContext.fetch.timeout = %%-fetch-option-timeout-%%
|
||||
### option: ApiRequestContext.fetch.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: ApiRequestContext.fetch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
### option: APIRequestContext.fetch.headers = %%-fetch-option-headers-%%
|
||||
### option: APIRequestContext.fetch.data = %%-fetch-option-data-%%
|
||||
### option: APIRequestContext.fetch.form = %%-fetch-option-form-%%
|
||||
### option: APIRequestContext.fetch.multipart = %%-fetch-option-multipart-%%
|
||||
### option: APIRequestContext.fetch.timeout = %%-fetch-option-timeout-%%
|
||||
### option: APIRequestContext.fetch.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: APIRequestContext.fetch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
|
||||
## async method: ApiRequestContext.get
|
||||
## async method: APIRequestContext.get
|
||||
- returns: <[ApiResponse]>
|
||||
|
||||
Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request and returns its response.
|
||||
The method will populate request cookies from the context and update
|
||||
context cookies from the response. The method will automatically follow redirects.
|
||||
|
||||
### param: ApiRequestContext.get.url = %%-fetch-param-url-%%
|
||||
### option: ApiRequestContext.get.params = %%-fetch-option-params-%%
|
||||
### option: ApiRequestContext.get.headers = %%-fetch-option-headers-%%
|
||||
### option: ApiRequestContext.get.timeout = %%-fetch-option-timeout-%%
|
||||
### option: ApiRequestContext.get.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: ApiRequestContext.get.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
### param: APIRequestContext.get.url = %%-fetch-param-url-%%
|
||||
### option: APIRequestContext.get.params = %%-fetch-option-params-%%
|
||||
### option: APIRequestContext.get.headers = %%-fetch-option-headers-%%
|
||||
### option: APIRequestContext.get.timeout = %%-fetch-option-timeout-%%
|
||||
### option: APIRequestContext.get.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: APIRequestContext.get.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
|
||||
## async method: ApiRequestContext.head
|
||||
## async method: APIRequestContext.head
|
||||
- returns: <[ApiResponse]>
|
||||
|
||||
Sends HTTP(S) [HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) request and returns its response.
|
||||
The method will populate request cookies from the context and update
|
||||
context cookies from the response. The method will automatically follow redirects.
|
||||
|
||||
### param: ApiRequestContext.head.url = %%-fetch-param-url-%%
|
||||
### option: ApiRequestContext.head.params = %%-fetch-option-params-%%
|
||||
### option: ApiRequestContext.head.headers = %%-fetch-option-headers-%%
|
||||
### option: ApiRequestContext.head.timeout = %%-fetch-option-timeout-%%
|
||||
### option: ApiRequestContext.head.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: ApiRequestContext.head.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
### param: APIRequestContext.head.url = %%-fetch-param-url-%%
|
||||
### option: APIRequestContext.head.params = %%-fetch-option-params-%%
|
||||
### option: APIRequestContext.head.headers = %%-fetch-option-headers-%%
|
||||
### option: APIRequestContext.head.timeout = %%-fetch-option-timeout-%%
|
||||
### option: APIRequestContext.head.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: APIRequestContext.head.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
|
||||
## async method: ApiRequestContext.patch
|
||||
## async method: APIRequestContext.patch
|
||||
- returns: <[ApiResponse]>
|
||||
|
||||
Sends HTTP(S) [PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH) request and returns its response.
|
||||
The method will populate request cookies from the context and update
|
||||
context cookies from the response. The method will automatically follow redirects.
|
||||
|
||||
### param: ApiRequestContext.patch.url = %%-fetch-param-url-%%
|
||||
### option: ApiRequestContext.patch.params = %%-fetch-option-params-%%
|
||||
### option: ApiRequestContext.patch.headers = %%-fetch-option-headers-%%
|
||||
### option: ApiRequestContext.patch.data = %%-fetch-option-data-%%
|
||||
### option: ApiRequestContext.patch.form = %%-fetch-option-form-%%
|
||||
### option: ApiRequestContext.patch.multipart = %%-fetch-option-multipart-%%
|
||||
### option: ApiRequestContext.patch.timeout = %%-fetch-option-timeout-%%
|
||||
### option: ApiRequestContext.patch.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: ApiRequestContext.patch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
### param: APIRequestContext.patch.url = %%-fetch-param-url-%%
|
||||
### option: APIRequestContext.patch.params = %%-fetch-option-params-%%
|
||||
### option: APIRequestContext.patch.headers = %%-fetch-option-headers-%%
|
||||
### option: APIRequestContext.patch.data = %%-fetch-option-data-%%
|
||||
### option: APIRequestContext.patch.form = %%-fetch-option-form-%%
|
||||
### option: APIRequestContext.patch.multipart = %%-fetch-option-multipart-%%
|
||||
### option: APIRequestContext.patch.timeout = %%-fetch-option-timeout-%%
|
||||
### option: APIRequestContext.patch.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: APIRequestContext.patch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
|
||||
## async method: ApiRequestContext.post
|
||||
## async method: APIRequestContext.post
|
||||
- returns: <[ApiResponse]>
|
||||
|
||||
Sends HTTP(S) [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request and returns its response.
|
||||
The method will populate request cookies from the context and update
|
||||
context cookies from the response. The method will automatically follow redirects.
|
||||
|
||||
### param: ApiRequestContext.post.url = %%-fetch-param-url-%%
|
||||
### option: ApiRequestContext.post.params = %%-fetch-option-params-%%
|
||||
### option: ApiRequestContext.post.headers = %%-fetch-option-headers-%%
|
||||
### option: ApiRequestContext.post.data = %%-fetch-option-data-%%
|
||||
### option: ApiRequestContext.post.form = %%-fetch-option-form-%%
|
||||
### option: ApiRequestContext.post.multipart = %%-fetch-option-multipart-%%
|
||||
### option: ApiRequestContext.post.timeout = %%-fetch-option-timeout-%%
|
||||
### option: ApiRequestContext.post.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: ApiRequestContext.post.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
### param: APIRequestContext.post.url = %%-fetch-param-url-%%
|
||||
### option: APIRequestContext.post.params = %%-fetch-option-params-%%
|
||||
### option: APIRequestContext.post.headers = %%-fetch-option-headers-%%
|
||||
### option: APIRequestContext.post.data = %%-fetch-option-data-%%
|
||||
### option: APIRequestContext.post.form = %%-fetch-option-form-%%
|
||||
### option: APIRequestContext.post.multipart = %%-fetch-option-multipart-%%
|
||||
### option: APIRequestContext.post.timeout = %%-fetch-option-timeout-%%
|
||||
### option: APIRequestContext.post.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: APIRequestContext.post.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
|
||||
## async method: ApiRequestContext.put
|
||||
## async method: APIRequestContext.put
|
||||
- returns: <[ApiResponse]>
|
||||
|
||||
Sends HTTP(S) [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) request and returns its response.
|
||||
The method will populate request cookies from the context and update
|
||||
context cookies from the response. The method will automatically follow redirects.
|
||||
|
||||
### param: ApiRequestContext.put.url = %%-fetch-param-url-%%
|
||||
### option: ApiRequestContext.put.params = %%-fetch-option-params-%%
|
||||
### option: ApiRequestContext.put.headers = %%-fetch-option-headers-%%
|
||||
### option: ApiRequestContext.put.data = %%-fetch-option-data-%%
|
||||
### option: ApiRequestContext.put.form = %%-fetch-option-form-%%
|
||||
### option: ApiRequestContext.put.multipart = %%-fetch-option-multipart-%%
|
||||
### option: ApiRequestContext.put.timeout = %%-fetch-option-timeout-%%
|
||||
### option: ApiRequestContext.put.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: ApiRequestContext.put.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
### param: APIRequestContext.put.url = %%-fetch-param-url-%%
|
||||
### option: APIRequestContext.put.params = %%-fetch-option-params-%%
|
||||
### option: APIRequestContext.put.headers = %%-fetch-option-headers-%%
|
||||
### option: APIRequestContext.put.data = %%-fetch-option-data-%%
|
||||
### option: APIRequestContext.put.form = %%-fetch-option-form-%%
|
||||
### option: APIRequestContext.put.multipart = %%-fetch-option-multipart-%%
|
||||
### option: APIRequestContext.put.timeout = %%-fetch-option-timeout-%%
|
||||
### option: APIRequestContext.put.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||
### option: APIRequestContext.put.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||
|
||||
## async method: ApiRequestContext.storageState
|
||||
## async method: APIRequestContext.storageState
|
||||
- returns: <[Object]>
|
||||
- `cookies` <[Array]<[Object]>>
|
||||
- `name` <[string]>
|
||||
@ -150,4 +150,4 @@ context cookies from the response. The method will automatically follow redirect
|
||||
|
||||
Returns storage state for this request context, contains current cookies and local storage snapshot if it was passed to the constructor.
|
||||
|
||||
### option: ApiRequestContext.storageState.path = %%-storagestate-option-path-%%
|
||||
### option: APIRequestContext.storageState.path = %%-storagestate-option-path-%%
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
# class: ApiResponse
|
||||
* langs: js
|
||||
|
||||
[ApiResponse] class represents responses returned by [`method: ApiRequestContext.get`] and similar methods.
|
||||
[ApiResponse] class represents responses returned by [`method: APIRequestContext.get`] and similar methods.
|
||||
|
||||
## async method: ApiResponse.body
|
||||
- returns: <[Buffer]>
|
||||
|
||||
@ -851,7 +851,7 @@ Returns all open pages in the context.
|
||||
|
||||
## property: BrowserContext.request
|
||||
* langs: js
|
||||
- type: <[ApiRequestContext]>
|
||||
- type: <[APIRequestContext]>
|
||||
|
||||
API testing helper associated with this context. Requests made with this API will use context cookies.
|
||||
|
||||
|
||||
@ -2416,7 +2416,7 @@ last redirect.
|
||||
|
||||
## property: Page.request
|
||||
* langs: js
|
||||
- type: <[ApiRequestContext]>
|
||||
- type: <[APIRequestContext]>
|
||||
|
||||
API testing helper associated with this page. Requests made with this API will use page cookies.
|
||||
|
||||
|
||||
@ -216,7 +216,7 @@ This object can be used to launch or connect to Firefox, returning instances of
|
||||
|
||||
## property: Playwright.request
|
||||
* langs: js
|
||||
- type: <[ApiRequest]>
|
||||
- type: <[APIRequest]>
|
||||
|
||||
Exposes API that can be used for the Web API testing.
|
||||
|
||||
|
||||
@ -580,7 +580,7 @@ else
|
||||
## Modify responses
|
||||
* langs: js
|
||||
|
||||
To modify a response use [ApiRequestContext] to get original response and then pass the response to [`method: Route.fulfill`].
|
||||
To modify a response use [APIRequestContext] to get original response and then pass the response to [`method: Route.fulfill`].
|
||||
You can override individual fields on the reponse via options:
|
||||
|
||||
```js
|
||||
@ -605,7 +605,7 @@ await page.route('**/title.html', async route => {
|
||||
```
|
||||
|
||||
### API reference
|
||||
- [ApiRequestContext]
|
||||
- [APIRequestContext]
|
||||
- [`method: Page.route`]
|
||||
- [`method: BrowserContext.route`]
|
||||
- [`property: Playwright.request`]
|
||||
|
||||
@ -92,9 +92,9 @@ test('basic test', async ({ page }) => {
|
||||
```
|
||||
|
||||
## property: Fixtures.request
|
||||
- type: <[ApiRequestContext]>
|
||||
- type: <[APIRequestContext]>
|
||||
|
||||
Isolated [ApiRequestContext] instance for each test.
|
||||
Isolated [APIRequestContext] instance for each test.
|
||||
|
||||
```js js-flavor=js
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
@ -160,7 +160,7 @@ setup at all, just specify the `storageState.json` in Playwright Config as above
|
||||
|
||||
### Sign in via API request
|
||||
|
||||
If your web application supports signing in via API, you can use [ApiRequestContext] to simplify sign in flow. Global setup script from the example above would change like this:
|
||||
If your web application supports signing in via API, you can use [APIRequestContext] to simplify sign in flow. Global setup script from the example above would change like this:
|
||||
|
||||
```js js-flavor=js
|
||||
// global-setup.js
|
||||
|
||||
@ -3,7 +3,7 @@ id: test-send-api-requests
|
||||
title: "Send API requests"
|
||||
---
|
||||
|
||||
While running tests inside browsers you may want to make calls to the HTTP API of your application. It may be helpful if you need to prepare server state before running a test or to check some postconditions on the server after performing some actions in the browser. All of that could be achieved via [ApiRequestContext] methods.
|
||||
While running tests inside browsers you may want to make calls to the HTTP API of your application. It may be helpful if you need to prepare server state before running a test or to check some postconditions on the server after performing some actions in the browser. All of that could be achieved via [APIRequestContext] methods.
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
@ -196,8 +196,8 @@ test('last created issue should be on the server', async ({ page, request }) =>
|
||||
- [`property: Playwright.request`]
|
||||
- [`property: BrowserContext.request`]
|
||||
- [`property: Page.request`]
|
||||
- [`method: ApiRequest.newContext`]
|
||||
- [`method: ApiRequestContext.delete`]
|
||||
- [`method: ApiRequestContext.fetch`]
|
||||
- [`method: ApiRequestContext.get`]
|
||||
- [`method: ApiRequestContext.post`]
|
||||
- [`method: APIRequest.newContext`]
|
||||
- [`method: APIRequestContext.delete`]
|
||||
- [`method: APIRequestContext.fetch`]
|
||||
- [`method: APIRequestContext.get`]
|
||||
- [`method: APIRequestContext.post`]
|
||||
|
||||
@ -34,7 +34,7 @@ export { Frame } from './frame';
|
||||
export { Keyboard, Mouse, Touchscreen } from './input';
|
||||
export { JSHandle } from './jsHandle';
|
||||
export { Request, Response, Route, WebSocket } from './network';
|
||||
export { Fetch as ApiRequest, FetchRequest as ApiRequestContext, FetchResponse as ApiResponse } from './fetch';
|
||||
export { Fetch as APIRequest, FetchRequest as APIRequestContext, FetchResponse as ApiResponse } from './fetch';
|
||||
export { Page } from './page';
|
||||
export { Selectors } from './selectors';
|
||||
export { Tracing } from './tracing';
|
||||
|
||||
@ -49,7 +49,7 @@ type NewContextOptions = Omit<channels.PlaywrightNewRequestOptions, 'extraHTTPHe
|
||||
type RequestWithBodyOptions = Omit<FetchOptions, 'method'>;
|
||||
type RequestWithoutBodyOptions = Omit<RequestWithBodyOptions, 'data'|'form'|'multipart'>;
|
||||
|
||||
export class Fetch implements api.ApiRequest {
|
||||
export class Fetch implements api.APIRequest {
|
||||
private _playwright: Playwright;
|
||||
constructor(playwright: Playwright) {
|
||||
this._playwright = playwright;
|
||||
@ -69,7 +69,7 @@ export class Fetch implements api.ApiRequest {
|
||||
}
|
||||
}
|
||||
|
||||
export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, channels.FetchRequestInitializer> implements api.ApiRequestContext {
|
||||
export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, channels.FetchRequestInitializer> implements api.APIRequestContext {
|
||||
static from(channel: channels.FetchRequestChannel): FetchRequest {
|
||||
return (channel as any)._object;
|
||||
}
|
||||
|
||||
24
packages/playwright-core/types/types.d.ts
vendored
24
packages/playwright-core/types/types.d.ts
vendored
@ -2753,7 +2753,7 @@ export interface Page {
|
||||
/**
|
||||
* API testing helper associated with this page. Requests made with this API will use page cookies.
|
||||
*/
|
||||
request: ApiRequestContext;
|
||||
request: APIRequestContext;
|
||||
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by a page.
|
||||
@ -6459,7 +6459,7 @@ export interface BrowserContext {
|
||||
/**
|
||||
* API testing helper associated with this context. Requests made with this API will use context cookies.
|
||||
*/
|
||||
request: ApiRequestContext;
|
||||
request: APIRequestContext;
|
||||
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
@ -11596,15 +11596,15 @@ export interface AndroidWebView {
|
||||
/**
|
||||
* Exposes API that can be used for the Web API testing.
|
||||
*/
|
||||
export interface ApiRequest {
|
||||
export interface APIRequest {
|
||||
/**
|
||||
* Creates new instances of [ApiRequestContext].
|
||||
* Creates new instances of [APIRequestContext].
|
||||
* @param options
|
||||
*/
|
||||
newContext(options?: {
|
||||
/**
|
||||
* Methods like
|
||||
* [apiRequestContext.get(url[, options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get)
|
||||
* [aPIRequestContext.get(url[, options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get)
|
||||
* take the base URL into consideration by using the [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL)
|
||||
* constructor for building the corresponding URL. Examples:
|
||||
* - baseURL: `http://localhost:3000` and sending request to `/bar.html` results in `http://localhost:3000/bar.html`
|
||||
@ -11663,11 +11663,11 @@ export interface ApiRequest {
|
||||
* obtained via
|
||||
* [browserContext.storageState([options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-storage-state)
|
||||
* or
|
||||
* [apiRequestContext.storageState([options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-storage-state).
|
||||
* [aPIRequestContext.storageState([options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-storage-state).
|
||||
* Either a path to the file with saved storage, or the value returned by one of
|
||||
* [browserContext.storageState([options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-storage-state)
|
||||
* or
|
||||
* [apiRequestContext.storageState([options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-storage-state)
|
||||
* [aPIRequestContext.storageState([options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-storage-state)
|
||||
* methods.
|
||||
*/
|
||||
storageState?: string|{
|
||||
@ -11712,7 +11712,7 @@ export interface ApiRequest {
|
||||
* Specific user agent to use in this context.
|
||||
*/
|
||||
userAgent?: string;
|
||||
}): Promise<ApiRequestContext>;
|
||||
}): Promise<APIRequestContext>;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -11721,7 +11721,7 @@ export interface ApiRequest {
|
||||
* the cookies from the corresponding [BrowserContext]. This means that if you log in using this API, your e2e test will be
|
||||
* logged in and vice versa.
|
||||
*/
|
||||
export interface ApiRequestContext {
|
||||
export interface APIRequestContext {
|
||||
/**
|
||||
* Sends HTTP(S) [DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE) request and returns its
|
||||
* response. The method will populate request cookies from the context and update context cookies from the response. The
|
||||
@ -11758,7 +11758,7 @@ export interface ApiRequestContext {
|
||||
|
||||
/**
|
||||
* All responses returned by
|
||||
* [apiRequestContext.get(url[, options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get)
|
||||
* [aPIRequestContext.get(url[, options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get)
|
||||
* and similar methods are stored in the memory, so that you can later call
|
||||
* [apiResponse.body()](https://playwright.dev/docs/api/class-apiresponse#api-response-body). This method discards all
|
||||
* stored responses, and makes [apiResponse.body()](https://playwright.dev/docs/api/class-apiresponse#api-response-body)
|
||||
@ -12170,7 +12170,7 @@ export interface ApiRequestContext {
|
||||
|
||||
/**
|
||||
* [ApiResponse] class represents responses returned by
|
||||
* [apiRequestContext.get(url[, options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get)
|
||||
* [aPIRequestContext.get(url[, options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get)
|
||||
* and similar methods.
|
||||
*/
|
||||
export interface ApiResponse {
|
||||
@ -13710,7 +13710,7 @@ export const firefox: BrowserType;
|
||||
/**
|
||||
* Exposes API that can be used for the Web API testing.
|
||||
*/
|
||||
export const request: ApiRequest;
|
||||
export const request: APIRequest;
|
||||
|
||||
/**
|
||||
* Selectors can be used to install custom selector engines. See [Working with selectors](https://playwright.dev/docs/selectors) for more
|
||||
|
||||
6
packages/playwright-test/types/test.d.ts
vendored
6
packages/playwright-test/types/test.d.ts
vendored
@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { ApiRequestContext, Browser, BrowserContext, BrowserContextOptions, Page, LaunchOptions, ViewportSize, Geolocation, HTTPCredentials } from 'playwright-core';
|
||||
import type { APIRequestContext, Browser, BrowserContext, BrowserContextOptions, Page, LaunchOptions, ViewportSize, Geolocation, HTTPCredentials } from 'playwright-core';
|
||||
import type { Expect } from './testExpect';
|
||||
|
||||
export type { Expect } from './testExpect';
|
||||
@ -2659,7 +2659,7 @@ export interface PlaywrightTestArgs {
|
||||
*/
|
||||
page: Page;
|
||||
/**
|
||||
* Isolated [ApiRequestContext] instance for each test.
|
||||
* Isolated [APIRequestContext] instance for each test.
|
||||
*
|
||||
* ```ts
|
||||
* import { test, expect } from '@playwright/test';
|
||||
@ -2676,7 +2676,7 @@ export interface PlaywrightTestArgs {
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
request: ApiRequestContext;
|
||||
request: APIRequestContext;
|
||||
}
|
||||
|
||||
export type PlaywrightTestProject<TestArgs = {}, WorkerArgs = {}> = Project<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
|
||||
|
||||
@ -16,11 +16,11 @@
|
||||
|
||||
import fs from 'fs';
|
||||
import http from 'http';
|
||||
import type { ApiRequestContext } from 'playwright-core';
|
||||
import type { APIRequestContext } from 'playwright-core';
|
||||
import { expect, playwrightTest } from './config/browserTest';
|
||||
|
||||
export type GlobalFetchFixtures = {
|
||||
request: ApiRequestContext;
|
||||
request: APIRequestContext;
|
||||
};
|
||||
|
||||
const it = playwrightTest.extend<GlobalFetchFixtures>({
|
||||
@ -32,7 +32,7 @@ const it = playwrightTest.extend<GlobalFetchFixtures>({
|
||||
});
|
||||
|
||||
type PromiseArg<T> = T extends Promise<infer R> ? R : never;
|
||||
type StorageStateType = PromiseArg<ReturnType<ApiRequestContext['storageState']>>;
|
||||
type StorageStateType = PromiseArg<ReturnType<APIRequestContext['storageState']>>;
|
||||
|
||||
it.skip(({ mode }) => mode !== 'default');
|
||||
|
||||
|
||||
4
utils/generate_types/overrides-test.d.ts
vendored
4
utils/generate_types/overrides-test.d.ts
vendored
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { ApiRequestContext, Browser, BrowserContext, BrowserContextOptions, Page, LaunchOptions, ViewportSize, Geolocation, HTTPCredentials } from 'playwright-core';
|
||||
import type { APIRequestContext, Browser, BrowserContext, BrowserContextOptions, Page, LaunchOptions, ViewportSize, Geolocation, HTTPCredentials } from 'playwright-core';
|
||||
import type { Expect } from './testExpect';
|
||||
|
||||
export type { Expect } from './testExpect';
|
||||
@ -333,7 +333,7 @@ export interface PlaywrightWorkerArgs {
|
||||
export interface PlaywrightTestArgs {
|
||||
context: BrowserContext;
|
||||
page: Page;
|
||||
request: ApiRequestContext;
|
||||
request: APIRequestContext;
|
||||
}
|
||||
|
||||
export type PlaywrightTestProject<TestArgs = {}, WorkerArgs = {}> = Project<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user