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
2 changes: 1 addition & 1 deletion DRIVER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b0e0b7b555e637cc8c0ce94dd98c3be153861333
a804c193562095b0da20e5d4679fa87e4c8e5563
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->159.0.8154.13<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->159.0.8154.33<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->27.2<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->159.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->160.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |

## Documentation

Expand Down
6 changes: 3 additions & 3 deletions playwright/_impl/browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ async def _browser_from_connect_result(
browser = Browser.from_(result["browser"])
browser._connect_to_browser_type(self, {}, None)
if result["defaultContext"]:
await self._instrumentation.run_after_create_browser_context(
BrowserContext.from_(result["defaultContext"])
)
context = BrowserContext.from_(result["defaultContext"])
await self._playwright.selectors._register_on_context(context)
await self._instrumentation.run_after_create_browser_context(context)
return browser

# Python only: the members of the Python API that upstream does not have.
Expand Down
10 changes: 10 additions & 0 deletions playwright/_impl/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ async def register(
)
self._selector_engines.append(selector_engine)

async def _register_on_context(self, context: "BrowserContext") -> None:
for selector_engine in self._selector_engines:
await context._channel.registerSelectorEngine(
selectorEngine=selector_engine, timeout=NO_TIMEOUT
)
if self._test_id_attribute_name is not None:
await context._channel.setTestIdAttributeName(
testIdAttributeName=self._test_id_attribute_name, timeout=NO_TIMEOUT
)

def set_test_id_attribute(self, attribute_name: str) -> None:
self._test_id_attribute_name = attribute_name
set_test_id_attribute(attribute_name)
Expand Down
4 changes: 2 additions & 2 deletions playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,7 @@ async def clear_permissions(self) -> None:
context = await browser.new_context()
await context.grant_permissions([\"clipboard-read\"])
# do stuff ..
context.clear_permissions()
await context.clear_permissions()
```
"""

Expand Down Expand Up @@ -11511,7 +11511,7 @@ async def evaluate(
Passing argument to `expression`:

```py
result = await page.get_by_testid(\"myId\").evaluate(\"(element, [x, y]) => element.textContent + ' ' + x * y\", [7, 8])
result = await page.get_by_test_id(\"myId\").evaluate(\"(element, [x, y]) => element.textContent + ' ' + x * y\", [7, 8])
print(result) # prints \"myId text 56\"
```

Expand Down
6 changes: 2 additions & 4 deletions playwright/sync_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -3214,8 +3214,6 @@ def route(
context = browser.new_context()
page = context.new_page()
context.route(re.compile(r\"(\\.png$)|(\\.jpg$)\"), lambda route: route.abort())
page = await context.new_page()
page = context.new_page()
page.goto(\"https://example.com\")
browser.close()
```
Expand Down Expand Up @@ -11530,7 +11528,7 @@ def evaluate(
Passing argument to `expression`:

```py
result = page.get_by_testid(\"myId\").evaluate(\"(element, [x, y]) => element.textContent + ' ' + x * y\", [7, 8])
result = page.get_by_test_id(\"myId\").evaluate(\"(element, [x, y]) => element.textContent + ' ' + x * y\", [7, 8])
print(result) # prints \"myId text 56\"
```

Expand Down Expand Up @@ -14930,7 +14928,7 @@ def to_contain_class(
from playwright.sync_api import expect

locator = page.locator(\".list > .component\")
await expect(locator).to_contain_class([\"inactive\", \"active\", \"inactive\"])
expect(locator).to_contain_class([\"inactive\", \"active\", \"inactive\"])
```

Parameters
Expand Down
49 changes: 49 additions & 0 deletions tests/async/library/chromium/test_connect_over_cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,55 @@ async def test_CD_019_should_return_valid_browser_from_context_browser(
await browser_server.close()


async def test_CD_055_should_work_with_registered_selector_engines(
playwright: Playwright,
browser_type: BrowserType,
launch_arguments: Dict,
port: int,
) -> None:
browser_server = await launch(browser_type, launch_arguments, port)
try:
# Python: invoke the engine factory, as the JS function argument does.
await playwright.selectors.register(
"cdpTag",
"""(() => ({
query: (root, selector) => root.querySelector(selector),
queryAll: (root, selector) => Array.from(root.querySelectorAll(selector)),
}))()""",
)
cdp_browser = await browser_type.connect_over_cdp(f"http://127.0.0.1:{port}/")
page = await cdp_browser.contexts[0].new_page()
await page.set_content("<div>hello</div>")
assert await page.locator("cdpTag=div").text_content() == "hello"
await cdp_browser.close()
finally:
await browser_server.close()


async def test_CD_056_should_respect_the_test_id_attribute_in_strict_mode_errors(
playwright: Playwright,
browser_type: BrowserType,
launch_arguments: Dict,
port: int,
) -> None:
browser_server = await launch(browser_type, launch_arguments, port)
try:
playwright.selectors.set_test_id_attribute("data-foo")
cdp_browser = await browser_type.connect_over_cdp(f"http://127.0.0.1:{port}/")
page = await cdp_browser.contexts[0].new_page()
await page.set_content(
'<button data-foo="a">x</button><button data-foo="b">x</button>'
)
with pytest.raises(Error) as exc_info:
await page.locator("button").click()
# Python: strict mode errors name the Python locator API.
assert 'aka get_by_test_id("a")' in exc_info.value.message
await cdp_browser.close()
finally:
playwright.selectors.set_test_id_attribute("data-testid")
await browser_server.close()


async def test_CD_020_should_report_an_expected_error_when_the_endpoint_url_returns_a_non_expected_status_code(
browser_type: BrowserType, server: Server
) -> None:
Expand Down
39 changes: 32 additions & 7 deletions tests/async/library/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,39 @@
import re
import time
from pathlib import Path
from typing import Awaitable, Callable, Optional
from typing import AsyncGenerator, Awaitable, Callable, Dict, Optional

import pytest

from playwright.async_api import BrowserContext, Error, Page, Route, expect
from playwright.async_api import (
Browser,
BrowserContext,
BrowserType,
Error,
Page,
Route,
expect,
)
from tests.server import Server, TestServerRequest


@pytest.fixture(scope="module")
async def browser(
browser_type: BrowserType, browser_name: str, launch_arguments: Dict
) -> AsyncGenerator[Browser, None]:
# Python: the module's browser uses the upstream launchOptions fixture.
options = dict(launch_arguments)
if browser_name == "firefox":
options["firefox_user_prefs"] = {
**options.get("firefox_user_prefs", {}),
# Test DOM fullscreen without requiring a window manager under Xvfb.
"full-screen-api.ignore-widgets": True,
}
browser = await browser_type.launch(**options)
yield browser
await browser.close()


async def test_CA_001_shared_array_buffer_should_work_smoke(
context_factory: Callable[..., Awaitable[BrowserContext]], https_server: Server
) -> None:
Expand Down Expand Up @@ -330,12 +355,8 @@ async def test_CA_019_window_gesture_event_in_web_kit(


async def test_CA_020_request_fullscreen(
page: Page, server: Server, browser_name: str, headless: bool
page: Page, server: Server, browser_name: str, platform: str
) -> None:
if browser_name == "firefox" and not headless:
pytest.skip(
"fixme: Error: Request for fullscreen was denied because requesting element is not in the currently focused tab"
)
await page.goto(server.EMPTY_PAGE)
await page.evaluate(
"""() => {
Expand All @@ -356,6 +377,10 @@ async def test_CA_020_request_fullscreen(
)
assert not await page.evaluate("() => !!document.fullscreenElement")

if browser_name == "webkit" and platform != "linux":
pytest.skip(
"fixme: requestFullscreen() in a popup rejects with InvalidStateError on Windows and hangs the context teardown on macOS"
)
async with page.expect_popup() as popup_info:
await page.evaluate(
"url => window.open(url, 'popup', 'popup')", server.EMPTY_PAGE
Expand Down
21 changes: 21 additions & 0 deletions tests/async/page/test_page_screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def skip_firefox_headed(browser_name: str, headless: bool) -> None:
pytest.skip("Firefox headed produces a different image.")


@pytest.fixture
def skip_firefox_headed_animations(browser_name: str, headless: bool) -> None:
if browser_name == "firefox" and not headless:
pytest.skip(
"Firefox headed produces a different image: https://github.com/microsoft/playwright-browsers/issues/2714"
)


CARET_CONTENT = """
<!-- Refer to stylesheet from other origin. Accessing this
stylesheet rules will throw.
Expand Down Expand Up @@ -955,6 +963,7 @@ async def test_SS_051_page_screenshot_mask_option_should_remove_elements_based_o
assert display == ""


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_098_page_screenshot_animations_should_preserve_scroll_animation_progress_during_screenshots(
page: Page, utils: Utils
) -> None:
Expand All @@ -979,6 +988,7 @@ async def test_SS_098_page_screenshot_animations_should_preserve_scroll_animatio
assert await page.screenshot(animations="allow") == expected


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_052_page_screenshot_animations_should_not_capture_infinite_css_animation(
page: Page, server: Server, utils: Utils
) -> None:
Expand All @@ -991,6 +1001,7 @@ async def test_SS_052_page_screenshot_animations_should_not_capture_infinite_css
assert new_screenshot == screenshot


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_053_page_screenshot_animations_should_not_capture_pseudo_element_css_animation(
page: Page, server: Server, utils: Utils
) -> None:
Expand All @@ -1003,6 +1014,7 @@ async def test_SS_053_page_screenshot_animations_should_not_capture_pseudo_eleme
assert new_screenshot == screenshot


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_054_page_screenshot_animations_should_not_capture_css_animations_in_shadow_dom(
page: Page, server: Server, utils: Utils
) -> None:
Expand All @@ -1014,6 +1026,7 @@ async def test_SS_054_page_screenshot_animations_should_not_capture_css_animatio
assert new_screenshot == screenshot


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_056_page_screenshot_animations_should_resume_infinite_animations(
page: Page, server: Server, utils: Utils
) -> None:
Expand All @@ -1025,6 +1038,7 @@ async def test_SS_056_page_screenshot_animations_should_resume_infinite_animatio
assert compare_images(buffer1, buffer2, max_diff_pixels=50) is not None


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_057_page_screenshot_animations_should_not_capture_infinite_web_animations(
page: Page, server: Server, utils: Utils
) -> None:
Expand All @@ -1042,6 +1056,7 @@ async def test_SS_057_page_screenshot_animations_should_not_capture_infinite_web
assert compare_images(buffer1, buffer2, max_diff_pixels=50) is not None


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_058_page_screenshot_animations_should_fire_transitionend_for_finite_transitions(
page: Page, server: Server, utils: Utils
) -> None:
Expand Down Expand Up @@ -1069,6 +1084,7 @@ async def test_SS_058_page_screenshot_animations_should_fire_transitionend_for_f
assert await page.evaluate("() => window['__TRANSITION_END']") is True


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_059_page_screenshot_animations_should_capture_screenshots_after_layoutchanges_in_transitionend_event(
page: Page, server: Server, utils: Utils
) -> None:
Expand Down Expand Up @@ -1108,6 +1124,7 @@ async def test_SS_059_page_screenshot_animations_should_capture_screenshots_afte
assert screenshot1 == screenshot2


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_060_page_screenshot_animations_should_not_change_animation_with_playback_rate_equal_to_0(
page: Page, server: Server, utils: Utils
) -> None:
Expand Down Expand Up @@ -1136,6 +1153,7 @@ async def test_SS_060_page_screenshot_animations_should_not_change_animation_wit
)


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_061_page_screenshot_animations_should_trigger_particular_events_for_css_transitions(
page: Page, server: Server
) -> None:
Expand Down Expand Up @@ -1163,6 +1181,7 @@ async def test_SS_061_page_screenshot_animations_should_trigger_particular_event
]


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_062_page_screenshot_animations_should_trigger_particular_events_for_i_nfinite_css_animation(
page: Page, server: Server
) -> None:
Expand Down Expand Up @@ -1190,6 +1209,7 @@ async def test_SS_062_page_screenshot_animations_should_trigger_particular_event
]


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_063_page_screenshot_animations_should_trigger_particular_events_for_finite_css_animation(
page: Page, server: Server
) -> None:
Expand Down Expand Up @@ -1226,6 +1246,7 @@ async def test_SS_063_page_screenshot_animations_should_trigger_particular_event
]


@pytest.mark.usefixtures("skip_firefox_headed_animations")
async def test_SS_064_page_screenshot_animations_should_wait_for_fonts_to_load(
page: Page, server: Server, browser_name: str, is_win: bool
) -> None:
Expand Down
49 changes: 49 additions & 0 deletions tests/sync/library/chromium/test_connect_over_cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,55 @@ def test_CD_019_should_return_valid_browser_from_context_browser(
browser_server.close()


def test_CD_055_should_work_with_registered_selector_engines(
playwright: Playwright,
browser_type: BrowserType,
launch_arguments: Dict,
port: int,
) -> None:
browser_server = launch(browser_type, launch_arguments, port)
try:
# Python: invoke the engine factory, as the JS function argument does.
playwright.selectors.register(
"cdpTag",
"""(() => ({
query: (root, selector) => root.querySelector(selector),
queryAll: (root, selector) => Array.from(root.querySelectorAll(selector)),
}))()""",
)
cdp_browser = browser_type.connect_over_cdp(f"http://127.0.0.1:{port}/")
page = cdp_browser.contexts[0].new_page()
page.set_content("<div>hello</div>")
assert page.locator("cdpTag=div").text_content() == "hello"
cdp_browser.close()
finally:
browser_server.close()


def test_CD_056_should_respect_the_test_id_attribute_in_strict_mode_errors(
playwright: Playwright,
browser_type: BrowserType,
launch_arguments: Dict,
port: int,
) -> None:
browser_server = launch(browser_type, launch_arguments, port)
try:
playwright.selectors.set_test_id_attribute("data-foo")
cdp_browser = browser_type.connect_over_cdp(f"http://127.0.0.1:{port}/")
page = cdp_browser.contexts[0].new_page()
page.set_content(
'<button data-foo="a">x</button><button data-foo="b">x</button>'
)
with pytest.raises(Error) as exc_info:
page.locator("button").click()
# Python: strict mode errors name the Python locator API.
assert 'aka get_by_test_id("a")' in exc_info.value.message
cdp_browser.close()
finally:
playwright.selectors.set_test_id_attribute("data-testid")
browser_server.close()


def test_CD_020_should_report_an_expected_error_when_the_endpoint_url_returns_a_non_expected_status_code(
browser_type: BrowserType, server: Server
) -> None:
Expand Down
Loading
Loading