mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(fetch): add helper methods for put, patch, head, delete (#9374)
This commit is contained in:
parent
8bfd63e4ba
commit
51490a82e1
@ -6,6 +6,20 @@ 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
|
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.
|
will be logged in and vice versa.
|
||||||
|
|
||||||
|
## 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-%%
|
||||||
|
|
||||||
## async method: ApiRequestContext.dispose
|
## async method: ApiRequestContext.dispose
|
||||||
|
|
||||||
All responses received through [`method: ApiRequestContext.fetch`], [`method: ApiRequestContext.get`], [`method: ApiRequestContext.post`]
|
All responses received through [`method: ApiRequestContext.fetch`], [`method: ApiRequestContext.get`], [`method: ApiRequestContext.post`]
|
||||||
@ -15,121 +29,109 @@ discards all stored responses, and makes [`method: ApiResponse.body`] throw "Res
|
|||||||
## async method: ApiRequestContext.fetch
|
## async method: ApiRequestContext.fetch
|
||||||
- returns: <[ApiResponse]>
|
- returns: <[ApiResponse]>
|
||||||
|
|
||||||
Sends HTTP(S) fetch and returns its response. The method will populate fetch cookies from the context and update
|
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.
|
context cookies from the response. The method will automatically follow redirects.
|
||||||
|
|
||||||
### param: ApiRequestContext.fetch.urlOrRequest
|
### param: ApiRequestContext.fetch.urlOrRequest
|
||||||
- `urlOrRequest` <[string]|[Request]>
|
- `urlOrRequest` <[string]|[Request]>
|
||||||
|
|
||||||
Target URL or Request to get all fetch parameters from.
|
Target URL or Request to get all parameters from.
|
||||||
|
|
||||||
### option: ApiRequestContext.fetch.params
|
### option: ApiRequestContext.fetch.params = %%-fetch-option-params-%%
|
||||||
- `params` <[Object]<[string], [string]>>
|
|
||||||
|
|
||||||
Query parameters to be send with the URL.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.fetch.method
|
### option: ApiRequestContext.fetch.method
|
||||||
- `method` <[string]>
|
- `method` <[string]>
|
||||||
|
|
||||||
If set changes the fetch method (e.g. PUT or POST). If not specified, GET method is used.
|
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
|
|
||||||
- `headers` <[Object]<[string], [string]>>
|
|
||||||
|
|
||||||
Allows to set HTTP headers.
|
|
||||||
|
|
||||||
|
### option: ApiRequestContext.fetch.headers = %%-fetch-option-headers-%%
|
||||||
### option: ApiRequestContext.fetch.data = %%-fetch-option-data-%%
|
### option: ApiRequestContext.fetch.data = %%-fetch-option-data-%%
|
||||||
### option: ApiRequestContext.fetch.form = %%-fetch-option-form-%%
|
### option: ApiRequestContext.fetch.form = %%-fetch-option-form-%%
|
||||||
### option: ApiRequestContext.fetch.multipart = %%-fetch-option-multipart-%%
|
### option: ApiRequestContext.fetch.multipart = %%-fetch-option-multipart-%%
|
||||||
|
### option: ApiRequestContext.fetch.timeout = %%-fetch-option-timeout-%%
|
||||||
### option: ApiRequestContext.fetch.timeout
|
### option: ApiRequestContext.fetch.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||||
- `timeout` <[float]>
|
|
||||||
|
|
||||||
Request timeout in milliseconds.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.fetch.failOnStatusCode
|
|
||||||
- `failOnStatusCode` <[boolean]>
|
|
||||||
|
|
||||||
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
|
|
||||||
for all status codes.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.fetch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
### option: ApiRequestContext.fetch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||||
|
|
||||||
|
|
||||||
## async method: ApiRequestContext.get
|
## async method: ApiRequestContext.get
|
||||||
- returns: <[ApiResponse]>
|
- returns: <[ApiResponse]>
|
||||||
|
|
||||||
Sends HTTP(S) GET request and returns its response. The method will populate fetch cookies from the context and update
|
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.
|
context cookies from the response. The method will automatically follow redirects.
|
||||||
|
|
||||||
### param: ApiRequestContext.get.url
|
### param: ApiRequestContext.get.url = %%-fetch-param-url-%%
|
||||||
- `url` <[string]>
|
### option: ApiRequestContext.get.params = %%-fetch-option-params-%%
|
||||||
|
### option: ApiRequestContext.get.headers = %%-fetch-option-headers-%%
|
||||||
Target URL.
|
### option: ApiRequestContext.get.timeout = %%-fetch-option-timeout-%%
|
||||||
|
### option: ApiRequestContext.get.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||||
### option: ApiRequestContext.get.params
|
|
||||||
- `params` <[Object]<[string], [string]>>
|
|
||||||
|
|
||||||
Query parameters to be send with the URL.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.get.headers
|
|
||||||
- `headers` <[Object]<[string], [string]>>
|
|
||||||
|
|
||||||
Allows to set HTTP headers.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.get.timeout
|
|
||||||
- `timeout` <[float]>
|
|
||||||
|
|
||||||
Request timeout in milliseconds.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.get.failOnStatusCode
|
|
||||||
- `failOnStatusCode` <[boolean]>
|
|
||||||
|
|
||||||
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
|
|
||||||
for all status codes.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.get.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
### option: ApiRequestContext.get.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||||
|
|
||||||
|
## 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-%%
|
||||||
|
|
||||||
|
## 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-%%
|
||||||
|
|
||||||
## async method: ApiRequestContext.post
|
## async method: ApiRequestContext.post
|
||||||
- returns: <[ApiResponse]>
|
- returns: <[ApiResponse]>
|
||||||
|
|
||||||
Sends HTTP(S) fetch and returns its response. The method will populate fetch cookies from the context and update
|
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.
|
context cookies from the response. The method will automatically follow redirects.
|
||||||
|
|
||||||
### param: ApiRequestContext.post.url
|
### param: ApiRequestContext.post.url = %%-fetch-param-url-%%
|
||||||
- `url` <[string]>
|
### option: ApiRequestContext.post.params = %%-fetch-option-params-%%
|
||||||
|
### option: ApiRequestContext.post.headers = %%-fetch-option-headers-%%
|
||||||
Target URL.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.post.params
|
|
||||||
- `params` <[Object]<[string], [string]>>
|
|
||||||
|
|
||||||
Query parameters to be send with the URL.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.post.headers
|
|
||||||
- `headers` <[Object]<[string], [string]>>
|
|
||||||
|
|
||||||
Allows to set HTTP headers.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.post.data = %%-fetch-option-data-%%
|
### option: ApiRequestContext.post.data = %%-fetch-option-data-%%
|
||||||
|
|
||||||
### option: ApiRequestContext.post.form = %%-fetch-option-form-%%
|
### option: ApiRequestContext.post.form = %%-fetch-option-form-%%
|
||||||
|
|
||||||
### option: ApiRequestContext.post.multipart = %%-fetch-option-multipart-%%
|
### option: ApiRequestContext.post.multipart = %%-fetch-option-multipart-%%
|
||||||
|
### option: ApiRequestContext.post.timeout = %%-fetch-option-timeout-%%
|
||||||
### option: ApiRequestContext.post.timeout
|
### option: ApiRequestContext.post.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||||
- `timeout` <[float]>
|
|
||||||
|
|
||||||
Request timeout in milliseconds.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.post.failOnStatusCode
|
|
||||||
- `failOnStatusCode` <[boolean]>
|
|
||||||
|
|
||||||
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
|
|
||||||
for all status codes.
|
|
||||||
|
|
||||||
### option: ApiRequestContext.post.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
### option: ApiRequestContext.post.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||||
|
|
||||||
|
## 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-%%
|
||||||
|
|
||||||
## async method: ApiRequestContext.storageState
|
## async method: ApiRequestContext.storageState
|
||||||
- returns: <[Object]>
|
- returns: <[Object]>
|
||||||
- `cookies` <[Array]<[Object]>>
|
- `cookies` <[Array]<[Object]>>
|
||||||
|
|||||||
@ -297,6 +297,32 @@ Emulates consistent viewport for each page. Defaults to an 1280x720 viewport. Us
|
|||||||
Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the
|
Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the
|
||||||
[`option: viewport`] is set.
|
[`option: viewport`] is set.
|
||||||
|
|
||||||
|
## fetch-param-url
|
||||||
|
- `url` <[string]>
|
||||||
|
|
||||||
|
Target URL.
|
||||||
|
|
||||||
|
## fetch-option-params
|
||||||
|
- `params` <[Object]<[string], [string]>>
|
||||||
|
|
||||||
|
Query parameters to be send with the URL.
|
||||||
|
|
||||||
|
## fetch-option-headers
|
||||||
|
- `headers` <[Object]<[string], [string]>>
|
||||||
|
|
||||||
|
Allows to set HTTP headers.
|
||||||
|
|
||||||
|
## fetch-option-timeout
|
||||||
|
- `timeout` <[float]>
|
||||||
|
|
||||||
|
Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
|
||||||
|
|
||||||
|
## fetch-option-failonstatuscode
|
||||||
|
- `failOnStatusCode` <[boolean]>
|
||||||
|
|
||||||
|
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
|
||||||
|
for all status codes.
|
||||||
|
|
||||||
## fetch-option-form
|
## fetch-option-form
|
||||||
- `form` <[Object]<[string], [string]|[float]|[boolean]>>
|
- `form` <[Object]<[string], [string]|[float]|[boolean]>>
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,9 @@ type NewContextOptions = Omit<channels.PlaywrightNewRequestOptions, 'extraHTTPHe
|
|||||||
storageState?: string | StorageState,
|
storageState?: string | StorageState,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;
|
private _playwright: Playwright;
|
||||||
constructor(playwright: Playwright) {
|
constructor(playwright: Playwright) {
|
||||||
@ -81,28 +84,48 @@ export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, cha
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(
|
async delete(url: string, options?: RequestWithoutBodyOptions): Promise<FetchResponse> {
|
||||||
url: string,
|
return this.fetch(url, {
|
||||||
options?: {
|
...options,
|
||||||
params?: { [key: string]: string; };
|
method: 'DELETE',
|
||||||
headers?: { [key: string]: string; };
|
});
|
||||||
timeout?: number;
|
}
|
||||||
failOnStatusCode?: boolean;
|
|
||||||
ignoreHTTPSErrors?: boolean,
|
async head(url: string, options?: RequestWithoutBodyOptions): Promise<FetchResponse> {
|
||||||
}): Promise<FetchResponse> {
|
return this.fetch(url, {
|
||||||
|
...options,
|
||||||
|
method: 'HEAD',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(url: string, options?: RequestWithoutBodyOptions): Promise<FetchResponse> {
|
||||||
return this.fetch(url, {
|
return this.fetch(url, {
|
||||||
...options,
|
...options,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async post(url: string, options?: Omit<FetchOptions, 'method'>): Promise<FetchResponse> {
|
async patch(url: string, options?: RequestWithBodyOptions): Promise<FetchResponse> {
|
||||||
|
return this.fetch(url, {
|
||||||
|
...options,
|
||||||
|
method: 'PATCH',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async post(url: string, options?: RequestWithBodyOptions): Promise<FetchResponse> {
|
||||||
return this.fetch(url, {
|
return this.fetch(url, {
|
||||||
...options,
|
...options,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async put(url: string, options?: RequestWithBodyOptions): Promise<FetchResponse> {
|
||||||
|
return this.fetch(url, {
|
||||||
|
...options,
|
||||||
|
method: 'PUT',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async fetch(urlOrRequest: string | api.Request, options: FetchOptions = {}): Promise<FetchResponse> {
|
async fetch(urlOrRequest: string | api.Request, options: FetchOptions = {}): Promise<FetchResponse> {
|
||||||
return this._wrapApiCall(async (channel: channels.FetchRequestChannel) => {
|
return this._wrapApiCall(async (channel: channels.FetchRequestChannel) => {
|
||||||
const request: network.Request | undefined = (urlOrRequest instanceof network.Request) ? urlOrRequest as network.Request : undefined;
|
const request: network.Request | undefined = (urlOrRequest instanceof network.Request) ? urlOrRequest as network.Request : undefined;
|
||||||
|
|||||||
@ -134,7 +134,7 @@ export abstract class FetchRequest extends SdkObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let postData;
|
let postData;
|
||||||
if (['POST', 'PUSH', 'PATCH'].includes(method))
|
if (['POST', 'PUT', 'PATCH'].includes(method))
|
||||||
postData = serializePostData(params, headers);
|
postData = serializePostData(params, headers);
|
||||||
else if (params.postData || params.jsonData || params.formData || params.multipartData)
|
else if (params.postData || params.jsonData || params.formData || params.multipartData)
|
||||||
throw new Error(`Method ${method} does not accept post data`);
|
throw new Error(`Method ${method} does not accept post data`);
|
||||||
|
|||||||
@ -130,7 +130,7 @@ it('should add session cookies to request', async ({ context, server }) => {
|
|||||||
expect(req.headers.cookie).toEqual('username=John Doe');
|
expect(req.headers.cookie).toEqual('username=John Doe');
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const method of ['get', 'post', 'fetch']) {
|
for (const method of ['fetch', 'delete', 'get', 'head', 'patch', 'post', 'put']) {
|
||||||
it(`${method} should support queryParams`, async ({ context, server }) => {
|
it(`${method} should support queryParams`, async ({ context, server }) => {
|
||||||
let request;
|
let request;
|
||||||
const url = new URL(server.EMPTY_PAGE);
|
const url = new URL(server.EMPTY_PAGE);
|
||||||
|
|||||||
@ -38,7 +38,7 @@ it.afterAll(() => {
|
|||||||
http.globalAgent = prevAgent;
|
http.globalAgent = prevAgent;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const method of ['get', 'post', 'fetch']) {
|
for (const method of ['fetch', 'delete', 'get', 'head', 'patch', 'post', 'put']) {
|
||||||
it(`${method} should work`, async ({ playwright, server }) => {
|
it(`${method} should work`, async ({ playwright, server }) => {
|
||||||
const request = await playwright.request.newContext();
|
const request = await playwright.request.newContext();
|
||||||
const response = await request[method](server.PREFIX + '/simple.json');
|
const response = await request[method](server.PREFIX + '/simple.json');
|
||||||
@ -49,7 +49,7 @@ for (const method of ['get', 'post', 'fetch']) {
|
|||||||
expect(response.url()).toBe(server.PREFIX + '/simple.json');
|
expect(response.url()).toBe(server.PREFIX + '/simple.json');
|
||||||
expect(response.headers()['content-type']).toBe('application/json; charset=utf-8');
|
expect(response.headers()['content-type']).toBe('application/json; charset=utf-8');
|
||||||
expect(response.headersArray()).toContainEqual({ name: 'Content-Type', value: 'application/json; charset=utf-8' });
|
expect(response.headersArray()).toContainEqual({ name: 'Content-Type', value: 'application/json; charset=utf-8' });
|
||||||
expect(await response.text()).toBe('{"foo": "bar"}\n');
|
expect(await response.text()).toBe(method === 'head' ? '' : '{"foo": "bar"}\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should dispose global ${method} request`, async function({ playwright, context, server }) {
|
it(`should dispose global ${method} request`, async function({ playwright, context, server }) {
|
||||||
|
|||||||
235
types/types.d.ts
vendored
235
types/types.d.ts
vendored
@ -11721,6 +11721,40 @@ export interface ApiRequest {
|
|||||||
* logged in and vice versa.
|
* 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
|
||||||
|
* method will automatically follow redirects.
|
||||||
|
* @param url Target URL.
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
delete(url: string, options?: {
|
||||||
|
/**
|
||||||
|
* Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
|
||||||
|
*/
|
||||||
|
failOnStatusCode?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to set HTTP headers.
|
||||||
|
*/
|
||||||
|
headers?: { [key: string]: string; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to ignore HTTPS errors when sending network requests. Defaults to `false`.
|
||||||
|
*/
|
||||||
|
ignoreHTTPSErrors?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query parameters to be send with the URL.
|
||||||
|
*/
|
||||||
|
params?: { [key: string]: string; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
|
||||||
|
*/
|
||||||
|
timeout?: number;
|
||||||
|
}): Promise<ApiResponse>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All responses received through
|
* All responses received through
|
||||||
* [apiRequestContext.fetch(urlOrRequest[, options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-fetch),
|
* [apiRequestContext.fetch(urlOrRequest[, options])](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-fetch),
|
||||||
@ -11734,9 +11768,9 @@ export interface ApiRequestContext {
|
|||||||
dispose(): Promise<void>;
|
dispose(): Promise<void>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends HTTP(S) fetch and returns its response. The method will populate fetch cookies from the context and update context
|
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
||||||
* cookies from the response. The method will automatically follow redirects.
|
* context cookies from the response. The method will automatically follow redirects.
|
||||||
* @param urlOrRequest Target URL or Request to get all fetch parameters from.
|
* @param urlOrRequest Target URL or Request to get all parameters from.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
fetch(urlOrRequest: string|Request, options?: {
|
fetch(urlOrRequest: string|Request, options?: {
|
||||||
@ -11770,7 +11804,8 @@ export interface ApiRequestContext {
|
|||||||
ignoreHTTPSErrors?: boolean;
|
ignoreHTTPSErrors?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set changes the fetch method (e.g. PUT or POST). If not specified, GET method is used.
|
* 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.
|
||||||
*/
|
*/
|
||||||
method?: string;
|
method?: string;
|
||||||
|
|
||||||
@ -11803,14 +11838,15 @@ export interface ApiRequestContext {
|
|||||||
params?: { [key: string]: string; };
|
params?: { [key: string]: string; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request timeout in milliseconds.
|
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
|
||||||
*/
|
*/
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
}): Promise<ApiResponse>;
|
}): Promise<ApiResponse>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends HTTP(S) GET request and returns its response. The method will populate fetch cookies from the context and update
|
* Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request and returns its response. The
|
||||||
* context cookies from the response. The method will automatically follow redirects.
|
* method will populate request cookies from the context and update context cookies from the response. The method will
|
||||||
|
* automatically follow redirects.
|
||||||
* @param url Target URL.
|
* @param url Target URL.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
@ -11836,14 +11872,120 @@ export interface ApiRequestContext {
|
|||||||
params?: { [key: string]: string; };
|
params?: { [key: string]: string; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request timeout in milliseconds.
|
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
|
||||||
*/
|
*/
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
}): Promise<ApiResponse>;
|
}): Promise<ApiResponse>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends HTTP(S) fetch and returns its response. The method will populate fetch cookies from the context and update context
|
* Sends HTTP(S) [HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) request and returns its response.
|
||||||
* cookies from the response. The method will automatically follow redirects.
|
* The method will populate request cookies from the context and update context cookies from the response. The method will
|
||||||
|
* automatically follow redirects.
|
||||||
|
* @param url Target URL.
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
head(url: string, options?: {
|
||||||
|
/**
|
||||||
|
* Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
|
||||||
|
*/
|
||||||
|
failOnStatusCode?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to set HTTP headers.
|
||||||
|
*/
|
||||||
|
headers?: { [key: string]: string; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to ignore HTTPS errors when sending network requests. Defaults to `false`.
|
||||||
|
*/
|
||||||
|
ignoreHTTPSErrors?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query parameters to be send with the URL.
|
||||||
|
*/
|
||||||
|
params?: { [key: string]: string; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
|
||||||
|
*/
|
||||||
|
timeout?: number;
|
||||||
|
}): Promise<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 url Target URL.
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
patch(url: string, options?: {
|
||||||
|
/**
|
||||||
|
* Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
|
||||||
|
* `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` header will
|
||||||
|
* be set to `application/octet-stream` if not explicitly set.
|
||||||
|
*/
|
||||||
|
data?: string|Buffer|Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
|
||||||
|
*/
|
||||||
|
failOnStatusCode?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent as
|
||||||
|
* this request body. If this parameter is specified `content-type` header will be set to
|
||||||
|
* `application/x-www-form-urlencoded` unless explicitly provided.
|
||||||
|
*/
|
||||||
|
form?: { [key: string]: string|number|boolean; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to set HTTP headers.
|
||||||
|
*/
|
||||||
|
headers?: { [key: string]: string; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to ignore HTTPS errors when sending network requests. Defaults to `false`.
|
||||||
|
*/
|
||||||
|
ignoreHTTPSErrors?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this request
|
||||||
|
* body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless explicitly
|
||||||
|
* provided. File values can be passed either as [`fs.ReadStream`](https://nodejs.org/api/fs.html#fs_class_fs_readstream)
|
||||||
|
* or as file-like object containing file name, mime-type and its content.
|
||||||
|
*/
|
||||||
|
multipart?: { [key: string]: string|number|boolean|ReadStream|{
|
||||||
|
/**
|
||||||
|
* File name
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File type
|
||||||
|
*/
|
||||||
|
mimeType: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File content
|
||||||
|
*/
|
||||||
|
buffer: Buffer;
|
||||||
|
}; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query parameters to be send with the URL.
|
||||||
|
*/
|
||||||
|
params?: { [key: string]: string; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
|
||||||
|
*/
|
||||||
|
timeout?: number;
|
||||||
|
}): Promise<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 url Target URL.
|
* @param url Target URL.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
@ -11906,7 +12048,78 @@ export interface ApiRequestContext {
|
|||||||
params?: { [key: string]: string; };
|
params?: { [key: string]: string; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request timeout in milliseconds.
|
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
|
||||||
|
*/
|
||||||
|
timeout?: number;
|
||||||
|
}): Promise<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 url Target URL.
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
put(url: string, options?: {
|
||||||
|
/**
|
||||||
|
* Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
|
||||||
|
* `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` header will
|
||||||
|
* be set to `application/octet-stream` if not explicitly set.
|
||||||
|
*/
|
||||||
|
data?: string|Buffer|Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
|
||||||
|
*/
|
||||||
|
failOnStatusCode?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent as
|
||||||
|
* this request body. If this parameter is specified `content-type` header will be set to
|
||||||
|
* `application/x-www-form-urlencoded` unless explicitly provided.
|
||||||
|
*/
|
||||||
|
form?: { [key: string]: string|number|boolean; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to set HTTP headers.
|
||||||
|
*/
|
||||||
|
headers?: { [key: string]: string; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to ignore HTTPS errors when sending network requests. Defaults to `false`.
|
||||||
|
*/
|
||||||
|
ignoreHTTPSErrors?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this request
|
||||||
|
* body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless explicitly
|
||||||
|
* provided. File values can be passed either as [`fs.ReadStream`](https://nodejs.org/api/fs.html#fs_class_fs_readstream)
|
||||||
|
* or as file-like object containing file name, mime-type and its content.
|
||||||
|
*/
|
||||||
|
multipart?: { [key: string]: string|number|boolean|ReadStream|{
|
||||||
|
/**
|
||||||
|
* File name
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File type
|
||||||
|
*/
|
||||||
|
mimeType: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File content
|
||||||
|
*/
|
||||||
|
buffer: Buffer;
|
||||||
|
}; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query parameters to be send with the URL.
|
||||||
|
*/
|
||||||
|
params?: { [key: string]: string; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
|
||||||
*/
|
*/
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
}): Promise<ApiResponse>;
|
}): Promise<ApiResponse>;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user