Skip to content

Commit

Permalink
chore(roll): roll Playwright to 1.39.0-alpha-oct-10-2023
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Oct 11, 2023
1 parent e81afd4 commit f4b4635
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 163 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 🎭 [Playwright](https://playwright.dev) for Python [![PyPI version](https://badge.fury.io/py/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![Anaconda version](https://img.shields.io/conda/v/microsoft/playwright)](https://anaconda.org/Microsoft/playwright) [![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://aka.ms/playwright-slack)
# 🎭 [Playwright](https://playwright.dev) for Python [![PyPI version](https://badge.fury.io/py/playwright.svg)](https://pypi.python.org/pypi/playwright/) [![Anaconda version](https://img.shields.io/conda/v/microsoft/playwright)](https://anaconda.org/Microsoft/playwright) [![Join Discord](https://img.shields.io/badge/join-discord-infomational)](https://aka.ms/playwright/discord)

Playwright is a Python library to automate [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) browsers with a single API. Playwright delivers automation that is **ever-green**, **capable**, **reliable** and **fast**. [See how Playwright is better](https://playwright.dev/python/docs/why-playwright).

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->117.0.5938.62<!-- GEN:stop --> ||||
| Chromium <!-- GEN:chromium-version -->119.0.6045.9<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->17.0<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->117.0<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->118.0.1<!-- GEN:stop --> ||||

## Documentation

Expand Down Expand Up @@ -49,6 +49,6 @@ asyncio.run(main())
## Other languages

More comfortable in another programming language? [Playwright](https://playwright.dev) is also available in
- [Node.js (JavaScript / TypeScript)](https://playwright.dev/docs/intro)
- [.NET](https://playwright.dev/dotnet/docs/intro)
- [Java](https://playwright.dev/java/docs/intro)
- [Node.js (JavaScript / TypeScript)](https://playwright.dev/docs/intro),
- [.NET](https://playwright.dev/dotnet/docs/intro),
- [Java](https://playwright.dev/java/docs/intro).
2 changes: 1 addition & 1 deletion playwright/_impl/_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ async def to_have_attribute(
__tracebackhide__ = True
expected_text = to_expected_text_values([value])
await self._expect_impl(
"to.have.attribute",
"to.have.attribute.value",
FrameExpectOptions(
expressionArg=name, expectedText=expected_text, timeout=timeout
),
Expand Down
5 changes: 3 additions & 2 deletions playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __init__(
)
self._channel.on(
"console",
lambda params: self._on_console_message(from_channel(params["message"])),
lambda event: self._on_console_message(event),
)

self._channel.on(
Expand Down Expand Up @@ -545,7 +545,8 @@ def _on_request_finished(
if response:
response._finished_future.set_result(True)

def _on_console_message(self, message: ConsoleMessage) -> None:
def _on_console_message(self, event: Dict) -> None:
message = ConsoleMessage(event, self._loop, self._dispatcher_fiber)
self.emit(BrowserContext.Events.Console, message)
page = message.page
if page:
Expand Down
6 changes: 3 additions & 3 deletions playwright/_impl/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ def _send_message_to_server(
"internal": not stack_trace_information["apiName"],
},
}
self._transport.send(message)
self._callbacks[id] = callback

if self._tracing_count > 0 and frames and guid != "localUtils":
self.local_utils.add_stack_to_tracing_no_reply(id, frames)

self._transport.send(message)
self._callbacks[id] = callback

return callback

def dispatch(self, msg: ParsedMessagePayload) -> None:
Expand Down
30 changes: 13 additions & 17 deletions playwright/_impl/_console_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING, Dict, List, Optional
from asyncio import AbstractEventLoop
from typing import TYPE_CHECKING, Any, Dict, List, Optional

from playwright._impl._api_structures import SourceLocation
from playwright._impl._connection import (
ChannelOwner,
from_channel,
from_nullable_channel,
)
from playwright._impl._connection import from_channel, from_nullable_channel
from playwright._impl._js_handle import JSHandle

if TYPE_CHECKING: # pragma: no cover
from playwright._impl._page import Page


class ConsoleMessage(ChannelOwner):
class ConsoleMessage:
def __init__(
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
self, event: Dict, loop: AbstractEventLoop, dispatcher_fiber: Any
) -> None:
super().__init__(parent, type, guid, initializer)
# Note: currently, we only report console messages for pages and they always have a page.
# However, in the future we might report console messages for service workers or something else,
# where page() would be null.
self._page: Optional["Page"] = from_nullable_channel(initializer.get("page"))
self._event = event
self._loop = loop
self._dispatcher_fiber = dispatcher_fiber
self._page: Optional["Page"] = from_nullable_channel(event.get("page"))

def __repr__(self) -> str:
return f"<ConsoleMessage type={self.type} text={self.text}>"
Expand All @@ -44,19 +40,19 @@ def __str__(self) -> str:

@property
def type(self) -> str:
return self._initializer["type"]
return self._event["type"]

@property
def text(self) -> str:
return self._initializer["text"]
return self._event["text"]

@property
def args(self) -> List[JSHandle]:
return list(map(from_channel, self._initializer["args"]))
return list(map(from_channel, self._event["args"]))

@property
def location(self) -> SourceLocation:
return self._initializer["location"]
return self._event["location"]

@property
def page(self) -> Optional["Page"]:
Expand Down
10 changes: 0 additions & 10 deletions playwright/_impl/_js_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,6 @@ def parse_value(value: Any, refs: Optional[Dict[int, Any]] = None) -> Any:
if "bi" in value:
return int(value["bi"])

if "m" in value:
v = {}
refs[value["m"]["id"]] = v
return v

if "se" in value:
v = set()
refs[value["se"]["id"]] = v
return v

if "a" in value:
a: List = []
refs[value["id"]] = a
Expand Down
15 changes: 15 additions & 0 deletions playwright/_impl/_local_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def __init__(
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
) -> None:
super().__init__(parent, type, guid, initializer)
self.devices = {
device["name"]: parse_device_descriptor(device["descriptor"])
for device in initializer["deviceDescriptors"]
}

async def zip(self, params: Dict) -> None:
await self._channel.send("zip", params)
Expand Down Expand Up @@ -75,3 +79,14 @@ def add_stack_to_tracing_no_reply(self, id: int, frames: List[StackFrame]) -> No
}
},
)


def parse_device_descriptor(dict: Dict) -> Dict:
return {
"user_agent": dict["userAgent"],
"viewport": dict["viewport"],
"device_scale_factor": dict["deviceScaleFactor"],
"is_mobile": dict["isMobile"],
"has_touch": dict["hasTouch"],
"default_browser_type": dict["defaultBrowserType"],
}
3 changes: 0 additions & 3 deletions playwright/_impl/_object_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from playwright._impl._browser_type import BrowserType
from playwright._impl._cdp_session import CDPSession
from playwright._impl._connection import ChannelOwner
from playwright._impl._console_message import ConsoleMessage
from playwright._impl._dialog import Dialog
from playwright._impl._element_handle import ElementHandle
from playwright._impl._fetch import APIRequestContext
Expand Down Expand Up @@ -60,8 +59,6 @@ def create_remote_object(
return BrowserContext(parent, type, guid, initializer)
if type == "CDPSession":
return CDPSession(parent, type, guid, initializer)
if type == "ConsoleMessage":
return ConsoleMessage(parent, type, guid, initializer)
if type == "Dialog":
return Dialog(parent, type, guid, initializer)
if type == "ElementHandle":
Expand Down
19 changes: 1 addition & 18 deletions playwright/_impl/_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from playwright._impl._browser_type import BrowserType
from playwright._impl._connection import ChannelOwner, from_channel
from playwright._impl._fetch import APIRequest
from playwright._impl._local_utils import LocalUtils
from playwright._impl._selectors import Selectors, SelectorsOwner


Expand Down Expand Up @@ -48,12 +47,7 @@ def __init__(
self._connection.on(
"close", lambda: self.selectors._remove_channel(selectors_owner)
)
self.devices = {}
self.devices = {
device["name"]: parse_device_descriptor(device["descriptor"])
for device in initializer["deviceDescriptors"]
}
self._utils: LocalUtils = from_channel(initializer["utils"])
self.devices = self._connection.local_utils.devices

def __getitem__(self, value: str) -> "BrowserType":
if value == "chromium":
Expand All @@ -72,14 +66,3 @@ def _set_selectors(self, selectors: Selectors) -> None:

async def stop(self) -> None:
pass


def parse_device_descriptor(dict: Dict) -> Dict:
return {
"user_agent": dict["userAgent"],
"viewport": dict["viewport"],
"device_scale_factor": dict["deviceScaleFactor"],
"is_mobile": dict["isMobile"],
"has_touch": dict["hasTouch"],
"default_browser_type": dict["defaultBrowserType"],
}
Loading

0 comments on commit f4b4635

Please sign in to comment.