Skip to content

Releases: microsoft/playwright-python

v1.48.0

21 Oct 13:45
b807406
Compare
Choose a tag to compare

WebSocket routing

New methods page.route_web_socket() and browser_context.route_web_socket() allow to intercept, modify and mock WebSocket connections initiated in the page. Below is a simple example that mocks WebSocket communication by responding to a "request" with a "response".

def message_handler(ws: WebSocketRoute, message: Union[str, bytes]):
  if message == "request":
    ws.send("response")

page.route_web_socket("/ws", lambda ws: ws.on_message(
    lambda message: message_handler(ws, message)
))

See WebSocketRoute for more details.

UI updates

  • New "copy" buttons for annotations and test location in the HTML report.
  • Route method calls like route.fulfill() are not shown in the report and trace viewer anymore. You can see which network requests were routed in the network tab instead.
  • New "Copy as cURL" and "Copy as fetch" buttons for requests in the network tab.

Miscellaneous

  • New method page.request_gc() may help detect memory leaks.
  • Requests made by APIRequestContext now record detailed timing and security information in the HAR.
  • This version adds support for Python 3.13
  • This version is the last version supporting Python 3.8

Browser Versions

  • Chromium 130.0.6723.19
  • Mozilla Firefox 130.0
  • WebKit 18.0

This version was also tested against the following stable channels:

  • Google Chrome 129
  • Microsoft Edge 129

v1.47.0

12 Sep 16:54
082db40
Compare
Choose a tag to compare

Network Tab improvements

The Network tab in the trace viewer has several nice improvements:

  • filtering by asset type and URL
  • better display of query string parameters
  • preview of font assets

Network tab now has filters

Miscellaneous

  • The mcr.microsoft.com/playwright-python:v1.47.0 now serves a Playwright image based on Ubuntu 24.04 Noble.
    To use the 22.04 jammy-based image, please use mcr.microsoft.com/playwright-python:v1.47.0-jammy instead.
  • The :latest/:focal/:jammy tag for Playwright Docker images is no longer being published. Pin to a specific version for better stability and reproducibility.
  • TLS client certificates can now be passed from memory by passing cert and key as bytes instead of file paths.
  • no_wait_after in locator.selectOption() was deprecated.
  • We've seen reports of WebGL in Webkit misbehaving on GitHub Actions macos-13. We recommend upgrading GitHub Actions to macos-14.

Browser Versions

  • Chromium 129.0.6668.29
  • Mozilla Firefox 130.0
  • WebKit 18.0

This version was also tested against the following stable channels:

  • Google Chrome 128
  • Microsoft Edge 128

v1.46.0

12 Aug 12:04
8b9bcdc
Compare
Choose a tag to compare

TLS Client Certificates

Playwright now allows to supply client-side certificates, so that server can verify them, as specified by TLS Client Authentication.

You can provide client certificates as a parameter of browser.new_context() and api_request.new_context(). The following snippet sets up a client certificate for https://example.com:

context = browser.new_context(
    client_certificates=[
        {
            "origin": "https://example.com",
            "certPath": "client-certificates/cert.pem",
            "keyPath": "client-certificates/key.pem",
        }
    ],
)

When using the Pytest plugin, it can be added like this:

@pytest.fixture(scope="session")
def browser_context_args(browser_context_args):
    return {
        **browser_context_args,
        "client_certificates": [
            {
                "origin": "https://example.com",
                "certPath": "client-certificates/cert.pem",
                "keyPath": "client-certificates/key.pem",
            }
        ],
    }

Trace Viewer Updates

  • Content of text attachments is now rendered inline in the attachments pane.
  • New setting to show/hide routing actions like route.continue_().
  • Request method and status are shown in the network details tab.
  • New button to copy source file location to clipboard.
  • Metadata pane now displays the base_url.

Miscellaneous

Browser Versions

  • Chromium 128.0.6613.18
  • Mozilla Firefox 128.0
  • WebKit 18.0

This version was also tested against the following stable channels:

  • Google Chrome 127
  • Microsoft Edge 127

v1.45.1

23 Jul 11:07
b2e5ef2
Compare
Choose a tag to compare

Highlights

microsoft/playwright-java#1617 - [Bug]: Trace Viewer not reporting all actions
microsoft/playwright#31764 - [Bug]: some actions do not appear in the trace file

Browser Versions

  • Chromium 127.0.6533.5
  • Mozilla Firefox 127.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 126
  • Microsoft Edge 126

v1.45.0

03 Jul 10:24
90bf2e6
Compare
Choose a tag to compare

Clock

Utilizing the new Clock API allows to manipulate and control time within tests to verify time-related behavior. This API covers many common scenarios, including:

  • testing with predefined time;
  • keeping consistent time and timers;
  • monitoring inactivity;
  • ticking through time manually.
# Initialize clock with some time before the test time and let the page load
# naturally. `Date.now` will progress as the timers fire.
page.clock.install(time=datetime.datetime(2024, 2, 2, 8, 0, 0))
page.goto("http://localhost:3333")

# Pretend that the user closed the laptop lid and opened it again at 10am.
# Pause the time once reached that point.
page.clock.pause_at(datetime.datetime(2024, 2, 2, 10, 0, 0))

# Assert the page state.
expect(page.get_by_test_id("current-time")).to_have_text("2/2/2024, 10:00:00 AM")

# Close the laptop lid again and open it at 10:30am.
page.clock.fast_forward("30:00")
expect(page.get_by_test_id("current-time")).to_have_text("2/2/2024, 10:30:00 AM")

See the clock guide for more details.

Miscellaneous

  • Method locator.setInputFiles() now supports uploading a directory for <input type=file webkitdirectory> elements.
    page.get_by_label("Upload directory").set_input_files('mydir')
  • Multiple methods like locator.click() or locator.press() now support a ControlOrMeta modifier key. This key maps to Meta on macOS and maps to Control on Windows and Linux.
    # Press the common keyboard shortcut Control+S or Meta+S to trigger a "Save" operation.
    page.keyboard.press("ControlOrMeta+S")
  • New property httpCredentials.send in apiRequest.newContext() that allows to either always send the Authorization header or only send it in response to 401 Unauthorized.
  • Playwright now supports Chromium, Firefox and WebKit on Ubuntu 24.04.
  • v1.45 is the last release to receive WebKit update for macOS 12 Monterey. Please update macOS to keep using the latest WebKit.

Browser Versions

  • Chromium 127.0.6533.5
  • Mozilla Firefox 127.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 126
  • Microsoft Edge 126

v1.44.0

17 May 09:21
7cc2bc9
Compare
Choose a tag to compare

New APIs

Accessibility assertions

Locator handler

locator = page.get_by_text("This interstitial covers the button")
page.add_locator_handler(locator, lambda overlay: overlay.locator("#close").click(), times=3, no_wait_after=True)
# Run your tests that can be interrupted by the overlay.
# ...
page.remove_locator_handler(locator)

Miscellaneous options

Browser Versions

  • Chromium 125.0.6422.14
  • Mozilla Firefox 125.0.1
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 124
  • Microsoft Edge 124

v1.43.0

09 Apr 10:31
d12ce3b
Compare
Choose a tag to compare

New APIs

  • Method BrowserContext.clear_cookies([options]) now supports filters to remove only some cookies.

    # Clear all cookies.
    context.clear_cookies()
    # New: clear cookies with a particular name.
    context.clear_cookies(name="session-id")
    # New: clear cookies for a particular domain.
    context.clear_cookies(domain="my-origin.com")
  • New method locator.content_frame converts a {@link Locator} object to a FrameLocator. This can be useful when you have a Locator object obtained somewhere, and later on would like to interact with the content inside the frame.

    locator = page.locator("iframe[name='embedded']")
    # ...
    frame_locator = locator.content_frame
    frame_locator.getByRole("button").click()
  • New method frameLocator.owner converts a FrameLocator object to a Locator. This can be useful when you have a FrameLocator object obtained somewhere, and later on would like to interact with the iframe element.

    frame_locator = page.frame_locator("iframe[name='embedded']")
    # ...
    locator = frame_locator.owner
    expect(locator).to_be_visible()
  • Conda builds are now published for macOS-arm64 and Linux-arm64.

Browser Versions

  • Chromium 124.0.6367.8
  • Mozilla Firefox 124.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 123
  • Microsoft Edge 123

v1.42.0

06 Mar 10:06
Compare
Choose a tag to compare

New Locator Handler

New method page.add_locator_handler(locator, handler) registers a callback that will be invoked when specified element becomes visible and may block Playwright actions. The callback can get rid of the overlay. Here is an example that closes a cookie dialog when it appears.

# Setup the handler.
page.add_locator_handler(
    page.get_by_role("heading", name="Hej! You are in control of your cookies."),
    lambda: page.get_by_role("button", name="Accept all").click(),
)
# Write the test as usual.
page.goto("https://www.ikea.com/")
page.get_by_role("link", name="Collection of blue and white").click()
expect(page.get_by_role("heading", name="Light and easy")).to_be_visible()

New APIs

Announcements

  • ⚠️ Ubuntu 18 is not supported anymore.

Browser Versions

  • Chromium 123.0.6312.4
  • Mozilla Firefox 123.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 122
  • Microsoft Edge 123

v1.41.2

06 Feb 20:43
Compare
Choose a tag to compare

Highlights

#2258 - [REGRESSION] Failing step is not highlighted in red in actions panel for versions after 1.39.0
microsoft/playwright#29123 - [REGRESSION] route.continue: Protocol error (Fetch.continueRequest): Invalid InterceptionId.

Browser Versions

  • Chromium 121.0.6167.57
  • Mozilla Firefox 121.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 120
  • Microsoft Edge 120

v1.41.1

24 Jan 23:07
2b39066
Compare
Choose a tag to compare

Highlights

microsoft/playwright#29067 - [REGRESSION] Codegen/Recorder: not all clicks are being actioned nor recorded
microsoft/playwright#29019 - [REGRESSION] trace.playwright.dev does not currently support the loading from URL

Browser Versions

  • Chromium 121.0.6167.57
  • Mozilla Firefox 121.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 120
  • Microsoft Edge 120