Skip to content

Commit 8c937ba

Browse files
authored
fix: setDefaultTimeout (#120)
1 parent 875b380 commit 8c937ba

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

playwright/sync_api.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def isNavigationRequest(self) -> bool:
191191
-------
192192
bool
193193
"""
194-
return mapping.from_maybe_impl(self._sync(self._impl_obj.isNavigationRequest()))
194+
return mapping.from_maybe_impl(self._impl_obj.isNavigationRequest())
195195

196196

197197
mapping.register(RequestImpl, Request)
@@ -756,7 +756,7 @@ def asElement(self) -> typing.Union["ElementHandle", NoneType]:
756756
-------
757757
typing.Union[ElementHandle, NoneType]
758758
"""
759-
return mapping.from_impl_nullable(self._sync(self._impl_obj.asElement()))
759+
return mapping.from_impl_nullable(self._impl_obj.asElement())
760760

761761
def dispose(self) -> NoneType:
762762
"""JSHandle.dispose
@@ -797,7 +797,7 @@ def asElement(self) -> typing.Union["ElementHandle", NoneType]:
797797
-------
798798
typing.Union[ElementHandle, NoneType]
799799
"""
800-
return mapping.from_impl_nullable(self._sync(self._impl_obj.asElement()))
800+
return mapping.from_impl_nullable(self._impl_obj.asElement())
801801

802802
def ownerFrame(self) -> typing.Union["Frame", NoneType]:
803803
"""ElementHandle.ownerFrame
@@ -2062,7 +2062,7 @@ def isDetached(self) -> bool:
20622062
-------
20632063
bool
20642064
"""
2065-
return mapping.from_maybe_impl(self._sync(self._impl_obj.isDetached()))
2065+
return mapping.from_maybe_impl(self._impl_obj.isDetached())
20662066

20672067
def addScriptTag(
20682068
self, url: str = None, path: str = None, content: str = None, type: str = None
@@ -3155,7 +3155,7 @@ def frame(
31553155
frame matching the criteria. Returns `null` if no frame matches.
31563156
"""
31573157
return mapping.from_impl_nullable(
3158-
self._sync(self._impl_obj.frame(name=name, url=self._wrap_handler(url)))
3158+
self._impl_obj.frame(name=name, url=self._wrap_handler(url))
31593159
)
31603160

31613161
def setDefaultNavigationTimeout(self, timeout: int) -> NoneType:
@@ -3178,7 +3178,7 @@ def setDefaultNavigationTimeout(self, timeout: int) -> NoneType:
31783178
Maximum navigation time in milliseconds
31793179
"""
31803180
return mapping.from_maybe_impl(
3181-
self._sync(self._impl_obj.setDefaultNavigationTimeout(timeout=timeout))
3181+
self._impl_obj.setDefaultNavigationTimeout(timeout=timeout)
31823182
)
31833183

31843184
def setDefaultTimeout(self, timeout: int) -> NoneType:
@@ -3194,7 +3194,7 @@ def setDefaultTimeout(self, timeout: int) -> NoneType:
31943194
Maximum time in milliseconds
31953195
"""
31963196
return mapping.from_maybe_impl(
3197-
self._sync(self._impl_obj.setDefaultTimeout(timeout=timeout))
3197+
self._impl_obj.setDefaultTimeout(timeout=timeout)
31983198
)
31993199

32003200
def querySelector(self, selector: str) -> typing.Union["ElementHandle", NoneType]:
@@ -3974,7 +3974,7 @@ def viewportSize(self) -> typing.Union[Viewport, NoneType]:
39743974
-------
39753975
typing.Union[Viewport, NoneType]
39763976
"""
3977-
return mapping.from_maybe_impl(self._sync(self._impl_obj.viewportSize()))
3977+
return mapping.from_maybe_impl(self._impl_obj.viewportSize())
39783978

39793979
def bringToFront(self) -> NoneType:
39803980
"""Page.bringToFront
@@ -4149,7 +4149,7 @@ def isClosed(self) -> bool:
41494149
-------
41504150
bool
41514151
"""
4152-
return mapping.from_maybe_impl(self._sync(self._impl_obj.isClosed()))
4152+
return mapping.from_maybe_impl(self._impl_obj.isClosed())
41534153

41544154
def click(
41554155
self,
@@ -5003,7 +5003,7 @@ def setDefaultNavigationTimeout(self, timeout: int) -> NoneType:
50035003
Maximum navigation time in milliseconds
50045004
"""
50055005
return mapping.from_maybe_impl(
5006-
self._sync(self._impl_obj.setDefaultNavigationTimeout(timeout=timeout))
5006+
self._impl_obj.setDefaultNavigationTimeout(timeout=timeout)
50075007
)
50085008

50095009
def setDefaultTimeout(self, timeout: int) -> NoneType:
@@ -5019,7 +5019,7 @@ def setDefaultTimeout(self, timeout: int) -> NoneType:
50195019
Maximum time in milliseconds
50205020
"""
50215021
return mapping.from_maybe_impl(
5022-
self._sync(self._impl_obj.setDefaultTimeout(timeout=timeout))
5022+
self._impl_obj.setDefaultTimeout(timeout=timeout)
50235023
)
50245024

50255025
def newPage(self) -> "Page":
@@ -5374,7 +5374,7 @@ def isConnected(self) -> bool:
53745374
-------
53755375
bool
53765376
"""
5377-
return mapping.from_maybe_impl(self._sync(self._impl_obj.isConnected()))
5377+
return mapping.from_maybe_impl(self._impl_obj.isConnected())
53785378

53795379
def newContext(
53805380
self,

scripts/generate_sync_api.py

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

15+
import inspect
1516
import re
1617
from types import FunctionType
1718
from typing import Any, get_type_hints # type: ignore
@@ -87,8 +88,14 @@ def generate(t: Any) -> None:
8788
[prefix, suffix] = return_value(
8889
get_type_hints(value, api_globals)["return"]
8990
)
90-
prefix = " return " + prefix + f"self._sync(self._impl_obj.{name}("
91-
suffix = "))" + suffix
91+
if inspect.iscoroutinefunction(value):
92+
prefix = (
93+
" return " + prefix + f"self._sync(self._impl_obj.{name}("
94+
)
95+
suffix = "))" + suffix
96+
else:
97+
prefix = " return " + prefix + f"self._impl_obj.{name}("
98+
suffix = ")" + suffix
9299
print(f"{prefix}{arguments(value, len(prefix))}{suffix}")
93100
if "expect_" in name:
94101
print("")

tests/test_sync.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import pytest
1818

19-
from playwright import Error, sync_playwright
19+
from playwright import Error, TimeoutError, sync_playwright
2020
from playwright.sync_api import Browser, Page
2121

2222

@@ -214,3 +214,10 @@ def test_sync_playwright_multiple_times():
214214
with sync_playwright() as pw2:
215215
assert pw1.chromium == pw2.chromium
216216
assert "Can only run one Playwright at a time." in exc.value.message
217+
218+
219+
def test_sync_set_default_timeout(page):
220+
page.setDefaultTimeout(1)
221+
with pytest.raises(TimeoutError) as exc:
222+
page.waitForFunction("false")
223+
assert "Timeout 1ms exceeded." in exc.value.message

0 commit comments

Comments
 (0)