playwright-browserstack 1.62.0__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- playwright/__init__.py +19 -0
- playwright/__main__.py +33 -0
- playwright/_impl/__init__.py +0 -0
- playwright/_impl/__pyinstaller/__init__.py +20 -0
- playwright/_impl/__pyinstaller/hook-playwright.async_api.py +17 -0
- playwright/_impl/__pyinstaller/hook-playwright.sync_api.py +17 -0
- playwright/_impl/_android.py +704 -0
- playwright/_impl/_api_structures.py +365 -0
- playwright/_impl/_artifact.py +87 -0
- playwright/_impl/_assertions.py +1124 -0
- playwright/_impl/_async_base.py +105 -0
- playwright/_impl/_browser.py +293 -0
- playwright/_impl/_browser_context.py +754 -0
- playwright/_impl/_browser_type.py +368 -0
- playwright/_impl/_cdp_session.py +46 -0
- playwright/_impl/_clock.py +104 -0
- playwright/_impl/_connection.py +764 -0
- playwright/_impl/_console_message.py +98 -0
- playwright/_impl/_credentials.py +57 -0
- playwright/_impl/_debugger.py +54 -0
- playwright/_impl/_dialog.py +63 -0
- playwright/_impl/_disposable.py +96 -0
- playwright/_impl/_download.py +64 -0
- playwright/_impl/_driver.py +41 -0
- playwright/_impl/_element_handle.py +480 -0
- playwright/_impl/_errors.py +64 -0
- playwright/_impl/_event_context_manager.py +33 -0
- playwright/_impl/_fetch.py +626 -0
- playwright/_impl/_file_chooser.py +57 -0
- playwright/_impl/_form_data.py +34 -0
- playwright/_impl/_frame.py +985 -0
- playwright/_impl/_glob.py +65 -0
- playwright/_impl/_greenlets.py +49 -0
- playwright/_impl/_har_router.py +122 -0
- playwright/_impl/_helper.py +601 -0
- playwright/_impl/_impl_to_api_mapping.py +158 -0
- playwright/_impl/_input.py +111 -0
- playwright/_impl/_js_handle.py +336 -0
- playwright/_impl/_json_pipe.py +97 -0
- playwright/_impl/_local_utils.py +95 -0
- playwright/_impl/_locator.py +1024 -0
- playwright/_impl/_map.py +31 -0
- playwright/_impl/_network.py +1017 -0
- playwright/_impl/_object_factory.py +116 -0
- playwright/_impl/_page.py +1637 -0
- playwright/_impl/_path_utils.py +27 -0
- playwright/_impl/_playwright.py +68 -0
- playwright/_impl/_screencast.py +177 -0
- playwright/_impl/_selectors.py +67 -0
- playwright/_impl/_set_input_files_helpers.py +158 -0
- playwright/_impl/_str_utils.py +76 -0
- playwright/_impl/_stream.py +46 -0
- playwright/_impl/_sync_base.py +151 -0
- playwright/_impl/_tracing.py +281 -0
- playwright/_impl/_transport.py +184 -0
- playwright/_impl/_video.py +56 -0
- playwright/_impl/_waiter.py +197 -0
- playwright/_impl/_web_error.py +48 -0
- playwright/_impl/_web_storage.py +58 -0
- playwright/_impl/_writable_stream.py +42 -0
- playwright/_repo_version.py +24 -0
- playwright/async_api/__init__.py +275 -0
- playwright/async_api/_android_generated.py +462 -0
- playwright/async_api/_context_manager.py +57 -0
- playwright/async_api/_generated.py +23875 -0
- playwright/driver/LICENSE +2946 -0
- playwright/driver/README.md +1 -0
- playwright/driver/node.exe +0 -0
- playwright/driver/package/LICENSE +202 -0
- playwright/driver/package/NOTICE +5 -0
- playwright/driver/package/README.md +3 -0
- playwright/driver/package/ThirdPartyNotices.txt +13 -0
- playwright/driver/package/bin/install_media_pack.ps1 +5 -0
- playwright/driver/package/bin/install_webkit_wsl.ps1 +33 -0
- playwright/driver/package/bin/reinstall_chrome_beta_linux.sh +42 -0
- playwright/driver/package/bin/reinstall_chrome_beta_mac.sh +13 -0
- playwright/driver/package/bin/reinstall_chrome_beta_win.ps1 +24 -0
- playwright/driver/package/bin/reinstall_chrome_stable_linux.sh +42 -0
- playwright/driver/package/bin/reinstall_chrome_stable_mac.sh +12 -0
- playwright/driver/package/bin/reinstall_chrome_stable_win.ps1 +24 -0
- playwright/driver/package/bin/reinstall_msedge_beta_linux.sh +48 -0
- playwright/driver/package/bin/reinstall_msedge_beta_mac.sh +11 -0
- playwright/driver/package/bin/reinstall_msedge_beta_win.ps1 +23 -0
- playwright/driver/package/bin/reinstall_msedge_dev_linux.sh +48 -0
- playwright/driver/package/bin/reinstall_msedge_dev_mac.sh +11 -0
- playwright/driver/package/bin/reinstall_msedge_dev_win.ps1 +23 -0
- playwright/driver/package/bin/reinstall_msedge_stable_linux.sh +48 -0
- playwright/driver/package/bin/reinstall_msedge_stable_mac.sh +11 -0
- playwright/driver/package/bin/reinstall_msedge_stable_win.ps1 +24 -0
- playwright/driver/package/browsers.json +75 -0
- playwright/driver/package/cli.js +21 -0
- playwright/driver/package/index.d.ts +17 -0
- playwright/driver/package/index.js +17 -0
- playwright/driver/package/index.mjs +28 -0
- playwright/driver/package/lib/bootstrap.js +88 -0
- playwright/driver/package/lib/coreBundle.js +74830 -0
- playwright/driver/package/lib/entry/cliDaemon.js +5 -0
- playwright/driver/package/lib/entry/dashboardApp.js +3 -0
- playwright/driver/package/lib/entry/mcp.js +10 -0
- playwright/driver/package/lib/entry/oopBrowserDownload.js +3 -0
- playwright/driver/package/lib/package.js +50 -0
- playwright/driver/package/lib/server/chromium/appIcon.png +0 -0
- playwright/driver/package/lib/server/electron/loader.js +118 -0
- playwright/driver/package/lib/serverRegistry.js +7347 -0
- playwright/driver/package/lib/serverRegistry.js.LICENSE +354 -0
- playwright/driver/package/lib/tools/cli-client/channelSessions.js +141 -0
- playwright/driver/package/lib/tools/cli-client/cli.js +6 -0
- playwright/driver/package/lib/tools/cli-client/help.json +708 -0
- playwright/driver/package/lib/tools/cli-client/minimist.js +128 -0
- playwright/driver/package/lib/tools/cli-client/output.js +343 -0
- playwright/driver/package/lib/tools/cli-client/program.js +404 -0
- playwright/driver/package/lib/tools/cli-client/registry.js +176 -0
- playwright/driver/package/lib/tools/cli-client/session.js +258 -0
- playwright/driver/package/lib/tools/dashboard/appIcon.png +0 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/SKILL.md +420 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/element-attributes.md +23 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/playwright-tests.md +39 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/request-mocking.md +87 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/running-code.md +241 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/session-management.md +225 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/storage-state.md +275 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/test-generation.md +433 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/tracing.md +139 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/video-recording.md +143 -0
- playwright/driver/package/lib/tools/skills/playwright-component-testing/SKILL.md +143 -0
- playwright/driver/package/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +144 -0
- playwright/driver/package/lib/tools/skills/playwright-component-testing/references/migration.md +85 -0
- playwright/driver/package/lib/tools/skills/playwright-component-testing/references/react.md +67 -0
- playwright/driver/package/lib/tools/skills/playwright-component-testing/references/vue.md +75 -0
- playwright/driver/package/lib/tools/skills/playwright-trace/SKILL.md +171 -0
- playwright/driver/package/lib/tools/utils/extension.js +101 -0
- playwright/driver/package/lib/tools/utils/socketConnection.js +108 -0
- playwright/driver/package/lib/utilsBundle.js +90764 -0
- playwright/driver/package/lib/utilsBundle.js.LICENSE +2179 -0
- playwright/driver/package/lib/vite/dashboard/assets/codicon-DCmgc-ay.ttf +0 -0
- playwright/driver/package/lib/vite/dashboard/assets/firefox-1bWoP6pv.svg +1 -0
- playwright/driver/package/lib/vite/dashboard/assets/firefox-beta-k3eOH_eK.svg +1 -0
- playwright/driver/package/lib/vite/dashboard/assets/firefox-nightly-Cp5nfeDT.svg +1 -0
- playwright/driver/package/lib/vite/dashboard/assets/index-CyWAfh-p.js +11 -0
- playwright/driver/package/lib/vite/dashboard/assets/index-DhC616m4.css +1 -0
- playwright/driver/package/lib/vite/dashboard/assets/safari-na3_-uQk.svg +1 -0
- playwright/driver/package/lib/vite/dashboard/index.html +29 -0
- playwright/driver/package/lib/vite/dashboard/playwright-logo.svg +24 -0
- playwright/driver/package/lib/vite/htmlReport/index.html +16 -0
- playwright/driver/package/lib/vite/htmlReport/report.css +2 -0
- playwright/driver/package/lib/vite/htmlReport/report.js +32 -0
- playwright/driver/package/lib/vite/recorder/assets/codeMirrorModule--QdMvsKi.css +1 -0
- playwright/driver/package/lib/vite/recorder/assets/codeMirrorModule-CwYYHbcZ.js +32 -0
- playwright/driver/package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- playwright/driver/package/lib/vite/recorder/assets/index-DYjdXIbE.js +129 -0
- playwright/driver/package/lib/vite/recorder/assets/index-l_lX622x.css +1 -0
- playwright/driver/package/lib/vite/recorder/index.html +29 -0
- playwright/driver/package/lib/vite/recorder/playwright-logo.svg +9 -0
- playwright/driver/package/lib/vite/traceViewer/assets/codeMirrorModule-By56iMx7.js +32 -0
- playwright/driver/package/lib/vite/traceViewer/assets/defaultSettingsView-B34OrIms.js +181 -0
- playwright/driver/package/lib/vite/traceViewer/assets/urlMatch-L3liM589.js +1 -0
- playwright/driver/package/lib/vite/traceViewer/assets/xtermModule-COQkjINf.js +7 -0
- playwright/driver/package/lib/vite/traceViewer/codeMirrorModule.-QdMvsKi.css +1 -0
- playwright/driver/package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- playwright/driver/package/lib/vite/traceViewer/defaultSettingsView.BLFoOugd.css +1 -0
- playwright/driver/package/lib/vite/traceViewer/index.B_TqY17P.css +1 -0
- playwright/driver/package/lib/vite/traceViewer/index.Dl36UVQT.js +1 -0
- playwright/driver/package/lib/vite/traceViewer/index.html +44 -0
- playwright/driver/package/lib/vite/traceViewer/manifest.webmanifest +16 -0
- playwright/driver/package/lib/vite/traceViewer/playwright-logo.svg +9 -0
- playwright/driver/package/lib/vite/traceViewer/snapshot.B_Jk1wbt.js +1 -0
- playwright/driver/package/lib/vite/traceViewer/snapshot.html +10 -0
- playwright/driver/package/lib/vite/traceViewer/sw.bundle.js +4 -0
- playwright/driver/package/lib/vite/traceViewer/uiMode.C7UW1sC9.css +1 -0
- playwright/driver/package/lib/vite/traceViewer/uiMode.D962mr9b.js +5 -0
- playwright/driver/package/lib/vite/traceViewer/uiMode.html +18 -0
- playwright/driver/package/lib/vite/traceViewer/xtermModule.kHJ-D0s7.css +1 -0
- playwright/driver/package/lib/webp_codec.LICENSE +173 -0
- playwright/driver/package/lib/webp_codec.wasm +0 -0
- playwright/driver/package/lib/xdg-open +1267 -0
- playwright/driver/package/package.json +34 -0
- playwright/driver/package/types/protocol.d.ts +24842 -0
- playwright/driver/package/types/structs.d.ts +47 -0
- playwright/driver/package/types/types.d.ts +26188 -0
- playwright/py.typed +0 -0
- playwright/sync_api/__init__.py +275 -0
- playwright/sync_api/_android_generated.py +494 -0
- playwright/sync_api/_context_manager.py +98 -0
- playwright/sync_api/_generated.py +24045 -0
- playwright_browserstack-1.62.0.dist-info/METADATA +82 -0
- playwright_browserstack-1.62.0.dist-info/RECORD +192 -0
- playwright_browserstack-1.62.0.dist-info/WHEEL +5 -0
- playwright_browserstack-1.62.0.dist-info/entry_points.txt +5 -0
- playwright_browserstack-1.62.0.dist-info/licenses/LICENSE +202 -0
- playwright_browserstack-1.62.0.dist-info/licenses/LICENSE.txt +51 -0
- playwright_browserstack-1.62.0.dist-info/licenses/NOTICE +18 -0
- playwright_browserstack-1.62.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import base64
|
|
16
|
+
import json
|
|
17
|
+
import mimetypes
|
|
18
|
+
import pathlib
|
|
19
|
+
import typing
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Any, Dict, List, Optional, Union, cast
|
|
22
|
+
|
|
23
|
+
import playwright._impl._network as network
|
|
24
|
+
from playwright._impl._api_structures import (
|
|
25
|
+
ClientCertificate,
|
|
26
|
+
FilePayload,
|
|
27
|
+
FormField,
|
|
28
|
+
Headers,
|
|
29
|
+
HttpCredentials,
|
|
30
|
+
ProxySettings,
|
|
31
|
+
RemoteAddr,
|
|
32
|
+
ResourceTiming,
|
|
33
|
+
SecurityDetails,
|
|
34
|
+
ServerFilePayload,
|
|
35
|
+
StorageState,
|
|
36
|
+
)
|
|
37
|
+
from playwright._impl._connection import ChannelOwner, from_channel
|
|
38
|
+
from playwright._impl._errors import is_target_closed_error
|
|
39
|
+
from playwright._impl._form_data import FormData
|
|
40
|
+
from playwright._impl._helper import (
|
|
41
|
+
Error,
|
|
42
|
+
NameValue,
|
|
43
|
+
TargetClosedError,
|
|
44
|
+
TimeoutSettings,
|
|
45
|
+
async_readfile,
|
|
46
|
+
async_writefile,
|
|
47
|
+
is_file_payload,
|
|
48
|
+
locals_to_params,
|
|
49
|
+
object_to_array,
|
|
50
|
+
to_impl,
|
|
51
|
+
)
|
|
52
|
+
from playwright._impl._network import serialize_headers, to_client_certificates_protocol
|
|
53
|
+
from playwright._impl._tracing import Tracing
|
|
54
|
+
|
|
55
|
+
if typing.TYPE_CHECKING:
|
|
56
|
+
from playwright._impl._playwright import Playwright
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
FormType = Union[Dict[str, Union[bool, float, str]], FormData]
|
|
60
|
+
DataType = Union[Any, bytes, str]
|
|
61
|
+
MultipartType = Union[Dict[str, Union[bytes, bool, float, str, FilePayload]], FormData]
|
|
62
|
+
ParamsType = Union[Dict[str, Union[bool, float, str]], str]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class APIRequest:
|
|
66
|
+
def __init__(self, playwright: "Playwright") -> None:
|
|
67
|
+
self.playwright = playwright
|
|
68
|
+
self._loop = playwright._loop
|
|
69
|
+
self._dispatcher_fiber = playwright._connection._dispatcher_fiber
|
|
70
|
+
|
|
71
|
+
async def new_context(
|
|
72
|
+
self,
|
|
73
|
+
baseURL: str = None,
|
|
74
|
+
extraHTTPHeaders: Dict[str, str] = None,
|
|
75
|
+
httpCredentials: HttpCredentials = None,
|
|
76
|
+
ignoreHTTPSErrors: bool = None,
|
|
77
|
+
proxy: ProxySettings = None,
|
|
78
|
+
userAgent: str = None,
|
|
79
|
+
timeout: float = None,
|
|
80
|
+
storageState: Union[StorageState, str, Path] = None,
|
|
81
|
+
clientCertificates: List[ClientCertificate] = None,
|
|
82
|
+
failOnStatusCode: bool = None,
|
|
83
|
+
maxRedirects: int = None,
|
|
84
|
+
) -> "APIRequestContext":
|
|
85
|
+
params = locals_to_params(locals())
|
|
86
|
+
if "storageState" in params:
|
|
87
|
+
storage_state = params["storageState"]
|
|
88
|
+
if not isinstance(storage_state, dict) and storage_state:
|
|
89
|
+
params["storageState"] = json.loads(
|
|
90
|
+
(await async_readfile(storage_state)).decode()
|
|
91
|
+
)
|
|
92
|
+
if "extraHTTPHeaders" in params:
|
|
93
|
+
params["extraHTTPHeaders"] = serialize_headers(params["extraHTTPHeaders"])
|
|
94
|
+
params["clientCertificates"] = await to_client_certificates_protocol(
|
|
95
|
+
params.get("clientCertificates")
|
|
96
|
+
)
|
|
97
|
+
context = cast(
|
|
98
|
+
APIRequestContext,
|
|
99
|
+
from_channel(
|
|
100
|
+
await self.playwright._channel.send("newRequest", None, params)
|
|
101
|
+
),
|
|
102
|
+
)
|
|
103
|
+
context._timeout_settings.set_default_timeout(timeout)
|
|
104
|
+
return context
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class APIRequestContext(ChannelOwner):
|
|
108
|
+
def __init__(
|
|
109
|
+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
|
|
110
|
+
) -> None:
|
|
111
|
+
super().__init__(parent, type, guid, initializer)
|
|
112
|
+
self._tracing: Tracing = from_channel(initializer["tracing"])
|
|
113
|
+
self._close_reason: Optional[str] = None
|
|
114
|
+
self._timeout_settings = TimeoutSettings(None)
|
|
115
|
+
|
|
116
|
+
async def dispose(self, reason: str = None) -> None:
|
|
117
|
+
self._close_reason = reason
|
|
118
|
+
await self._tracing._export_all_hars()
|
|
119
|
+
try:
|
|
120
|
+
await self._channel.send("dispose", None, {"reason": reason})
|
|
121
|
+
except Error as e:
|
|
122
|
+
if is_target_closed_error(e):
|
|
123
|
+
return
|
|
124
|
+
raise e
|
|
125
|
+
self._tracing._reset_stack_counter()
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def tracing(self) -> Tracing:
|
|
129
|
+
return self._tracing
|
|
130
|
+
|
|
131
|
+
async def delete(
|
|
132
|
+
self,
|
|
133
|
+
url: str,
|
|
134
|
+
params: ParamsType = None,
|
|
135
|
+
headers: Headers = None,
|
|
136
|
+
data: DataType = None,
|
|
137
|
+
form: FormType = None,
|
|
138
|
+
multipart: MultipartType = None,
|
|
139
|
+
timeout: float = None,
|
|
140
|
+
failOnStatusCode: bool = None,
|
|
141
|
+
ignoreHTTPSErrors: bool = None,
|
|
142
|
+
maxRedirects: int = None,
|
|
143
|
+
maxRetries: int = None,
|
|
144
|
+
) -> "APIResponse":
|
|
145
|
+
return await self.fetch(
|
|
146
|
+
url,
|
|
147
|
+
method="DELETE",
|
|
148
|
+
params=params,
|
|
149
|
+
headers=headers,
|
|
150
|
+
data=data,
|
|
151
|
+
form=form,
|
|
152
|
+
multipart=multipart,
|
|
153
|
+
timeout=timeout,
|
|
154
|
+
failOnStatusCode=failOnStatusCode,
|
|
155
|
+
ignoreHTTPSErrors=ignoreHTTPSErrors,
|
|
156
|
+
maxRedirects=maxRedirects,
|
|
157
|
+
maxRetries=maxRetries,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
async def head(
|
|
161
|
+
self,
|
|
162
|
+
url: str,
|
|
163
|
+
params: ParamsType = None,
|
|
164
|
+
headers: Headers = None,
|
|
165
|
+
data: DataType = None,
|
|
166
|
+
form: FormType = None,
|
|
167
|
+
multipart: MultipartType = None,
|
|
168
|
+
timeout: float = None,
|
|
169
|
+
failOnStatusCode: bool = None,
|
|
170
|
+
ignoreHTTPSErrors: bool = None,
|
|
171
|
+
maxRedirects: int = None,
|
|
172
|
+
maxRetries: int = None,
|
|
173
|
+
) -> "APIResponse":
|
|
174
|
+
return await self.fetch(
|
|
175
|
+
url,
|
|
176
|
+
method="HEAD",
|
|
177
|
+
params=params,
|
|
178
|
+
headers=headers,
|
|
179
|
+
data=data,
|
|
180
|
+
form=form,
|
|
181
|
+
multipart=multipart,
|
|
182
|
+
timeout=timeout,
|
|
183
|
+
failOnStatusCode=failOnStatusCode,
|
|
184
|
+
ignoreHTTPSErrors=ignoreHTTPSErrors,
|
|
185
|
+
maxRedirects=maxRedirects,
|
|
186
|
+
maxRetries=maxRetries,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
async def get(
|
|
190
|
+
self,
|
|
191
|
+
url: str,
|
|
192
|
+
params: ParamsType = None,
|
|
193
|
+
headers: Headers = None,
|
|
194
|
+
data: DataType = None,
|
|
195
|
+
form: FormType = None,
|
|
196
|
+
multipart: MultipartType = None,
|
|
197
|
+
timeout: float = None,
|
|
198
|
+
failOnStatusCode: bool = None,
|
|
199
|
+
ignoreHTTPSErrors: bool = None,
|
|
200
|
+
maxRedirects: int = None,
|
|
201
|
+
maxRetries: int = None,
|
|
202
|
+
) -> "APIResponse":
|
|
203
|
+
return await self.fetch(
|
|
204
|
+
url,
|
|
205
|
+
method="GET",
|
|
206
|
+
params=params,
|
|
207
|
+
headers=headers,
|
|
208
|
+
data=data,
|
|
209
|
+
form=form,
|
|
210
|
+
multipart=multipart,
|
|
211
|
+
timeout=timeout,
|
|
212
|
+
failOnStatusCode=failOnStatusCode,
|
|
213
|
+
ignoreHTTPSErrors=ignoreHTTPSErrors,
|
|
214
|
+
maxRedirects=maxRedirects,
|
|
215
|
+
maxRetries=maxRetries,
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
async def patch(
|
|
219
|
+
self,
|
|
220
|
+
url: str,
|
|
221
|
+
params: ParamsType = None,
|
|
222
|
+
headers: Headers = None,
|
|
223
|
+
data: DataType = None,
|
|
224
|
+
form: FormType = None,
|
|
225
|
+
multipart: MultipartType = None,
|
|
226
|
+
timeout: float = None,
|
|
227
|
+
failOnStatusCode: bool = None,
|
|
228
|
+
ignoreHTTPSErrors: bool = None,
|
|
229
|
+
maxRedirects: int = None,
|
|
230
|
+
maxRetries: int = None,
|
|
231
|
+
) -> "APIResponse":
|
|
232
|
+
return await self.fetch(
|
|
233
|
+
url,
|
|
234
|
+
method="PATCH",
|
|
235
|
+
params=params,
|
|
236
|
+
headers=headers,
|
|
237
|
+
data=data,
|
|
238
|
+
form=form,
|
|
239
|
+
multipart=multipart,
|
|
240
|
+
timeout=timeout,
|
|
241
|
+
failOnStatusCode=failOnStatusCode,
|
|
242
|
+
ignoreHTTPSErrors=ignoreHTTPSErrors,
|
|
243
|
+
maxRedirects=maxRedirects,
|
|
244
|
+
maxRetries=maxRetries,
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
async def put(
|
|
248
|
+
self,
|
|
249
|
+
url: str,
|
|
250
|
+
params: ParamsType = None,
|
|
251
|
+
headers: Headers = None,
|
|
252
|
+
data: DataType = None,
|
|
253
|
+
form: FormType = None,
|
|
254
|
+
multipart: MultipartType = None,
|
|
255
|
+
timeout: float = None,
|
|
256
|
+
failOnStatusCode: bool = None,
|
|
257
|
+
ignoreHTTPSErrors: bool = None,
|
|
258
|
+
maxRedirects: int = None,
|
|
259
|
+
maxRetries: int = None,
|
|
260
|
+
) -> "APIResponse":
|
|
261
|
+
return await self.fetch(
|
|
262
|
+
url,
|
|
263
|
+
method="PUT",
|
|
264
|
+
params=params,
|
|
265
|
+
headers=headers,
|
|
266
|
+
data=data,
|
|
267
|
+
form=form,
|
|
268
|
+
multipart=multipart,
|
|
269
|
+
timeout=timeout,
|
|
270
|
+
failOnStatusCode=failOnStatusCode,
|
|
271
|
+
ignoreHTTPSErrors=ignoreHTTPSErrors,
|
|
272
|
+
maxRedirects=maxRedirects,
|
|
273
|
+
maxRetries=maxRetries,
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
async def post(
|
|
277
|
+
self,
|
|
278
|
+
url: str,
|
|
279
|
+
params: ParamsType = None,
|
|
280
|
+
headers: Headers = None,
|
|
281
|
+
data: DataType = None,
|
|
282
|
+
form: FormType = None,
|
|
283
|
+
multipart: MultipartType = None,
|
|
284
|
+
timeout: float = None,
|
|
285
|
+
failOnStatusCode: bool = None,
|
|
286
|
+
ignoreHTTPSErrors: bool = None,
|
|
287
|
+
maxRedirects: int = None,
|
|
288
|
+
maxRetries: int = None,
|
|
289
|
+
) -> "APIResponse":
|
|
290
|
+
return await self.fetch(
|
|
291
|
+
url,
|
|
292
|
+
method="POST",
|
|
293
|
+
params=params,
|
|
294
|
+
headers=headers,
|
|
295
|
+
data=data,
|
|
296
|
+
form=form,
|
|
297
|
+
multipart=multipart,
|
|
298
|
+
timeout=timeout,
|
|
299
|
+
failOnStatusCode=failOnStatusCode,
|
|
300
|
+
ignoreHTTPSErrors=ignoreHTTPSErrors,
|
|
301
|
+
maxRedirects=maxRedirects,
|
|
302
|
+
maxRetries=maxRetries,
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
async def fetch(
|
|
306
|
+
self,
|
|
307
|
+
urlOrRequest: Union[str, network.Request],
|
|
308
|
+
params: ParamsType = None,
|
|
309
|
+
method: str = None,
|
|
310
|
+
headers: Headers = None,
|
|
311
|
+
data: DataType = None,
|
|
312
|
+
form: FormType = None,
|
|
313
|
+
multipart: MultipartType = None,
|
|
314
|
+
timeout: float = None,
|
|
315
|
+
failOnStatusCode: bool = None,
|
|
316
|
+
ignoreHTTPSErrors: bool = None,
|
|
317
|
+
maxRedirects: int = None,
|
|
318
|
+
maxRetries: int = None,
|
|
319
|
+
) -> "APIResponse":
|
|
320
|
+
url = urlOrRequest if isinstance(urlOrRequest, str) else None
|
|
321
|
+
request = (
|
|
322
|
+
cast(network.Request, to_impl(urlOrRequest))
|
|
323
|
+
if isinstance(to_impl(urlOrRequest), network.Request)
|
|
324
|
+
else None
|
|
325
|
+
)
|
|
326
|
+
assert request or isinstance(
|
|
327
|
+
urlOrRequest, str
|
|
328
|
+
), "First argument must be either URL string or Request"
|
|
329
|
+
return await self._inner_fetch(
|
|
330
|
+
request,
|
|
331
|
+
url,
|
|
332
|
+
method,
|
|
333
|
+
headers,
|
|
334
|
+
data,
|
|
335
|
+
params,
|
|
336
|
+
form,
|
|
337
|
+
multipart,
|
|
338
|
+
timeout,
|
|
339
|
+
failOnStatusCode,
|
|
340
|
+
ignoreHTTPSErrors,
|
|
341
|
+
maxRedirects,
|
|
342
|
+
maxRetries,
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
async def _inner_fetch(
|
|
346
|
+
self,
|
|
347
|
+
request: Optional[network.Request],
|
|
348
|
+
url: Optional[str],
|
|
349
|
+
method: str = None,
|
|
350
|
+
headers: Headers = None,
|
|
351
|
+
data: DataType = None,
|
|
352
|
+
params: ParamsType = None,
|
|
353
|
+
form: FormType = None,
|
|
354
|
+
multipart: MultipartType = None,
|
|
355
|
+
timeout: float = None,
|
|
356
|
+
failOnStatusCode: bool = None,
|
|
357
|
+
ignoreHTTPSErrors: bool = None,
|
|
358
|
+
maxRedirects: int = None,
|
|
359
|
+
maxRetries: int = None,
|
|
360
|
+
) -> "APIResponse":
|
|
361
|
+
if self._close_reason:
|
|
362
|
+
raise TargetClosedError(self._close_reason)
|
|
363
|
+
assert (
|
|
364
|
+
(1 if data else 0) + (1 if form else 0) + (1 if multipart else 0)
|
|
365
|
+
) <= 1, "Only one of 'data', 'form' or 'multipart' can be specified"
|
|
366
|
+
assert (
|
|
367
|
+
maxRedirects is None or maxRedirects >= 0
|
|
368
|
+
), "'max_redirects' must be greater than or equal to '0'"
|
|
369
|
+
assert (
|
|
370
|
+
maxRetries is None or maxRetries >= 0
|
|
371
|
+
), "'max_retries' must be greater than or equal to '0'"
|
|
372
|
+
url = url or (request.url if request else url)
|
|
373
|
+
method = method or (request.method if request else "GET")
|
|
374
|
+
# Cannot call allHeaders() here as the request may be paused inside route handler.
|
|
375
|
+
headers_obj = headers or (request.headers if request else None)
|
|
376
|
+
serialized_headers = serialize_headers(headers_obj) if headers_obj else None
|
|
377
|
+
json_data: Any = None
|
|
378
|
+
form_data: Optional[List[NameValue]] = None
|
|
379
|
+
multipart_data: Optional[List[FormField]] = None
|
|
380
|
+
post_data_buffer: Optional[bytes] = None
|
|
381
|
+
if data is not None:
|
|
382
|
+
if isinstance(data, str):
|
|
383
|
+
if is_json_content_type(serialized_headers):
|
|
384
|
+
json_data = data if is_json_parsable(data) else json.dumps(data)
|
|
385
|
+
else:
|
|
386
|
+
post_data_buffer = data.encode()
|
|
387
|
+
elif isinstance(data, bytes):
|
|
388
|
+
post_data_buffer = data
|
|
389
|
+
elif isinstance(data, (dict, list, int, bool)):
|
|
390
|
+
json_data = json.dumps(data)
|
|
391
|
+
else:
|
|
392
|
+
raise Error(f"Unsupported 'data' type: {type(data)}")
|
|
393
|
+
elif form:
|
|
394
|
+
if isinstance(form, FormData):
|
|
395
|
+
form_data = []
|
|
396
|
+
for fd_name, fd_value in form._fields:
|
|
397
|
+
if isinstance(fd_value, (pathlib.Path, dict)):
|
|
398
|
+
raise Error(
|
|
399
|
+
f"Form field {fd_name!r} must be a string, number or boolean. Use 'multipart' for file uploads."
|
|
400
|
+
)
|
|
401
|
+
form_data.append(NameValue(name=fd_name, value=str(fd_value)))
|
|
402
|
+
else:
|
|
403
|
+
form_data = object_to_array(form)
|
|
404
|
+
elif multipart:
|
|
405
|
+
multipart_data = []
|
|
406
|
+
if isinstance(multipart, FormData):
|
|
407
|
+
for fd_name, fd_value in multipart._fields:
|
|
408
|
+
multipart_data.append(
|
|
409
|
+
await _form_data_field_to_form_field(fd_name, fd_value)
|
|
410
|
+
)
|
|
411
|
+
else:
|
|
412
|
+
# Convert file-like values to ServerFilePayload structs.
|
|
413
|
+
for name, value in multipart.items():
|
|
414
|
+
if is_file_payload(value):
|
|
415
|
+
payload = cast(FilePayload, value)
|
|
416
|
+
assert isinstance(
|
|
417
|
+
payload["buffer"], bytes
|
|
418
|
+
), f"Unexpected buffer type of 'data.{name}'"
|
|
419
|
+
multipart_data.append(
|
|
420
|
+
FormField(name=name, file=file_payload_to_json(payload))
|
|
421
|
+
)
|
|
422
|
+
elif isinstance(value, str):
|
|
423
|
+
multipart_data.append(FormField(name=name, value=value))
|
|
424
|
+
if (
|
|
425
|
+
post_data_buffer is None
|
|
426
|
+
and json_data is None
|
|
427
|
+
and form_data is None
|
|
428
|
+
and multipart_data is None
|
|
429
|
+
):
|
|
430
|
+
post_data_buffer = request.post_data_buffer if request else None
|
|
431
|
+
post_data = (
|
|
432
|
+
base64.b64encode(post_data_buffer).decode() if post_data_buffer else None
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
response = await self._channel.send(
|
|
436
|
+
"fetch",
|
|
437
|
+
self._timeout_settings.timeout,
|
|
438
|
+
{
|
|
439
|
+
"url": url,
|
|
440
|
+
"timeout": timeout,
|
|
441
|
+
"params": object_to_array(params) if isinstance(params, dict) else None,
|
|
442
|
+
"encodedParams": params if isinstance(params, str) else None,
|
|
443
|
+
"method": method,
|
|
444
|
+
"headers": serialized_headers,
|
|
445
|
+
"postData": post_data,
|
|
446
|
+
"jsonData": json_data,
|
|
447
|
+
"formData": form_data,
|
|
448
|
+
"multipartData": multipart_data,
|
|
449
|
+
"failOnStatusCode": failOnStatusCode,
|
|
450
|
+
"ignoreHTTPSErrors": ignoreHTTPSErrors,
|
|
451
|
+
"maxRedirects": maxRedirects,
|
|
452
|
+
"maxRetries": maxRetries,
|
|
453
|
+
},
|
|
454
|
+
)
|
|
455
|
+
return APIResponse(self, response)
|
|
456
|
+
|
|
457
|
+
async def storage_state(
|
|
458
|
+
self,
|
|
459
|
+
path: Union[pathlib.Path, str] = None,
|
|
460
|
+
indexedDB: bool = None,
|
|
461
|
+
) -> StorageState:
|
|
462
|
+
result = await self._channel.send_return_as_dict(
|
|
463
|
+
"storageState", None, {"indexedDB": indexedDB}
|
|
464
|
+
)
|
|
465
|
+
if path:
|
|
466
|
+
await async_writefile(path, json.dumps(result))
|
|
467
|
+
return result
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def file_payload_to_json(payload: FilePayload) -> ServerFilePayload:
|
|
471
|
+
return ServerFilePayload(
|
|
472
|
+
name=payload["name"],
|
|
473
|
+
mimeType=payload["mimeType"],
|
|
474
|
+
buffer=base64.b64encode(payload["buffer"]).decode(),
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
async def _form_data_field_to_form_field(name: str, value: Any) -> FormField:
|
|
479
|
+
if isinstance(value, pathlib.Path):
|
|
480
|
+
mime_type, _ = mimetypes.guess_type(str(value))
|
|
481
|
+
return FormField(
|
|
482
|
+
name=name,
|
|
483
|
+
file=ServerFilePayload(
|
|
484
|
+
name=value.name,
|
|
485
|
+
mimeType=mime_type or "application/octet-stream",
|
|
486
|
+
buffer=base64.b64encode(await async_readfile(str(value))).decode(),
|
|
487
|
+
),
|
|
488
|
+
)
|
|
489
|
+
if is_file_payload(value):
|
|
490
|
+
payload = cast(FilePayload, value)
|
|
491
|
+
assert isinstance(
|
|
492
|
+
payload["buffer"], bytes
|
|
493
|
+
), f"Unexpected buffer type of form field {name!r}"
|
|
494
|
+
return FormField(name=name, file=file_payload_to_json(payload))
|
|
495
|
+
if isinstance(value, (str, int, float, bool)):
|
|
496
|
+
return FormField(name=name, value=str(value))
|
|
497
|
+
raise Error(f"Unsupported form field {name!r} value type: {type(value).__name__}")
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
class APIResponse:
|
|
501
|
+
def __init__(self, context: APIRequestContext, initializer: Dict) -> None:
|
|
502
|
+
self._loop = context._loop
|
|
503
|
+
self._dispatcher_fiber = context._connection._dispatcher_fiber
|
|
504
|
+
self._request = context
|
|
505
|
+
self._initializer = initializer
|
|
506
|
+
self._headers = network.RawHeaders(initializer["headers"])
|
|
507
|
+
|
|
508
|
+
def __repr__(self) -> str:
|
|
509
|
+
return f"<APIResponse url={self.url!r} status={self.status!r} status_text={self.status_text!r}>"
|
|
510
|
+
|
|
511
|
+
@property
|
|
512
|
+
def ok(self) -> bool:
|
|
513
|
+
return self.status >= 200 and self.status <= 299
|
|
514
|
+
|
|
515
|
+
@property
|
|
516
|
+
def url(self) -> str:
|
|
517
|
+
return self._initializer["url"]
|
|
518
|
+
|
|
519
|
+
@property
|
|
520
|
+
def status(self) -> int:
|
|
521
|
+
return self._initializer["status"]
|
|
522
|
+
|
|
523
|
+
@property
|
|
524
|
+
def status_text(self) -> str:
|
|
525
|
+
return self._initializer["statusText"]
|
|
526
|
+
|
|
527
|
+
@property
|
|
528
|
+
def headers(self) -> Headers:
|
|
529
|
+
return self._headers.headers()
|
|
530
|
+
|
|
531
|
+
@property
|
|
532
|
+
def headers_array(self) -> network.HeadersArray:
|
|
533
|
+
return self._headers.headers_array()
|
|
534
|
+
|
|
535
|
+
@property
|
|
536
|
+
def timing(self) -> ResourceTiming:
|
|
537
|
+
return cast(
|
|
538
|
+
ResourceTiming,
|
|
539
|
+
{
|
|
540
|
+
"startTime": -1,
|
|
541
|
+
"domainLookupStart": -1,
|
|
542
|
+
"domainLookupEnd": -1,
|
|
543
|
+
"connectStart": -1,
|
|
544
|
+
"secureConnectionStart": -1,
|
|
545
|
+
"connectEnd": -1,
|
|
546
|
+
"requestStart": -1,
|
|
547
|
+
"responseStart": -1,
|
|
548
|
+
**self._initializer.get("timing", {}),
|
|
549
|
+
"responseEnd": self._initializer.get("responseEndTiming", -1),
|
|
550
|
+
},
|
|
551
|
+
)
|
|
552
|
+
|
|
553
|
+
async def body(self) -> bytes:
|
|
554
|
+
try:
|
|
555
|
+
result = await self._request._connection.wrap_api_call(
|
|
556
|
+
lambda: self._request._channel.send_return_as_dict(
|
|
557
|
+
"fetchResponseBody",
|
|
558
|
+
None,
|
|
559
|
+
{
|
|
560
|
+
"fetchUid": self._fetch_uid,
|
|
561
|
+
},
|
|
562
|
+
),
|
|
563
|
+
True,
|
|
564
|
+
)
|
|
565
|
+
if result is None:
|
|
566
|
+
raise Error("Response has been disposed")
|
|
567
|
+
return base64.b64decode(result["binary"])
|
|
568
|
+
except Error as exc:
|
|
569
|
+
if is_target_closed_error(exc):
|
|
570
|
+
raise Error("Response has been disposed")
|
|
571
|
+
raise exc
|
|
572
|
+
|
|
573
|
+
async def text(self) -> str:
|
|
574
|
+
content = await self.body()
|
|
575
|
+
return content.decode()
|
|
576
|
+
|
|
577
|
+
async def json(self) -> Any:
|
|
578
|
+
content = await self.text()
|
|
579
|
+
return json.loads(content)
|
|
580
|
+
|
|
581
|
+
async def security_details(self) -> Optional[SecurityDetails]:
|
|
582
|
+
return self._initializer.get("securityDetails") or None
|
|
583
|
+
|
|
584
|
+
async def server_addr(self) -> Optional[RemoteAddr]:
|
|
585
|
+
return self._initializer.get("serverAddr") or None
|
|
586
|
+
|
|
587
|
+
async def dispose(self) -> None:
|
|
588
|
+
await self._request._channel.send(
|
|
589
|
+
"disposeAPIResponse",
|
|
590
|
+
None,
|
|
591
|
+
{
|
|
592
|
+
"fetchUid": self._fetch_uid,
|
|
593
|
+
},
|
|
594
|
+
)
|
|
595
|
+
|
|
596
|
+
@property
|
|
597
|
+
def _fetch_uid(self) -> str:
|
|
598
|
+
return self._initializer["fetchUid"]
|
|
599
|
+
|
|
600
|
+
async def _fetch_log(self) -> List[str]:
|
|
601
|
+
return await self._request._channel.send(
|
|
602
|
+
"fetchLog",
|
|
603
|
+
None,
|
|
604
|
+
{
|
|
605
|
+
"fetchUid": self._fetch_uid,
|
|
606
|
+
},
|
|
607
|
+
)
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
def is_json_content_type(headers: network.HeadersArray = None) -> bool:
|
|
611
|
+
if not headers:
|
|
612
|
+
return False
|
|
613
|
+
for header in headers:
|
|
614
|
+
if header["name"] == "Content-Type":
|
|
615
|
+
return header["value"].startswith("application/json")
|
|
616
|
+
return False
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
def is_json_parsable(value: Any) -> bool:
|
|
620
|
+
if not isinstance(value, str):
|
|
621
|
+
return False
|
|
622
|
+
try:
|
|
623
|
+
json.loads(value)
|
|
624
|
+
return True
|
|
625
|
+
except json.JSONDecodeError:
|
|
626
|
+
return False
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import TYPE_CHECKING, Sequence, Union
|
|
17
|
+
|
|
18
|
+
from playwright._impl._api_structures import FilePayload
|
|
19
|
+
|
|
20
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
21
|
+
from playwright._impl._element_handle import ElementHandle
|
|
22
|
+
from playwright._impl._page import Page
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class FileChooser:
|
|
26
|
+
def __init__(
|
|
27
|
+
self, page: "Page", element_handle: "ElementHandle", is_multiple: bool
|
|
28
|
+
) -> None:
|
|
29
|
+
self._page = page
|
|
30
|
+
self._loop = page._loop
|
|
31
|
+
self._dispatcher_fiber = page._dispatcher_fiber
|
|
32
|
+
self._element_handle = element_handle
|
|
33
|
+
self._is_multiple = is_multiple
|
|
34
|
+
|
|
35
|
+
def __repr__(self) -> str:
|
|
36
|
+
return f"<FileChooser page={self._page} element={self._element_handle}>"
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def page(self) -> "Page":
|
|
40
|
+
return self._page
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def element(self) -> "ElementHandle":
|
|
44
|
+
return self._element_handle
|
|
45
|
+
|
|
46
|
+
def is_multiple(self) -> bool:
|
|
47
|
+
return self._is_multiple
|
|
48
|
+
|
|
49
|
+
async def set_files(
|
|
50
|
+
self,
|
|
51
|
+
files: Union[
|
|
52
|
+
str, Path, FilePayload, Sequence[Union[str, Path]], Sequence[FilePayload]
|
|
53
|
+
],
|
|
54
|
+
timeout: float = None,
|
|
55
|
+
noWaitAfter: bool = None,
|
|
56
|
+
) -> None:
|
|
57
|
+
await self._element_handle.set_input_files(files, timeout, noWaitAfter)
|