/
api_request_context.ex
48 lines (42 loc) · 1.4 KB
/
api_request_context.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
defmodule Playwright.APIRequestContext do
@moduledoc """
This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services,
prepare environment or the server to your e2e test.
Use this at caution as has not been tested.
"""
use Playwright.ChannelOwner
alias Playwright.APIRequestContext
@type fetch_options() :: %{
optional(:params) => any(),
optional(:method) => binary(),
optional(:headers) => any(),
optional(:postData) => any(),
optional(:jsonData) => any(),
optional(:formData) => any(),
optional(:multipartData) => any(),
optional(:timeout) => non_neg_integer(),
optional(:failOnStatusCode) => boolean(),
optional(:ignoreHTTPSErrors) => boolean()
}
@spec post(t(), binary(), fetch_options()) :: Playwright.APIResponse.t()
def post(%APIRequestContext{session: session} = context, url, options \\ %{}) do
Channel.post(
session,
{:guid, context.guid},
:fetch,
Map.merge(
%{
url: url,
method: "POST"
},
options
)
)
end
@spec body(t(), Playwright.APIResponse.t()) :: any()
def body(%APIRequestContext{session: session} = context, response) do
Channel.post(session, {:guid, context.guid}, :fetch_response_body, %{
fetchUid: response.fetchUid
})
end
end