Skip to content

Commit 767d41b

Browse files
authored
feat(roll): roll Playwright to 1.2.0-next.1595486491367 (#83)
1 parent 6e1a593 commit 767d41b

17 files changed

+217
-133
lines changed

driver/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"license": "Apache-2.0",
1515
"dependencies": {
16-
"playwright": "1.2.0-next.1595094993390"
16+
"playwright": "1.2.0-next.1595486491367"
1717
},
1818
"devDependencies": {
1919
"pkg": "^4.4.9"

playwright/accessibility.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,62 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, Dict
15+
from typing import Any, Dict, Optional
1616

1717
from playwright.connection import Channel
1818
from playwright.element_handle import ElementHandle
1919

2020

21+
def _ax_node_from_protocol(axNode: Dict[str, Any]) -> Dict[str, Any]:
22+
result = {**axNode}
23+
if "valueNumber" in axNode:
24+
result["value"] = axNode["valueNumber"]
25+
elif "valueString" in axNode:
26+
result["value"] = axNode["valueString"]
27+
28+
if "checked" in axNode:
29+
result["checked"] = (
30+
True
31+
if axNode.get("checked") == "checked"
32+
else (
33+
False if axNode.get("checked") == "unchecked" else axNode.get("checked")
34+
)
35+
)
36+
37+
if "pressed" in axNode:
38+
result["pressed"] = (
39+
True
40+
if axNode.get("pressed") == "pressed"
41+
else (
42+
False if axNode.get("pressed") == "released" else axNode.get("pressed")
43+
)
44+
)
45+
46+
if axNode.get("children"):
47+
result["children"] = list(map(_ax_node_from_protocol, axNode["children"]))
48+
if "valueNumber" in result:
49+
del result["valueNumber"]
50+
if "valueString" in result:
51+
del result["valueString"]
52+
return result
53+
54+
2155
class Accessibility:
2256
def __init__(self, channel: Channel) -> None:
2357
self._channel = channel
2458
self._sync_owner: Any = None
2559

2660
async def snapshot(
2761
self, interestingOnly: bool = True, root: ElementHandle = None
28-
) -> Dict:
62+
) -> Optional[Dict[str, Any]]:
2963
root = root._channel if root else None
30-
return await self._channel.send(
31-
"accessibilitySnapshot", dict(root=root, interestingOnly=interestingOnly)
64+
result = await self._channel.send(
65+
"accessibilitySnapshot",
66+
dict(root=root, interestingOnly=interestingOnly),
67+
unpack_first_key=False,
68+
)
69+
return (
70+
_ax_node_from_protocol(result["rootAXNode"])
71+
if result.get("rootAXNode")
72+
else None
3273
)

playwright/browser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ async def newContext(
7676
params = locals_to_params(locals())
7777
if viewport == 0:
7878
params["viewport"] = None
79+
params["noDefaultViewport"] = True
7980
if extraHTTPHeaders:
8081
params["extraHTTPHeaders"] = serialize_headers(extraHTTPHeaders)
8182
channel = await self._channel.send("newContext", params)

playwright/connection.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ def __init__(self, scope: "ConnectionScope", guid: str) -> None:
3030
self._guid = guid
3131
self._object: Optional[ChannelOwner] = None
3232

33-
async def send(self, method: str, params: dict = None) -> Any:
33+
async def send(
34+
self, method: str, params: dict = None, unpack_first_key: bool = True
35+
) -> Any:
3436
if params is None:
3537
params = dict()
3638
result = await self._scope.send_message_to_server(self._guid, method, params)
3739
# Protocol now has named return values, assume result is one level deeper unless
3840
# there is explicit ambiguity.
39-
if isinstance(result, dict) and len(result) == 1:
41+
if unpack_first_key and isinstance(result, dict) and len(result) == 1:
4042
key = next(iter(result))
4143
return result[key]
4244
return result
@@ -174,7 +176,7 @@ def _dispatch(self, msg: ParsedMessagePayload) -> None:
174176
callback = self._callbacks.pop(id)
175177
error = msg.get("error")
176178
if error:
177-
parsed_error = parse_error(error)
179+
parsed_error = parse_error(error["error"]) # type: ignore
178180
parsed_error.stack = callback.stack_trace
179181
callback.future.set_exception(parsed_error)
180182
else:

playwright/drivers/browsers.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"browsers": [
44
{
55
"name": "chromium",
6-
"revision": "786218"
6+
"revision": "790602"
77
},
88
{
99
"name": "firefox",
10-
"revision": "1128"
10+
"revision": "1137"
1111
},
1212
{
1313
"name": "webkit",

playwright/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
class Frame(ChannelOwner):
5959
def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None:
6060
super().__init__(scope, guid, initializer)
61-
self._parent_frame = from_nullable_channel(initializer["parentFrame"])
61+
self._parent_frame = from_nullable_channel(initializer.get("parentFrame"))
6262
if self._parent_frame:
6363
self._parent_frame._child_frames.append(self)
6464
self._name = initializer["name"]

playwright/js_handle.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,6 @@ async def jsonValue(self) -> Any:
8888
return parse_result(await self._channel.send("jsonValue"))
8989

9090

91-
def is_primitive_value(value: Any) -> bool:
92-
return (
93-
isinstance(value, bool)
94-
or isinstance(value, int)
95-
or isinstance(value, float)
96-
or isinstance(value, str)
97-
)
98-
99-
10091
def serialize_value(value: Any, handles: List[JSHandle], depth: int) -> Any:
10192
if isinstance(value, JSHandle):
10293
h = len(handles)
@@ -119,17 +110,25 @@ def serialize_value(value: Any, handles: List[JSHandle], depth: int) -> Any:
119110
return dict(v="NaN")
120111
if isinstance(value, datetime):
121112
return dict(d=value.isoformat() + "Z")
122-
if is_primitive_value(value):
123-
return value
113+
if isinstance(value, bool):
114+
return {"b": value}
115+
if isinstance(value, int):
116+
return {"n": value}
117+
if isinstance(value, float):
118+
return {"f": value}
119+
if isinstance(value, str):
120+
return {"s": value}
124121

125122
if isinstance(value, list):
126123
result = list(map(lambda a: serialize_value(a, handles, depth + 1), value))
127124
return dict(a=result)
128125

129126
if isinstance(value, dict):
130-
result: Dict[str, Any] = dict() # type: ignore
127+
result = [] # type: ignore
131128
for name in value:
132-
result[name] = serialize_value(value[name], handles, depth + 1)
129+
result.append(
130+
{"k": name, "v": serialize_value(value[name], handles, depth + 1)}
131+
)
133132
return dict(o=result)
134133
return dict(v="undefined")
135134

@@ -168,10 +167,16 @@ def parse_value(value: Any) -> Any:
168167

169168
if "o" in value:
170169
o = value["o"]
171-
result = dict()
172-
for name in o:
173-
result[name] = parse_value(o[name])
174-
return result
170+
return {e["k"]: parse_value(e["v"]) for e in o}
171+
172+
if "n" in value:
173+
return value["n"]
174+
175+
if "s" in value:
176+
return value["s"]
177+
178+
if "b" in value:
179+
return value["b"]
175180
return value
176181

177182

playwright/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def async_init() -> None:
6666
connection = Connection(
6767
proc.stdout, proc.stdin, create_remote_object, asyncio.get_event_loop()
6868
)
69-
playwright_async = await connection.wait_for_object_with_known_name("playwright")
69+
playwright_async = await connection.wait_for_object_with_known_name("Playwright")
7070

7171

7272
if sys.platform == "win32":

playwright/network.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Request(ChannelOwner):
3232
def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None:
3333
super().__init__(scope, guid, initializer)
3434
self._redirected_from: Optional["Request"] = from_nullable_channel(
35-
initializer["redirectedFrom"]
35+
initializer.get("redirectedFrom")
3636
)
3737
self._redirected_to: Optional["Request"] = None
3838
if self._redirected_from:
@@ -53,7 +53,10 @@ def method(self) -> str:
5353

5454
@property
5555
def postData(self) -> Optional[str]:
56-
return self._initializer["postData"]
56+
b64_content = self._initializer.get("postData")
57+
if not b64_content:
58+
return None
59+
return base64.b64decode(bytes(b64_content, "utf-8")).decode()
5760

5861
@property
5962
def headers(self) -> Dict[str, str]:

playwright/object_factory.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,40 @@ def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None
4040
def create_remote_object(
4141
scope: ConnectionScope, type: str, guid: str, initializer: Dict
4242
) -> Any:
43-
if type == "bindingCall":
43+
if type == "BindingCall":
4444
return BindingCall(scope, guid, initializer)
45-
if type == "browser":
45+
if type == "Browser":
4646
return Browser(scope, guid, initializer)
47-
if type == "browserServer":
47+
if type == "BrowserServer":
4848
return BrowserServer(scope, guid, initializer)
49-
if type == "browserType":
49+
if type == "BrowserType":
5050
return BrowserType(scope, guid, initializer)
51-
if type == "context":
51+
if type == "BrowserContext":
5252
return BrowserContext(scope, guid, initializer)
53-
if type == "consoleMessage":
53+
if type == "ConsoleMessage":
5454
return ConsoleMessage(scope, guid, initializer)
55-
if type == "dialog":
55+
if type == "Dialog":
5656
return Dialog(scope, guid, initializer)
57-
if type == "download":
57+
if type == "Download":
5858
return Download(scope, guid, initializer)
59-
if type == "elementHandle":
59+
if type == "ElementHandle":
6060
return ElementHandle(scope, guid, initializer)
61-
if type == "frame":
61+
if type == "Frame":
6262
return Frame(scope, guid, initializer)
63-
if type == "jsHandle":
63+
if type == "JSHandle":
6464
return JSHandle(scope, guid, initializer)
65-
if type == "page":
65+
if type == "Page":
6666
return Page(scope, guid, initializer)
67-
if type == "playwright":
67+
if type == "Playwright":
6868
return Playwright(scope, guid, initializer)
69-
if type == "request":
69+
if type == "Request":
7070
return Request(scope, guid, initializer)
71-
if type == "response":
71+
if type == "Response":
7272
return Response(scope, guid, initializer)
73-
if type == "route":
73+
if type == "Route":
7474
return Route(scope, guid, initializer)
75-
if type == "worker":
75+
if type == "Worker":
7676
return Worker(scope, guid, initializer)
77-
if type == "selectors":
77+
if type == "Selectors":
7878
return Selectors(scope, guid, initializer)
7979
return DummyObject(scope, guid, initializer)

0 commit comments

Comments
 (0)