Skip to content
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ repos:
rev: v0.910
hooks:
- id: mypy
additional_dependencies: [types-pyOpenSSL==20.0.6]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
Expand Down
1 change: 1 addition & 0 deletions local-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ service_identity==21.1.0
setuptools==57.4.0
twine==3.4.2
twisted==21.7.0
types-pyOpenSSL==20.0.6
wheel==0.37.0
2 changes: 1 addition & 1 deletion playwright/_impl/_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def evaluate(
timeout,
)

async def evaluate_all(self, expression: str, arg: Serializable = None) -> None:
async def evaluate_all(self, expression: str, arg: Serializable = None) -> Any:
params = locals_to_params(locals())
return await self._frame.eval_on_selector_all(self._selector, **params)

Expand Down
6 changes: 5 additions & 1 deletion playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -11338,7 +11338,7 @@ async def evaluate(
)
)

async def evaluate_all(self, expression: str, arg: typing.Any = None) -> NoneType:
async def evaluate_all(self, expression: str, arg: typing.Any = None) -> typing.Any:
"""Locator.evaluate_all

The method finds all elements matching the specified locator and passes an array of matched elements as a first argument
Expand All @@ -11361,6 +11361,10 @@ async def evaluate_all(self, expression: str, arg: typing.Any = None) -> NoneTyp
as a function. Otherwise, evaluated as an expression.
arg : Union[Any, NoneType]
Optional argument to pass to `expression`.

Returns
-------
Any
"""

return mapping.from_maybe_impl(
Expand Down
6 changes: 5 additions & 1 deletion playwright/sync_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -11268,7 +11268,7 @@ def evaluate(
)
)

def evaluate_all(self, expression: str, arg: typing.Any = None) -> NoneType:
def evaluate_all(self, expression: str, arg: typing.Any = None) -> typing.Any:
"""Locator.evaluate_all

The method finds all elements matching the specified locator and passes an array of matched elements as a first argument
Expand All @@ -11291,6 +11291,10 @@ def evaluate_all(self, expression: str, arg: typing.Any = None) -> NoneType:
as a function. Otherwise, evaluated as an expression.
arg : Union[Any, NoneType]
Optional argument to pass to `expression`.

Returns
-------
Any
"""

return mapping.from_maybe_impl(
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ warn_redundant_casts = True
warn_unused_configs = True
check_untyped_defs = True
disallow_untyped_defs = True
[mypy-tests.*]
[mypy-tests/async.*]
ignore_errors = True
[flake8]
ignore =
Expand Down
3 changes: 2 additions & 1 deletion tests/async/test_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ async def test_bounding_box_with_SVG_nodes(page, server):
assert pw_bounding_box == web_bounding_box


@pytest.mark.skip_browser("firefox")
async def test_bounding_box_with_page_scale(browser, server):
context = await browser.new_context(
viewport={"width": 400, "height": 400, "is_mobile": True}
viewport={"width": 400, "height": 400}, is_mobile=True
)
page = await context.new_page()
await page.goto(server.PREFIX + "/input/button.html")
Expand Down
5 changes: 3 additions & 2 deletions tests/common/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
# limitations under the License.

import threading
from typing import Dict

from playwright.sync_api import sync_playwright


def test_running_in_thread(browser_name, launch_arguments):
def test_running_in_thread(browser_name: str, launch_arguments: Dict) -> None:
result = []

class TestThread(threading.Thread):
def run(self):
def run(self) -> None:
with sync_playwright() as playwright:
browser = getattr(playwright, browser_name).launch(**launch_arguments)
# This should not throw ^^.
Expand Down
60 changes: 32 additions & 28 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import subprocess
import sys
from pathlib import Path
from typing import Dict, List
from typing import Any, AsyncGenerator, Callable, Dict, Generator, List

import pytest
from PIL import Image
Expand All @@ -29,106 +29,108 @@
import playwright
from playwright._impl._path_utils import get_file_dirname

from .server import test_server
from .server import Server, WebSocketServerServer, test_server

_dirname = get_file_dirname()


def pytest_generate_tests(metafunc):
def pytest_generate_tests(metafunc: Any) -> None:
if "browser_name" in metafunc.fixturenames:
browsers = metafunc.config.option.browser or ["chromium", "firefox", "webkit"]
metafunc.parametrize("browser_name", browsers, scope="session")


@pytest.fixture(scope="session")
def event_loop():
def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
loop = asyncio.get_event_loop()
yield loop
loop.close()


@pytest.fixture(scope="session")
def assetdir():
def assetdir() -> Path:
return _dirname / "assets"


@pytest.fixture(scope="session")
def launch_arguments(pytestconfig):
def launch_arguments(pytestconfig: Any) -> Dict:
return {
"headless": not pytestconfig.getoption("--headful"),
"channel": pytestconfig.getoption("--browser-channel"),
}


@pytest.fixture
def server():
def server() -> Generator[Server, None, None]:
yield test_server.server


@pytest.fixture
def https_server():
def https_server() -> Generator[Server, None, None]:
yield test_server.https_server


@pytest.fixture
def ws_server():
def ws_server() -> Generator[WebSocketServerServer, None, None]:
yield test_server.ws_server


@pytest.fixture(autouse=True, scope="session")
async def start_server():
async def start_server() -> AsyncGenerator[None, None]:
test_server.start()
yield
test_server.stop()


@pytest.fixture(autouse=True)
def after_each_hook():
def after_each_hook() -> Generator[None, None, None]:
yield
test_server.reset()


@pytest.fixture(scope="session")
def browser_name(pytestconfig):
def browser_name(pytestconfig: Any) -> None:
return pytestconfig.getoption("browser")


@pytest.fixture(scope="session")
def browser_channel(pytestconfig):
def browser_channel(pytestconfig: Any) -> None:
return pytestconfig.getoption("--browser-channel")


@pytest.fixture(scope="session")
def is_webkit(browser_name):
def is_webkit(browser_name: str) -> bool:
return browser_name == "webkit"


@pytest.fixture(scope="session")
def is_firefox(browser_name):
def is_firefox(browser_name: str) -> bool:
return browser_name == "firefox"


@pytest.fixture(scope="session")
def is_chromium(browser_name):
def is_chromium(browser_name: str) -> bool:
return browser_name == "chromium"


@pytest.fixture(scope="session")
def is_win():
def is_win() -> bool:
return sys.platform == "win32"


@pytest.fixture(scope="session")
def is_linux():
def is_linux() -> bool:
return sys.platform == "linux"


@pytest.fixture(scope="session")
def is_mac():
def is_mac() -> bool:
return sys.platform == "darwin"


def _get_skiplist(request, values, value_name):
def _get_skiplist(
request: pytest.FixtureRequest, values: List[str], value_name: str
) -> List[str]:
skipped_values = []
# Allowlist
only_marker = request.node.get_closest_marker(f"only_{value_name}")
Expand All @@ -145,7 +147,7 @@ def _get_skiplist(request, values, value_name):


@pytest.fixture(autouse=True)
def skip_by_browser(request, browser_name):
def skip_by_browser(request: pytest.FixtureRequest, browser_name: str) -> None:
skip_browsers_names = _get_skiplist(
request, ["chromium", "firefox", "webkit"], "browser"
)
Expand All @@ -155,7 +157,7 @@ def skip_by_browser(request, browser_name):


@pytest.fixture(autouse=True)
def skip_by_platform(request):
def skip_by_platform(request: pytest.FixtureRequest) -> None:
skip_platform_names = _get_skiplist(
request, ["win32", "linux", "darwin"], "platform"
)
Expand All @@ -164,7 +166,7 @@ def skip_by_platform(request):
pytest.skip(f"skipped on this platform: {sys.platform}")


def pytest_addoption(parser):
def pytest_addoption(parser: Any) -> None:
group = parser.getgroup("playwright", "Playwright")
group.addoption(
"--browser",
Expand All @@ -187,8 +189,8 @@ def pytest_addoption(parser):


@pytest.fixture(scope="session")
def assert_to_be_golden(browser_name: str):
def compare(received_raw: bytes, golden_name: str):
def assert_to_be_golden(browser_name: str) -> Callable[[bytes, str], None]:
def compare(received_raw: bytes, golden_name: str) -> None:
golden_file = (_dirname / f"golden-{browser_name}" / golden_name).read_bytes()
received_image = Image.open(io.BytesIO(received_raw))
golden_image = Image.open(io.BytesIO(golden_file))
Expand Down Expand Up @@ -235,7 +237,7 @@ def __init__(
self.ws_endpoint = self.process.stdout.readline().decode().strip()
self.process.stdout.close()

def kill(self):
def kill(self) -> None:
# Send the signal to all the process groups
if self.process.poll() is not None:
return
Expand All @@ -244,10 +246,12 @@ def kill(self):


@pytest.fixture
def launch_server(browser_name: str, launch_arguments: Dict, tmp_path: Path):
def launch_server(
browser_name: str, launch_arguments: Dict, tmp_path: Path
) -> Generator[Callable[..., RemoteServer], None, None]:
remotes: List[RemoteServer] = []

def _launch_server(**kwargs: Dict):
def _launch_server(**kwargs: Dict[str, Any]) -> RemoteServer:
remote = RemoteServer(
browser_name,
{
Expand Down
Loading