class Playwright::APIRequestContext
“‘
assert await response.body() == ’{“status”: “ok”}‘
assert response.ok
)
},
“Authorization”: f“token {API_TOKEN}”,
# Add GitHub personal access token.
“Accept”: “application/vnd.github.v3+json”,
headers={
f“/repos/{USER}/{REPO}”,
response = api_request_context.delete(
# Delete a repository.
assert response.json() == REPO
assert response.ok
)
data={“name”: REPO},
},
“Authorization”: f“token {API_TOKEN}”,
# Add GitHub personal access token.
“Accept”: “application/vnd.github.v3+json”,
headers={
“/user/repos”,
response = api_request_context.post(
# Create a repository.
# api_request_context = p.request.new_context(base_url=“api.github.com”)
# Alternatively you can create a APIRequestContext manually without having a browser context attached:
page = context.new_page()
api_request_context = context.request
context = browser.new_context(base_url=“api.github.com”)
browser = p.chromium.launch()
# it will automatically set the cookies to the browser page and vise versa.
# requests with the internal APIRequestContext (e.g. `context.request` or `page.request`)
# This will launch a new browser, create a context and page. When making HTTP
with sync_playwright() as p:
API_TOKEN = os.getenv(“GITHUB_API_TOKEN”)
USER = “github-username”
REPO = “test-repo-1”
from playwright.sync_api import sync_playwright
import os
“`python sync
logged in and vice versa.
the cookies from the corresponding `BrowserContext`. This means that if you log in using this API, your e2e test will be
environment or the service to your e2e test. When used on `Page` or a `BrowserContext`, this API will automatically use
This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare
def delete(
response. The method will populate request cookies from the context and update context cookies from the response. The
Sends HTTP(S) [DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE) request and returns its
def delete( url, data: nil, failOnStatusCode: nil, form: nil, headers: nil, ignoreHTTPSErrors: nil, multipart: nil, params: nil, timeout: nil) wrap_impl(@impl.delete(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout))) end
def dispose
can later call [`method: APIResponse.body`]. This method discards all stored responses, and makes
All responses returned by [`method: APIRequestContext.get`] and similar methods are stored in the memory, so that you
def dispose wrap_impl(@impl.dispose) end
def event_emitter_proxy
def event_emitter_proxy _emitter_proxy ||= EventEmitterProxy.new(self, @impl)
def fetch(
Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
def fetch( urlOrRequest, data: nil, failOnStatusCode: nil, form: nil, headers: nil, ignoreHTTPSErrors: nil, method: nil, multipart: nil, params: nil, timeout: nil) wrap_impl(@impl.fetch(unwrap_impl(urlOrRequest), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), method: unwrap_impl(method), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout))) end
def get(
method will populate request cookies from the context and update context cookies from the response. The method will
Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request and returns its response. The
def get( url, failOnStatusCode: nil, headers: nil, ignoreHTTPSErrors: nil, params: nil, timeout: nil) wrap_impl(@impl.get(unwrap_impl(url), failOnStatusCode: unwrap_impl(failOnStatusCode), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), params: unwrap_impl(params), timeout: unwrap_impl(timeout))) end
def head(
The method will populate request cookies from the context and update context cookies from the response. The method will
Sends HTTP(S) [HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) request and returns its response.
def head( url, failOnStatusCode: nil, headers: nil, ignoreHTTPSErrors: nil, params: nil, timeout: nil) wrap_impl(@impl.head(unwrap_impl(url), failOnStatusCode: unwrap_impl(failOnStatusCode), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), params: unwrap_impl(params), timeout: unwrap_impl(timeout))) end
def off(event, callback)
-- inherited from EventEmitter --
def off(event, callback) event_emitter_proxy.off(event, callback) end
def on(event, callback)
-- inherited from EventEmitter --
def on(event, callback) event_emitter_proxy.on(event, callback) end
def once(event, callback)
-- inherited from EventEmitter --
def once(event, callback) event_emitter_proxy.once(event, callback) end
def patch(
The method will populate request cookies from the context and update context cookies from the response. The method will
Sends HTTP(S) [PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH) request and returns its response.
def patch( url, data: nil, failOnStatusCode: nil, form: nil, headers: nil, ignoreHTTPSErrors: nil, multipart: nil, params: nil, timeout: nil) wrap_impl(@impl.patch(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout))) end
def post(
The method will populate request cookies from the context and update context cookies from the response. The method will
Sends HTTP(S) [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request and returns its response.
def post( url, data: nil, failOnStatusCode: nil, form: nil, headers: nil, ignoreHTTPSErrors: nil, multipart: nil, params: nil, timeout: nil) wrap_impl(@impl.post(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout))) end
def put(
method will populate request cookies from the context and update context cookies from the response. The method will
Sends HTTP(S) [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) request and returns its response. The
def put( url, data: nil, failOnStatusCode: nil, form: nil, headers: nil, ignoreHTTPSErrors: nil, multipart: nil, params: nil, timeout: nil) wrap_impl(@impl.put(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout))) end
def storage_state(path: nil)
Returns storage state for this request context, contains current cookies and local storage snapshot if it was passed to
def storage_state(path: nil) raise NotImplementedError.new('storage_state is not implemented yet.') end