Skip to content

fix: setDefaultTimeout #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
24 changes: 12 additions & 12 deletions playwright/sync_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def isNavigationRequest(self) -> bool:
-------
bool
"""
return mapping.from_maybe_impl(self._sync(self._impl_obj.isNavigationRequest()))
return mapping.from_maybe_impl(self._impl_obj.isNavigationRequest())


mapping.register(RequestImpl, Request)
Expand Down Expand Up @@ -756,7 +756,7 @@ def asElement(self) -> typing.Union["ElementHandle", NoneType]:
-------
typing.Union[ElementHandle, NoneType]
"""
return mapping.from_impl_nullable(self._sync(self._impl_obj.asElement()))
return mapping.from_impl_nullable(self._impl_obj.asElement())

def dispose(self) -> NoneType:
"""JSHandle.dispose
Expand Down Expand Up @@ -797,7 +797,7 @@ def asElement(self) -> typing.Union["ElementHandle", NoneType]:
-------
typing.Union[ElementHandle, NoneType]
"""
return mapping.from_impl_nullable(self._sync(self._impl_obj.asElement()))
return mapping.from_impl_nullable(self._impl_obj.asElement())

def ownerFrame(self) -> typing.Union["Frame", NoneType]:
"""ElementHandle.ownerFrame
Expand Down Expand Up @@ -2062,7 +2062,7 @@ def isDetached(self) -> bool:
-------
bool
"""
return mapping.from_maybe_impl(self._sync(self._impl_obj.isDetached()))
return mapping.from_maybe_impl(self._impl_obj.isDetached())

def addScriptTag(
self, url: str = None, path: str = None, content: str = None, type: str = None
Expand Down Expand Up @@ -3155,7 +3155,7 @@ def frame(
frame matching the criteria. Returns `null` if no frame matches.
"""
return mapping.from_impl_nullable(
self._sync(self._impl_obj.frame(name=name, url=self._wrap_handler(url)))
self._impl_obj.frame(name=name, url=self._wrap_handler(url))
)

def setDefaultNavigationTimeout(self, timeout: int) -> NoneType:
Expand All @@ -3178,7 +3178,7 @@ def setDefaultNavigationTimeout(self, timeout: int) -> NoneType:
Maximum navigation time in milliseconds
"""
return mapping.from_maybe_impl(
self._sync(self._impl_obj.setDefaultNavigationTimeout(timeout=timeout))
self._impl_obj.setDefaultNavigationTimeout(timeout=timeout)
)

def setDefaultTimeout(self, timeout: int) -> NoneType:
Expand All @@ -3194,7 +3194,7 @@ def setDefaultTimeout(self, timeout: int) -> NoneType:
Maximum time in milliseconds
"""
return mapping.from_maybe_impl(
self._sync(self._impl_obj.setDefaultTimeout(timeout=timeout))
self._impl_obj.setDefaultTimeout(timeout=timeout)
)

def querySelector(self, selector: str) -> typing.Union["ElementHandle", NoneType]:
Expand Down Expand Up @@ -3974,7 +3974,7 @@ def viewportSize(self) -> typing.Union[Viewport, NoneType]:
-------
typing.Union[Viewport, NoneType]
"""
return mapping.from_maybe_impl(self._sync(self._impl_obj.viewportSize()))
return mapping.from_maybe_impl(self._impl_obj.viewportSize())

def bringToFront(self) -> NoneType:
"""Page.bringToFront
Expand Down Expand Up @@ -4149,7 +4149,7 @@ def isClosed(self) -> bool:
-------
bool
"""
return mapping.from_maybe_impl(self._sync(self._impl_obj.isClosed()))
return mapping.from_maybe_impl(self._impl_obj.isClosed())

def click(
self,
Expand Down Expand Up @@ -5003,7 +5003,7 @@ def setDefaultNavigationTimeout(self, timeout: int) -> NoneType:
Maximum navigation time in milliseconds
"""
return mapping.from_maybe_impl(
self._sync(self._impl_obj.setDefaultNavigationTimeout(timeout=timeout))
self._impl_obj.setDefaultNavigationTimeout(timeout=timeout)
)

def setDefaultTimeout(self, timeout: int) -> NoneType:
Expand All @@ -5019,7 +5019,7 @@ def setDefaultTimeout(self, timeout: int) -> NoneType:
Maximum time in milliseconds
"""
return mapping.from_maybe_impl(
self._sync(self._impl_obj.setDefaultTimeout(timeout=timeout))
self._impl_obj.setDefaultTimeout(timeout=timeout)
)

def newPage(self) -> "Page":
Expand Down Expand Up @@ -5374,7 +5374,7 @@ def isConnected(self) -> bool:
-------
bool
"""
return mapping.from_maybe_impl(self._sync(self._impl_obj.isConnected()))
return mapping.from_maybe_impl(self._impl_obj.isConnected())

def newContext(
self,
Expand Down
11 changes: 9 additions & 2 deletions scripts/generate_sync_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import inspect
import re
from types import FunctionType
from typing import Any, get_type_hints # type: ignore
Expand Down Expand Up @@ -87,8 +88,14 @@ def generate(t: Any) -> None:
[prefix, suffix] = return_value(
get_type_hints(value, api_globals)["return"]
)
prefix = " return " + prefix + f"self._sync(self._impl_obj.{name}("
suffix = "))" + suffix
if inspect.iscoroutinefunction(value):
prefix = (
" return " + prefix + f"self._sync(self._impl_obj.{name}("
)
suffix = "))" + suffix
else:
prefix = " return " + prefix + f"self._impl_obj.{name}("
suffix = ")" + suffix
print(f"{prefix}{arguments(value, len(prefix))}{suffix}")
if "expect_" in name:
print("")
Expand Down
9 changes: 8 additions & 1 deletion tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import pytest

from playwright import Error, sync_playwright
from playwright import Error, TimeoutError, sync_playwright
from playwright.sync_api import Browser, Page


Expand Down Expand Up @@ -214,3 +214,10 @@ def test_sync_playwright_multiple_times():
with sync_playwright() as pw2:
assert pw1.chromium == pw2.chromium
assert "Can only run one Playwright at a time." in exc.value.message


def test_sync_set_default_timeout(page):
page.setDefaultTimeout(1)
with pytest.raises(TimeoutError) as exc:
page.waitForFunction("false")
assert "Timeout 1ms exceeded." in exc.value.message