Skip to content

Commit 4a0d3f4

Browse files
committed
test: add browser.bind/unbind tests and fix Bind return type
1 parent 922cdc1 commit 4a0d3f4

6 files changed

Lines changed: 41 additions & 9 deletions

File tree

playwright/_impl/_api_structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class TracingGroupLocation(TypedDict, total=False):
313313
column: Optional[int]
314314

315315

316-
class BindResult(TypedDict):
316+
class Bind(TypedDict):
317317
endpoint: str
318318

319319

playwright/_impl/_browser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
)
2828

2929
from playwright._impl._api_structures import (
30-
BindResult,
30+
Bind,
3131
ClientCertificate,
3232
Geolocation,
3333
HttpCredentials,
@@ -247,9 +247,10 @@ async def bind(
247247
workspaceDir: str = None,
248248
host: str = None,
249249
port: int = None,
250-
) -> BindResult:
250+
) -> Bind:
251251
params = locals_to_params(locals())
252-
return await self._channel.send("startServer", None, params)
252+
result = await self._channel.send("startServer", None, params)
253+
return Bind(endpoint=result)
253254

254255
async def unbind(self) -> None:
255256
await self._channel.send("stopServer", None)

playwright/async_api/_generated.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from typing import Literal
2020

2121
from playwright._impl._api_structures import (
22-
BindResult,
22+
Bind,
2323
ClientCertificate,
2424
Cookie,
2525
FilePayload,
@@ -14709,7 +14709,7 @@ async def bind(
1470914709
workspace_dir: typing.Optional[str] = None,
1471014710
host: typing.Optional[str] = None,
1471114711
port: typing.Optional[int] = None,
14712-
) -> BindResult:
14712+
) -> Bind:
1471314713
"""Browser.bind
1471414714

1471514715
Binds the browser to a named pipe or web socket, making it available for other clients to connect to.

playwright/sync_api/_generated.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from typing import Literal
2020

2121
from playwright._impl._api_structures import (
22-
BindResult,
22+
Bind,
2323
ClientCertificate,
2424
Cookie,
2525
FilePayload,
@@ -14660,7 +14660,7 @@ def bind(
1466014660
workspace_dir: typing.Optional[str] = None,
1466114661
host: typing.Optional[str] = None,
1466214662
port: typing.Optional[int] = None,
14663-
) -> BindResult:
14663+
) -> Bind:
1466414664
"""Browser.bind
1466514665

1466614666
Binds the browser to a named pipe or web socket, making it available for other clients to connect to.

scripts/generate_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def return_value(value: Any) -> List[str]:
227227
from typing import Literal
228228
229229
230-
from playwright._impl._api_structures import Cookie, SetCookieParam, FloatRect, FilePayload, Geolocation, HttpCredentials, PdfMargins, Position, ProxySettings, ResourceTiming, SourceLocation, StorageState, ClientCertificate, ViewportSize, RemoteAddr, SecurityDetails, RequestSizes, NameValue, TracingGroupLocation, PausedDetails, PausedDetailsLocation, OnFrame, BindResult
230+
from playwright._impl._api_structures import Cookie, SetCookieParam, FloatRect, FilePayload, Geolocation, HttpCredentials, PdfMargins, Position, ProxySettings, ResourceTiming, SourceLocation, StorageState, ClientCertificate, ViewportSize, RemoteAddr, SecurityDetails, RequestSizes, NameValue, TracingGroupLocation, PausedDetails, PausedDetailsLocation, OnFrame, Bind
231231
from playwright._impl._browser import Browser as BrowserImpl
232232
from playwright._impl._browser_context import BrowserContext as BrowserContextImpl
233233
from playwright._impl._browser_type import BrowserType as BrowserTypeImpl

tests/async/test_browser_bind.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 playwright.async_api import Browser
16+
17+
18+
async def test_should_bind_and_unbind_browser(browser: Browser) -> None:
19+
server_info = await browser.bind("default")
20+
try:
21+
assert isinstance(server_info["endpoint"], str)
22+
finally:
23+
await browser.unbind()
24+
25+
26+
async def test_should_bind_with_custom_host_and_port(browser: Browser) -> None:
27+
server_info = await browser.bind("my-title", host="127.0.0.1", port=0)
28+
try:
29+
assert isinstance(server_info["endpoint"], str)
30+
finally:
31+
await browser.unbind()

0 commit comments

Comments
 (0)