Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions playwright/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
and for the async API [here](async_api.html).
"""

import playwright.helper as helper
import playwright.types as types
from playwright.main import AsyncPlaywrightContextManager, SyncPlaywrightContextManager

Error = helper.Error
TimeoutError = helper.TimeoutError
Error = types.Error
TimeoutError = types.TimeoutError


def async_playwright() -> AsyncPlaywrightContextManager:
Expand Down
55 changes: 26 additions & 29 deletions playwright/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,22 @@
from playwright.element_handle import ElementHandle as ElementHandleImpl
from playwright.file_chooser import FileChooser as FileChooserImpl
from playwright.frame import Frame as FrameImpl
from playwright.helper import (
from playwright.input import Keyboard as KeyboardImpl
from playwright.input import Mouse as MouseImpl
from playwright.input import Touchscreen as TouchscreenImpl
from playwright.js_handle import JSHandle as JSHandleImpl
from playwright.network import Request as RequestImpl
from playwright.network import Response as ResponseImpl
from playwright.network import Route as RouteImpl
from playwright.network import WebSocket as WebSocketImpl
from playwright.page import BindingCall as BindingCallImpl
from playwright.page import Page as PageImpl
from playwright.page import Worker as WorkerImpl
from playwright.playwright import Playwright as PlaywrightImpl
from playwright.selectors import Selectors as SelectorsImpl
from playwright.types import (
ConsoleMessageLocation,
Cookie,
Credentials,
DeviceDescriptor,
Error,
Expand All @@ -54,23 +68,8 @@
RequestFailure,
ResourceTiming,
SelectOption,
SetStorageState,
StorageState,
Viewport,
)
from playwright.input import Keyboard as KeyboardImpl
from playwright.input import Mouse as MouseImpl
from playwright.input import Touchscreen as TouchscreenImpl
from playwright.js_handle import JSHandle as JSHandleImpl
from playwright.network import Request as RequestImpl
from playwright.network import Response as ResponseImpl
from playwright.network import Route as RouteImpl
from playwright.network import WebSocket as WebSocketImpl
from playwright.page import BindingCall as BindingCallImpl
from playwright.page import Page as PageImpl
from playwright.page import Worker as WorkerImpl
from playwright.playwright import Playwright as PlaywrightImpl
from playwright.selectors import Selectors as SelectorsImpl
from playwright.video import Video as VideoImpl

NoneType = type(None)
Expand Down Expand Up @@ -4548,7 +4547,7 @@ async def setViewportSize(self, width: int, height: int) -> NoneType:
await self._impl_obj.setViewportSize(width=width, height=height)
)

def viewportSize(self) -> typing.Union[Viewport, NoneType]:
def viewportSize(self) -> typing.Union[IntSize, NoneType]:
"""Page.viewportSize

Returns
Expand Down Expand Up @@ -5920,7 +5919,7 @@ async def newPage(self) -> "Page":

async def cookies(
self, urls: typing.Union[str, typing.List[str]] = None
) -> typing.List[typing.Dict]:
) -> typing.List[Cookie]:
"""BrowserContext.cookies

If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
Expand All @@ -5933,23 +5932,21 @@ async def cookies(

Returns
-------
List[Dict]
List[{"name": str, "value": str, "url": Optional[str], "domain": Optional[str], "path": Optional[str], "expires": Optional[int], "httpOnly": Optional[bool], "secure": Optional[bool], "sameSite": Optional[Literal['Strict', 'Lax', 'None']]}]
"""
return mapping.from_maybe_impl(await self._impl_obj.cookies(urls=urls))

async def addCookies(self, cookies: typing.List[typing.Dict]) -> NoneType:
async def addCookies(self, cookies: typing.List[Cookie]) -> NoneType:
"""BrowserContext.addCookies

Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
obtained via browserContext.cookies([urls]).

Parameters
----------
cookies : List[Dict]
cookies : List[{"name": str, "value": str, "url": Optional[str], "domain": Optional[str], "path": Optional[str], "expires": Optional[int], "httpOnly": Optional[bool], "secure": Optional[bool], "sameSite": Optional[Literal['Strict', 'Lax', 'None']]}]
"""
return mapping.from_maybe_impl(
await self._impl_obj.addCookies(cookies=mapping.to_impl(cookies))
)
return mapping.from_maybe_impl(await self._impl_obj.addCookies(cookies=cookies))

async def clearCookies(self) -> NoneType:
"""BrowserContext.clearCookies
Expand Down Expand Up @@ -6218,7 +6215,7 @@ async def storageState(self) -> StorageState:

Returns
-------
{"cookies": List[Dict], "origins": List[Dict]}
{"cookies": Optional[List[{"name": str, "value": str, "url": Optional[str], "domain": Optional[str], "path": Optional[str], "expires": Optional[int], "httpOnly": Optional[bool], "secure": Optional[bool], "sameSite": Optional[Literal['Strict', 'Lax', 'None']]}]], "origins": Optional[List[Dict]]}
"""
return mapping.from_maybe_impl(await self._impl_obj.storageState())

Expand Down Expand Up @@ -6430,7 +6427,7 @@ async def newContext(
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
storageState: SetStorageState = None,
storageState: StorageState = None,
) -> "BrowserContext":
"""Browser.newContext

Expand Down Expand Up @@ -6481,7 +6478,7 @@ async def newContext(
Enables HAR recording for all pages into `recordHar.path` file. If not specified, the HAR is not recorded. Make sure to await browserContext.close() for the HAR to be saved.
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make sure to await browserContext.close() for videos to be saved.
storageState : Optional[{"cookies": Optional[List[Dict]], "origins": Optional[List[Dict]]}]
storageState : Optional[{"cookies": Optional[List[{"name": str, "value": str, "url": Optional[str], "domain": Optional[str], "path": Optional[str], "expires": Optional[int], "httpOnly": Optional[bool], "secure": Optional[bool], "sameSite": Optional[Literal['Strict', 'Lax', 'None']]}]], "origins": Optional[List[Dict]]}]
Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via browserContext.storageState().

Returns
Expand Down Expand Up @@ -6542,7 +6539,7 @@ async def newPage(
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
storageState: SetStorageState = None,
storageState: StorageState = None,
) -> "Page":
"""Browser.newPage

Expand Down Expand Up @@ -6596,7 +6593,7 @@ async def newPage(
Enables HAR recording for all pages into `recordHar.path` file. If not specified, the HAR is not recorded. Make sure to await browserContext.close() for the HAR to be saved.
recordVideo : Optional[{"dir": str, "size": Optional[{"width": int, "height": int}]}]
Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make sure to await browserContext.close() for videos to be saved.
storageState : Optional[{"cookies": Optional[List[Dict]], "origins": Optional[List[Dict]]}]
storageState : Optional[{"cookies": Optional[List[{"name": str, "value": str, "url": Optional[str], "domain": Optional[str], "path": Optional[str], "expires": Optional[int], "httpOnly": Optional[bool], "secure": Optional[bool], "sameSite": Optional[Literal['Strict', 'Lax', 'None']]}]], "origins": Optional[List[Dict]]}]
Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via browserContext.storageState().

Returns
Expand Down
16 changes: 7 additions & 9 deletions playwright/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@

from playwright.browser_context import BrowserContext
from playwright.connection import ChannelOwner, from_channel
from playwright.helper import (
ColorScheme,
from playwright.helper import ColorScheme, is_safe_close_error, locals_to_params
from playwright.network import serialize_headers
from playwright.page import Page
from playwright.types import (
Credentials,
Geolocation,
IntSize,
ProxyServer,
RecordHarOptions,
RecordVideoOptions,
SetStorageState,
is_safe_close_error,
locals_to_params,
StorageState,
)
from playwright.network import serialize_headers
from playwright.page import Page

if sys.version_info >= (3, 8): # pragma: no cover
from typing import Literal
Expand Down Expand Up @@ -96,7 +94,7 @@ async def newContext(
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
storageState: SetStorageState = None,
storageState: StorageState = None,
) -> BrowserContext:
params = locals_to_params(locals())
# Python is strict in which variables gets passed to methods. We get this
Expand Down Expand Up @@ -145,7 +143,7 @@ async def newPage(
videoSize: IntSize = None,
recordHar: RecordHarOptions = None,
recordVideo: RecordVideoOptions = None,
storageState: SetStorageState = None,
storageState: StorageState = None,
) -> Page:
params = locals_to_params(locals())
# Python is strict in which variables gets passed to methods. We get this
Expand Down
5 changes: 1 addition & 4 deletions playwright/browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@
from playwright.connection import ChannelOwner, from_channel
from playwright.event_context_manager import EventContextManagerImpl
from playwright.helper import (
Cookie,
Error,
Geolocation,
PendingWaitEvent,
RouteHandler,
RouteHandlerEntry,
StorageState,
TimeoutSettings,
URLMatch,
URLMatcher,
Expand All @@ -35,6 +31,7 @@
)
from playwright.network import Request, Route, serialize_headers
from playwright.page import BindingCall, Page
from playwright.types import Cookie, Error, Geolocation, StorageState
from playwright.wait_helper import WaitHelper

if TYPE_CHECKING: # pragma: no cover
Expand Down
9 changes: 3 additions & 6 deletions playwright/browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@
from playwright.browser import Browser
from playwright.browser_context import BrowserContext
from playwright.connection import ChannelOwner, from_channel
from playwright.helper import (
ColorScheme,
from playwright.helper import ColorScheme, Env, locals_to_params, not_installed_error
from playwright.network import serialize_headers
from playwright.types import (
Credentials,
Env,
Geolocation,
IntSize,
ProxyServer,
RecordHarOptions,
RecordVideoOptions,
locals_to_params,
not_installed_error,
)
from playwright.network import serialize_headers

if sys.version_info >= (3, 8): # pragma: no cover
from typing import Literal
Expand Down
2 changes: 1 addition & 1 deletion playwright/console_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from typing import Dict, List

from playwright.connection import ChannelOwner, from_channel
from playwright.helper import ConsoleMessageLocation
from playwright.js_handle import JSHandle
from playwright.types import ConsoleMessageLocation


class ConsoleMessage(ChannelOwner):
Expand Down
5 changes: 1 addition & 4 deletions playwright/element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@

from playwright.connection import ChannelOwner, from_nullable_channel
from playwright.helper import (
FilePayload,
FloatRect,
KeyboardModifier,
MouseButton,
MousePosition,
SelectOption,
SetFilePayload,
locals_to_params,
)
Expand All @@ -36,6 +32,7 @@
parse_result,
serialize_argument,
)
from playwright.types import FilePayload, FloatRect, MousePosition, SelectOption

if sys.version_info >= (3, 8): # pragma: no cover
from typing import Literal
Expand Down
2 changes: 1 addition & 1 deletion playwright/file_chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from typing import TYPE_CHECKING, List, Union

from playwright.helper import FilePayload
from playwright.types import FilePayload

if TYPE_CHECKING: # pragma: no cover
from playwright.element_handle import ElementHandle
Expand Down
4 changes: 1 addition & 3 deletions playwright/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@
from playwright.event_context_manager import EventContextManagerImpl
from playwright.helper import (
DocumentLoadState,
Error,
FilePayload,
FrameNavigatedEvent,
KeyboardModifier,
MouseButton,
MousePosition,
URLMatch,
URLMatcher,
is_function_body,
Expand All @@ -48,6 +45,7 @@
serialize_argument,
)
from playwright.network import Response
from playwright.types import Error, FilePayload, MousePosition
from playwright.wait_helper import WaitHelper

if sys.version_info >= (3, 8): # pragma: no cover
Expand Down
Loading