Skip to main content

发行说明

版本 1.52

¥Version 1.52

高亮

¥Highlights

  • 新的方法 expect(locator).to_contain_class(),以符合人机工程学的方式在元素上声明单独的类名。

    ¥New method expect(locator).to_contain_class() to ergonomically assert individual class names on the element.

      expect(page.get_by_role('listitem', name='Ship v1.52')).to_contain_class('done')
  • Aria 快照 新增两个属性:/children 用于严格匹配,/url 用于链接。

    ¥Aria Snapshots got two new properties: /children for strict matching and /url for links.

    expect(locator).to_match_aria_snapshot("""
    - list
    - /children: equal
    - listitem: Feature A
    - listitem:
    - link "Feature B":
    - /url: "https://playwright.nodejs.cn"
    """)

杂项

¥Miscellaneous

重大变化

¥Breaking Changes

  • page.route() 这样的方法中的 Glob URL 模式不再支持 ?[]。我们建议改用正则表达式。

    ¥Glob URL patterns in methods like page.route() do not support ? and [] anymore. We recommend using regular expressions instead.

  • 方法 route.continue_() 不再允许覆盖 Cookie 标头。如果提供了 Cookie 标头,它将被忽略,并从浏览器的 Cookie 存储中加载 Cookie。要设置自定义 Cookie,请使用 browser_context.add_cookies()

    ¥Method route.continue_() does not allow to override the Cookie header anymore. If a Cookie header is provided, it will be ignored, and the cookie will be loaded from the browser's cookie store. To set custom cookies, use browser_context.add_cookies().

  • macOS 13 现已弃用,将不再接收 WebKit 更新。请升级到较新的 macOS 版本以继续受益于最新的 WebKit 改进。

    ¥macOS 13 is now deprecated and will no longer receive WebKit updates. Please upgrade to a more recent macOS version to continue benefiting from the latest WebKit improvements.

浏览器版本

¥Browser Versions

  • Chromium 136.0.7103.25

  • Mozilla Firefox 137.0

  • WebKit 18.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • Google Chrome 135

  • Microsoft Edge 135

版本 1.51

¥Version 1.51

高亮

¥Highlights

浏览器版本

¥Browser Versions

  • Chromium 134.0.6998.35

  • Mozilla Firefox 135.0

  • WebKit 18.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • Google Chrome 133

  • Microsoft Edge 133

版本 1.50

¥Version 1.50

异步 Pytest 插件

¥Async Pytest Plugin

杂项

¥Miscellaneous

UI 更新

¥UI updates

  • Codegen 中的新按钮用于选择元素以生成 aria 快照。

    ¥New button in Codegen for picking elements to produce aria snapshots.

  • 其他详细信息(例如按下的键)现在与跟踪中的操作 API 调用一起显示。

    ¥Additional details (such as keys pressed) are now displayed alongside action API calls in traces.

  • 在跟踪中显示 canvas 内容容易出错。显示现在默认禁用,可以通过 Display canvas content UI 设置启用。

    ¥Display of canvas content in traces is error-prone. Display is now disabled by default, and can be enabled via the Display canvas content UI setting.

  • CallNetwork 面板现在显示额外的时间信息。

    ¥Call and Network panels now display additional time information.

重点

¥Breaking

浏览器版本

¥Browser Versions

  • Chromium 133.0.6943.16

  • Mozilla Firefox 134.0

  • WebKit 18.2

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • Google Chrome 132

  • Microsoft Edge 132

版本 1.49

¥Version 1.49

Aria 快照

¥Aria snapshots

新断言 expect(locator).to_match_aria_snapshot() 通过与预期的可访问性树(以 YAML 表示)进行比较来验证页面结构。

¥New assertion expect(locator).to_match_aria_snapshot() verifies page structure by comparing to an expected accessibility tree, represented as YAML.

page.goto("https://playwright.nodejs.cn")
expect(page.locator('body')).to_match_aria_snapshot('''
- banner:
- heading /Playwright enables reliable/ [level=1]
- link "Get started"
- link "Star microsoft/playwright on GitHub"
- main:
- img "Browsers (Chromium, Firefox, WebKit)"
- heading "Any browser • Any platform • One API"
''')

你可以使用 测试生成器 或调用 locator.aria_snapshot() 来生成此断言。

¥You can generate this assertion with Test Generator or by calling locator.aria_snapshot().

aria 快照指南 中了解更多信息。

¥Learn more in the aria snapshots guide.

跟踪组

¥Tracing groups

新方法 tracing.group() 允许你在跟踪查看器中直观地对操作进行分组。

¥New method tracing.group() allows you to visually group actions in the trace viewer.

# All actions between group and group_end
# will be shown in the trace viewer as a group.
page.context.tracing.group("Open Playwright.dev > API")
page.goto("https://playwright.nodejs.cn/")
page.get_by_role("link", name="API").click()
page.context.tracing.group_end()

重点:chromemsedge 通道切换到新的无头模式

¥Breaking: chrome and msedge channels switch to new headless mode

如果你在 playwright.config.ts 中使用以下通道之一,则此更改会影响你:

¥This change affects you if you're using one of the following channels in your playwright.config.ts:

  • chromechrome-devchrome-betachrome-canary

    ¥chrome, chrome-dev, chrome-beta, or chrome-canary

  • msedgemsedge-devmsedge-betamsedge-canary

    ¥msedge, msedge-dev, msedge-beta, or msedge-canary

更新到 Playwright v1.49 后,运行你的测试套件。如果仍然通过,你就可以开始了。如果没有,你可能需要更新快照,并围绕 PDF 查看器和扩展调整一些测试代码。详细信息请参见 问题 #33566

¥After updating to Playwright v1.49, run your test suite. If it still passes, you're good to go. If not, you will probably need to update your snapshots, and adapt some of your test code around PDF viewers and extensions. See issue #33566 for more details.

尝试新的 Chromium 无头

¥Try new Chromium headless

你可以使用 'chromium' 通道选择新的无头模式。如 Chrome 官方文档介绍 所示:

¥You can opt into the new headless mode by using 'chromium' channel. As official Chrome documentation puts it:

另一方面,New Headless 是真正的 Chrome 浏览器,因此更加真实、可靠并提供更多功能。这使其更适合高精度端到端 Web 应用测试或浏览器扩展测试。

¥New Headless on the other hand is the real Chrome browser, and is thus more authentic, reliable, and offers more features. This makes it more suitable for high-accuracy end-to-end web app testing or browser extension testing.

请参阅 问题 #33566 了解你可能遇到的可能故障列表以及有关 Chromium headless 的更多详细信息。如果你在选择加入后发现任何问题,请提交问题。

¥See issue #33566 for the list of possible breakages you could encounter and more details on Chromium headless. Please file an issue if you see any problems after opting in.

pytest test_login.py --browser-channel chromium

杂项

¥Miscellaneous

  • Ubuntu 20.04 和 Debian 11 上的 WebKit 将不再有更新。我们建议将你的操作系统更新到更高版本。

    ¥There will be no more updates for WebKit on Ubuntu 20.04 and Debian 11. We recommend updating your OS to a later version.

  • 快照内的 <canvas> 元素现在绘制预览。

    ¥<canvas> elements inside a snapshot now draw a preview.

  • 不再支持 Python 3.8。

    ¥Python 3.8 is not supported anymore.

浏览器版本

¥Browser Versions

  • Chromium 131.0.6778.33

  • Mozilla Firefox 132.0

  • WebKit 18.2

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • Google Chrome 130

  • Microsoft Edge 130

版本 1.48

¥Version 1.48

WebSocket 路由

¥WebSocket routing

新方法 page.route_web_socket()browser_context.route_web_socket() 允许拦截、修改和模拟在页面中发起的 WebSocket 连接。下面是一个简单的示例,通过使用 "response" 响应 "request" 来模拟 WebSocket 通信。

¥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)
))

详细信息请参见 WebSocketRoute

¥See WebSocketRoute for more details.

UI 更新

¥UI updates

  • HTML 报告中用于注释和测试位置的新 "copy" 按钮。

    ¥New "copy" buttons for annotations and test location in the HTML report.

  • route.fulfill() 这样的路由方法调用不再显示在报告和跟踪查看器中。你可以在网络选项卡中查看哪些网络请求被路由。

    ¥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.

  • 网络选项卡中用于请求的新 "复制为 cURL" 和 "复制为 fetch" 按钮。

    ¥New "Copy as cURL" and "Copy as fetch" buttons for requests in the network tab.

杂项

¥Miscellaneous

浏览器版本

¥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

版本 1.47

¥Version 1.47

网络选项卡改进

¥Network Tab improvements

跟踪查看器中的“网络”选项卡有几项不错的改进:

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

  • 按资源类型和 URL 过滤

    ¥filtering by asset type and URL

  • 更好地显示查询字符串参数

    ¥better display of query string parameters

  • 字体资源预览

    ¥preview of font assets

Network tab now has filters

杂项

¥Miscellaneous

  • mcr.microsoft.com/playwright/python:v1.47.0 现在提供基于 Ubuntu 24.04 Noble 的 Playwright 图片。要使用基于 22.04 jammy 的图片,请改用 mcr.microsoft.com/playwright/python:v1.47.0-jammy

    ¥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.

  • Playwright Docker 镜像的 :latest/:focal/:jammy 标签已不再发布。固定到特定版本以获得更好的稳定性和可重复性。

    ¥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.certclient_certificates.key 作为字节而不是文件路径传递,从内存中传递。

    ¥TLS client certificates can now be passed from memory by passing client_certificates.cert and client_certificates.key as bytes instead of file paths.

  • locator.select_option() 中的 no_wait_after 已被弃用。

    ¥no_wait_after in locator.select_option() was deprecated.

  • 我们已经看到有关 Webkit 中的 WebGL 在 GitHub Actions macos-13 上行为不当的报告。我们建议将 GitHub Actions 升级到 macos-14

    ¥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

版本 1.46

¥Version 1.46

TLS 客户端证书

¥TLS Client Certificates

Playwright 现在允许提供客户端证书,以便服务器能够按照 TLS 客户端身份验证的要求进行验证。

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

你可以将客户端证书作为 browser.new_context()api_request.new_context() 的参数提供。以下代码片段为 https://example.com 设置了客户端证书:

¥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",
}
],
)

跟踪查看器更新

¥Trace Viewer Updates

  • 文本附件的内容现在在附件窗格中以内联方式渲染。

    ¥Content of text attachments is now rendered inline in the attachments pane.

  • 新设置显示/隐藏路由操作,如 route.continue_()

    ¥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.

  • 元数据窗格现在显示 base_url

    ¥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

版本 1.45

¥Version 1.45

时钟

¥Clock

利用新的 时钟 API 允许在测试中操纵和控制时间来验证与时间相关的行为。此 API 涵盖许多常见场景,包括:

¥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

  • 方法 locator.set_input_files() 现在支持上传 <input type=file webkitdirectory> 元素的目录。

    ¥Method locator.set_input_files() now supports uploading a directory for <input type=file webkitdirectory> elements.

    page.get_by_label("Upload directory").set_input_files('mydir')
  • 现在,locator.click()locator.press() 等多种方法都支持 ControlOrMeta 修饰键。此键在 macOS 上映射到 Meta,在 Windows 和 Linux 上映射到 Control

    ¥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")
  • api_request.new_context() 中的新属性 httpCredentials.send 允许始终发送 Authorization 标头或仅在响应 401 Unauthorized 时发送它。

    ¥New property httpCredentials.send in api_request.new_context() that allows to either always send the Authorization header or only send it in response to 401 Unauthorized.

  • Playwright 现在支持 Ubuntu 24.04 上的 Chromium、Firefox 和 WebKit。

    ¥Playwright now supports Chromium, Firefox and WebKit on Ubuntu 24.04.

  • v1.45 是接收 macOS 12 Monterey 的 WebKit 更新的最后一个版本。请更新 macOS 以继续使用最新的 WebKit。

    ¥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

  • 网络工具包 17.4

    ¥WebKit 17.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • Google Chrome 126

  • Microsoft Edge 126

版本 1.44

¥Version 1.44

新 API

¥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

  • 网络工具包 17.4

    ¥WebKit 17.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • Google Chrome 124

  • Microsoft Edge 124

1.43 版本

¥Version 1.43

新 API

¥New APIs

  • 方法 browser_context.clear_cookies() 现在支持过滤器以仅删除一些 cookie。

    ¥Method browser_context.clear_cookies() 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")
  • 新方法 locator.content_frameLocator 对象转换为 FrameLocator。当你在某处获得了 Locator 对象,并且稍后想要与框架内的内容进行交互时,这会很有用。

    ¥New method locator.content_frame converts a 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()
  • 新方法 frame_locator.ownerFrameLocator 对象转换为 Locator。当你在某处获得了 FrameLocator 对象,并且稍后想要与 iframe 元素进行交互时,这会很有用。

    ¥New method frame_locator.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 版本现已发布 macOS-arm64 和 Linux-arm64 版本。

    ¥Conda builds are now published for macOS-arm64 and Linux-arm64.

浏览器版本

¥Browser Versions

  • Chromium 124.0.6367.8

  • 火狐浏览器 124.0

    ¥Mozilla Firefox 124.0

  • 网络工具包 17.4

    ¥WebKit 17.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 123

    ¥Google Chrome 123

  • 微软边缘 123

    ¥Microsoft Edge 123

1.42 版本

¥Version 1.42

新的定位器处理程序

¥New Locator Handler

新方法 page.add_locator_handler() 注册一个回调,当指定元素变得可见时将调用该回调,并且可能会阻止 Playwright 操作。回调可以摆脱覆盖。以下是一个在 Cookie 对话框出现时关闭该对话框的示例。

¥New method page.add_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()

新 API

¥New APIs

公告

¥Announcements

  • ⚠️ Ubuntu 18 不再受支持。

    ¥⚠️ Ubuntu 18 is not supported anymore.

浏览器版本

¥Browser Versions

  • Chromium 123.0.6312.4

  • 火狐浏览器 123.0

    ¥Mozilla Firefox 123.0

  • 网络工具包 17.4

    ¥WebKit 17.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 122

    ¥Google Chrome 122

  • 微软边缘 123

    ¥Microsoft Edge 123

1.41 版本

¥Version 1.41

新 API

¥New APIs

浏览器版本

¥Browser Versions

  • Chromium 121.0.6167.57

  • 火狐浏览器 121.0

    ¥Mozilla Firefox 121.0

  • 网络工具包 17.4

    ¥WebKit 17.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 120

    ¥Google Chrome 120

  • 微软 Edge 120

    ¥Microsoft Edge 120

1.40 版本

¥Version 1.40

测试生成器更新

¥Test Generator Update

Playwright Test Generator

生成断言的新工具:

¥New tools to generate assertions:

以下是带有断言的生成测试的示例:

¥Here is an example of a generated test with assertions:

from playwright.sync_api import Page, expect

def test_example(page: Page) -> None:
page.goto("https://playwright.nodejs.cn/")
page.get_by_role("link", name="Get started").click()
expect(page.get_by_label("Breadcrumbs").get_by_role("list")).to_contain_text("Installation")
expect(page.get_by_label("Search")).to_be_visible()
page.get_by_label("Search").click()
page.get_by_placeholder("Search docs").fill("locator")
expect(page.get_by_placeholder("Search docs")).to_have_value("locator");

新 API

¥New APIs

其他变更

¥Other Changes

浏览器版本

¥Browser Versions

  • Chromium 120.0.6099.28

  • 火狐浏览器 119.0

    ¥Mozilla Firefox 119.0

  • 网络工具包 17.4

    ¥WebKit 17.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 119

    ¥Google Chrome 119

  • 微软 Edge 119

    ¥Microsoft Edge 119

1.39 版本

¥Version 1.39

常青浏览器更新。

¥Evergreen browsers update.

浏览器版本

¥Browser Versions

  • Chromium 119.0.6045.9

  • 火狐浏览器 118.0.1

    ¥Mozilla Firefox 118.0.1

  • 网络工具包 17.4

    ¥WebKit 17.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 118

    ¥Google Chrome 118

  • 微软 Edge 118

    ¥Microsoft Edge 118

1.38 版本

¥Version 1.38

跟踪查看器更新

¥Trace Viewer Updates

Playwright Trace Viewer

  1. 放大时间范围。

    ¥Zoom into time range.

  2. 网络面板重新设计。

    ¥Network panel redesign.

新 API

¥New APIs

弃用

¥Deprecations

浏览器版本

¥Browser Versions

  • Chromium 117.0.5938.62

  • 火狐浏览器 117.0

    ¥Mozilla Firefox 117.0

  • 网络工具包 17.0

    ¥WebKit 17.0

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 116

    ¥Google Chrome 116

  • 微软 Edge 116

    ¥Microsoft Edge 116

1.37 版本

¥Version 1.37

高亮

¥Highlights

📚 Debian 12 Bookworm 支持

¥📚 Debian 12 Bookworm Support

Playwright 现在支持在 x86_64 和 arm64 上运行 Chromium、Firefox 和 WebKit 的 Debian 12 Bookworm。如果你遇到任何问题,请告诉我们!

¥Playwright now supports Debian 12 Bookworm on both x86_64 and arm64 for Chromium, Firefox and WebKit. Let us know if you encounter any issues!

Linux 支持如下所示:

¥Linux support looks like this:

乌班图 20.04乌班图 22.04Debian 11Debian 12
Chromium
WebKit
火狐浏览器

浏览器版本

¥Browser Versions

  • Chromium 116.0.5845.82

  • 火狐浏览器 115.0

    ¥Mozilla Firefox 115.0

  • 网络工具包 17.0

    ¥WebKit 17.0

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 115

    ¥Google Chrome 115

  • 微软 Edge 115

    ¥Microsoft Edge 115

1.36 版本

¥Version 1.36

🏝️ 夏季维护版本。

¥🏝️ Summer maintenance release.

浏览器版本

¥Browser Versions

  • Chromium 115.0.5790.75

  • 火狐浏览器 115.0

    ¥Mozilla Firefox 115.0

  • 网络工具包 17.0

    ¥WebKit 17.0

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 114

    ¥Google Chrome 114

  • 微软 Edge 114

    ¥Microsoft Edge 114

1.35 版本

¥Version 1.35

高亮

¥Highlights

  • 方法 page.screenshot()locator.screenshot() 新增选项 mask_color,用于更改默认遮罩颜色。

    ¥New option mask_color for methods page.screenshot() and locator.screenshot() to change default masking color.

  • 用于卸载浏览器二进制文件的新 uninstall CLI 命令:

    ¥New uninstall CLI command to uninstall browser binaries:

    $ playwright uninstall # remove browsers installed by this installation
    $ playwright uninstall --all # remove all ever-install Playwright browsers

浏览器版本

¥Browser Versions

  • Chromium 115.0.5790.13

  • 火狐浏览器 113.0

    ¥Mozilla Firefox 113.0

  • 网络工具包 16.4

    ¥WebKit 16.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 114

    ¥Google Chrome 114

  • 微软 Edge 114

    ¥Microsoft Edge 114

1.34 版本

¥Version 1.34

高亮

¥Highlights

浏览器版本

¥Browser Versions

  • Chromium 114.0.5735.26

  • 火狐浏览器 113.0

    ¥Mozilla Firefox 113.0

  • 网络工具包 16.4

    ¥WebKit 16.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 113

    ¥Google Chrome 113

  • 微软 Edge 113

    ¥Microsoft Edge 113

1.33 版本

¥Version 1.33

定位器更新

¥Locators Update

  • 使用 locator.or_() 创建与两个定位器之一匹配的定位器。考虑这样一个场景:你想要单击 "新邮件" 按钮,但有时会显示安全设置对话框。在这种情况下,你可以等待 "新邮件" 按钮或对话框并进行相应操作:

    ¥Use locator.or_() to create a locator that matches either of the two locators. Consider a scenario where you'd like to click on a "New email" button, but sometimes a security settings dialog shows up instead. In this case, you can wait for either a "New email" button, or a dialog and act accordingly:

    new_email = page.get_by_role("button", name="New email")
    dialog = page.get_by_text("Confirm security settings")
    expect(new_email.or_(dialog)).is_visible()
    if (dialog.is_visible()):
    page.get_by_role("button", name="Dismiss").click()
    new_email.click()
  • 使用 locator.filter() 中的新选项 has_nothas_not_text 来查找不符合某些条件的元素。

    ¥Use new options has_not and has_not_text in locator.filter() to find elements that do not match certain conditions.

    row_locator = page.locator("tr")
    row_locator.filter(has_not_text="text in column 1").filter(
    has_not=page.get_by_role("button", name="column 2 button")
    ).screenshot()
  • 使用新的 Web 优先断言 expect(locator).to_be_attached() 确保该元素存在于页面的 DOM 中。不要与确保该元素既附加又可见的 expect(locator).to_be_visible() 混淆。

    ¥Use new web-first assertion expect(locator).to_be_attached() to ensure that the element is present in the page's DOM. Do not confuse with the expect(locator).to_be_visible() that ensures that element is both attached & visible.

新 API

¥New APIs

⚠️ 重大改变

¥⚠️ Breaking change

  • mcr.microsoft.com/playwright/python:v1.33.0 现在提供基于 Ubuntu Jammy 的 Playwright 映像。要使用基于焦点的图片,请改用 mcr.microsoft.com/playwright/python:v1.33.0-focal

    ¥The mcr.microsoft.com/playwright/python:v1.33.0 now serves a Playwright image based on Ubuntu Jammy. To use the focal-based image, please use mcr.microsoft.com/playwright/python:v1.33.0-focal instead.

浏览器版本

¥Browser Versions

  • Chromium 113.0.5672.53

  • 火狐浏览器 112.0

    ¥Mozilla Firefox 112.0

  • 网络工具包 16.4

    ¥WebKit 16.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 112

    ¥Google Chrome 112

  • 微软 Edge 112

    ¥Microsoft Edge 112

1.32 版本

¥Version 1.32

新 API

¥New APIs

浏览器版本

¥Browser Versions

  • Chromium 112.0.5615.29

  • 火狐浏览器 111.0

    ¥Mozilla Firefox 111.0

  • 网络工具包 16.4

    ¥WebKit 16.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 111

    ¥Google Chrome 111

  • 微软 Edge 111

    ¥Microsoft Edge 111

1.31 版本

¥Version 1.31

新 API

¥New APIs

  • 根据 交集监视器 API,新断言 expect(locator).to_be_in_viewport() 确保定位器指向与视口相交的元素。

    ¥New assertion expect(locator).to_be_in_viewport() ensures that locator points to an element that intersects viewport, according to the intersection observer API.

    from playwright.sync_api import expect

    locator = page.get_by_role("button")

    # Make sure at least some part of element intersects viewport.
    expect(locator).to_be_in_viewport()

    # Make sure element is fully outside of viewport.
    expect(locator).not_to_be_in_viewport()

    # Make sure that at least half of the element intersects viewport.
    expect(locator).to_be_in_viewport(ratio=0.5)

杂项

¥Miscellaneous

  • 现在可以在单独的窗口中打开跟踪查看器中的 DOM 快照。

    ¥DOM snapshots in trace viewer can be now opened in a separate window.

  • 方法 route.fetch() 的新选项 max_redirects

    ¥New option max_redirects for method route.fetch().

  • Playwright 现在支持 Debian 11 arm64。

    ¥Playwright now supports Debian 11 arm64.

  • 官方 docker 图片 现在包括 Node 18,而不是 Node 16。

    ¥Official docker images now include Node 18 instead of Node 16.

浏览器版本

¥Browser Versions

  • Chromium 111.0.5563.19

  • 火狐浏览器 109.0

    ¥Mozilla Firefox 109.0

  • 网络工具包 16.4

    ¥WebKit 16.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 110

    ¥Google Chrome 110

  • 微软 Edge 110

    ¥Microsoft Edge 110

1.30 版本

¥Version 1.30

浏览器版本

¥Browser Versions

  • Chromium 110.0.5481.38

  • 火狐浏览器 108.0.2

    ¥Mozilla Firefox 108.0.2

  • 网络工具包 16.4

    ¥WebKit 16.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 109

    ¥Google Chrome 109

  • 微软 Edge 109

    ¥Microsoft Edge 109

1.29 版本

¥Version 1.29

新 API

¥New APIs

  • route.fulfill() 的新方法 route.fetch() 和新选项 json

    ¥New method route.fetch() and new option json for route.fulfill():

    def handle_route(route: Route):
    # Fetch original settings.
    response = route.fetch()

    # Force settings theme to a predefined value.
    json = response.json()
    json["theme"] = "Solorized"

    # Fulfill with modified data.
    route.fulfill(json=json)


    page.route("**/api/settings", handle_route)
  • 用于迭代所有匹配元素的新方法 locator.all()

    ¥New method locator.all() to iterate over all matching elements:

    # Check all checkboxes!
    checkboxes = page.get_by_role("checkbox")
    for checkbox in checkboxes.all():
    checkbox.check()
  • locator.select_option() 现在按值或标签匹配:

    ¥locator.select_option() matches now by value or label:

    <select multiple>
    <option value="red">Red</option>
    <option value="green">Green</option>
    <option value="blue">Blue</option>
    </select>
    element.select_option("Red")

杂项

¥Miscellaneous

浏览器版本

¥Browser Versions

  • Chromium 109.0.5414.46

  • 火狐浏览器 107.0

    ¥Mozilla Firefox 107.0

  • 网络工具包 16.4

    ¥WebKit 16.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 108

    ¥Google Chrome 108

  • 微软 Edge 108

    ¥Microsoft Edge 108

1.28 版本

¥Version 1.28

Playwright 工具

¥Playwright Tools

  • CodeGen 中的实时定位器。使用 "探索" 工具为页面上的任何元素生成定位器。

    ¥Live Locators in CodeGen. Generate a locator for any element on the page using "Explore" tool.

Locator Explorer

新 API

¥New APIs

浏览器版本

¥Browser Versions

  • Chromium 108.0.5359.29

  • 火狐浏览器 106.0

    ¥Mozilla Firefox 106.0

  • 网络工具包 16.4

    ¥WebKit 16.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 107

    ¥Google Chrome 107

  • 微软 Edge 107

    ¥Microsoft Edge 107

1.27 版本

¥Version 1.27

定位器

¥Locators

使用这些新的 API 编写定位器是一种乐趣:

¥With these new APIs writing locators is a joy:

page.get_by_label("User Name").fill("John")

page.get_by_label("Password").fill("secret-password")

page.get_by_role("button", name="Sign in").click()

expect(page.get_by_text("Welcome, John!")).to_be_visible()

所有相同的方法也可用于 LocatorFrameLocatorFrame 类。

¥All the same methods are also available on Locator, FrameLocator and Frame classes.

其他亮点

¥Other highlights

  • 正如 v1.25 中所宣布的,自 2022 年 12 月起将不再支持 Ubuntu 18。除此之外,从下一个 Playwright 版本开始,Ubuntu 18 将不再有 WebKit 更新。

    ¥As announced in v1.25, Ubuntu 18 will not be supported as of Dec 2022. In addition to that, there will be no WebKit updates on Ubuntu 18 starting from the next Playwright release.

行为改变

¥Behavior Changes

  • 具有空值的 expect(locator).to_have_attribute() 不再与缺失的属性匹配。例如,当 button 没有 disabled 属性时,以下代码片段将会成功。

    ¥expect(locator).to_have_attribute() with an empty value does not match missing attribute anymore. For example, the following snippet will succeed when button does not have a disabled attribute.

    expect(page.get_by_role("button")).to_have_attribute("disabled", "")

浏览器版本

¥Browser Versions

  • Chromium 107.0.5304.18

  • 火狐浏览器 105.0.1

    ¥Mozilla Firefox 105.0.1

  • 网络工具包 16.0

    ¥WebKit 16.0

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 106

    ¥Google Chrome 106

  • 微软 Edge 106

    ¥Microsoft Edge 106

1.26 版本

¥Version 1.26

断言

¥Assertions

其他亮点

¥Other highlights

行为改变

¥Behavior Change

许多 Playwright API 已经支持 wait_until: "domcontentloaded" 选项。例如:

¥A bunch of Playwright APIs already support the wait_until: "domcontentloaded" option. For example:

page.goto("https://playwright.nodejs.cn", wait_until="domcontentloaded")

在 1.26 之前,这将等待所有 iframe 触发 DOMContentLoaded 事件。

¥Prior to 1.26, this would wait for all iframes to fire the DOMContentLoaded event.

为了与 Web 规范保持一致,'domcontentloaded' 值仅等待目标框架触发 'DOMContentLoaded' 事件。使用 wait_until="load" 等待所有 iframe。

¥To align with web specification, the 'domcontentloaded' value only waits for the target frame to fire the 'DOMContentLoaded' event. Use wait_until="load" to wait for all iframes.

浏览器版本

¥Browser Versions

  • Chromium 106.0.5249.30

  • 火狐浏览器 104.0

    ¥Mozilla Firefox 104.0

  • 网络工具包 16.0

    ¥WebKit 16.0

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 105

    ¥Google Chrome 105

  • 微软 Edge 105

    ¥Microsoft Edge 105

1.25 版本

¥Version 1.25

公告

¥Announcements

  • 🎁 我们现在发布 Ubuntu 22.04 Jammy Jellyfish docker 镜像:mcr.microsoft.com/playwright/python:v1.34.0-jammy

    ¥🎁 We now ship Ubuntu 22.04 Jammy Jellyfish docker image: mcr.microsoft.com/playwright/python:v1.34.0-jammy.

  • 🪦 这是支持 macOS 10.15 的最后一个版本(自 1.21 起已弃用)。

    ¥🪦 This is the last release with macOS 10.15 support (deprecated as of 1.21).

  • ⚠️ Ubuntu 18 现已弃用,自 2022 年 12 月起将不再受支持。

    ¥⚠️ Ubuntu 18 is now deprecated and will not be supported as of Dec 2022.

浏览器版本

¥Browser Versions

  • Chromium 105.0.5195.19

  • 火狐浏览器 103.0

    ¥Mozilla Firefox 103.0

  • 网络工具包 16.0

    ¥WebKit 16.0

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 104

    ¥Google Chrome 104

  • 微软 Edge 104

    ¥Microsoft Edge 104

1.24 版本

¥Version 1.24

🐂 Debian 11 Bullseye 支持

¥🐂 Debian 11 Bullseye Support

Playwright 现在支持 x86_64 上的 Debian 11 Bullseye,适用于 Chromium、Firefox 和 WebKit。如果你遇到任何问题,请告诉我们!

¥Playwright now supports Debian 11 Bullseye on x86_64 for Chromium, Firefox and WebKit. Let us know if you encounter any issues!

Linux 支持如下所示:

¥Linux support looks like this:

| | 乌班图 20.04 | 乌班图 22.04 | Debian 11 | :--- | :---:| :---:| :---:| :---:| | Chromium | ✅ | ✅ | ✅ | | WebKit | ✅ | ✅ | ✅ | | Firefox | ✅ | ✅ | ✅ |

¥Ubuntu 20.04Ubuntu 22.04Debian 11
Chromium
WebKit
Firefox

新的介绍文档

¥New introduction docs

我们重写了入门文档,使其更加注重端到端测试。在 playwright.dev 上查看它们。

¥We rewrote our Getting Started docs to be more end-to-end testing focused. Check them out on playwright.dev.

1.23 版本

¥Version 1.23

网络重播

¥Network Replay

现在,你可以将网络流量记录到 HAR 文件中,并在测试中重复使用此流量。

¥Now you can record network traffic into a HAR file and re-use this traffic in your tests.

将网络记录到 HAR 文件中:

¥To record network into HAR file:

npx playwright open --save-har=github.har.zip https://github.com/microsoft

或者,你可以通过编程方式记录 HAR:

¥Alternatively, you can record HAR programmatically:

context = browser.new_context(record_har_path="github.har.zip")
# ... do stuff ...
context.close()

使用新方法 page.route_from_har()browser_context.route_from_har() 提供来自 HAR 文件的匹配响应:

¥Use the new methods page.route_from_har() or browser_context.route_from_har() to serve matching responses from the HAR file:

context.route_from_har("github.har.zip")

阅读 我们的文档 中的更多内容。

¥Read more in our documentation.

高级路由

¥Advanced Routing

你现在可以使用 route.fallback() 推迟路由到其他处理程序。

¥You can now use route.fallback() to defer routing to other handlers.

考虑以下示例:

¥Consider the following example:

# Remove a header from all requests
def remove_header_handler(route: Route) -> None:
headers = route.request.all_headers()
if "if-none-match" in headers:
del headers["if-none-match"]
route.fallback(headers=headers)

page.route("**/*", remove_header_handler)

# Abort all images
def abort_images_handler(route: Route) -> None:
if route.request.resource_type == "image":
route.abort()
else:
route.fallback()

page.route("**/*", abort_images_handler)

请注意,新方法 page.route_from_har()browser_context.route_from_har() 也参与路由并且可以推迟。

¥Note that the new methods page.route_from_har() and browser_context.route_from_har() also participate in routing and could be deferred to.

Web 优先断言更新

¥Web-First Assertions Update

杂项

¥Miscellaneous

  • 如果有一个 Service Worker 挡住了你的路,你现在可以使用新的上下文选项 service_workers 轻松禁用它:

    ¥If there's a service worker that's in your way, you can now easily disable it with a new context option service_workers:

    context = browser.new_context(service_workers="block")
    page = context.new_page()
  • 使用 .zip 路径作为 recordHar 上下文选项会自动压缩生成的 HAR:

    ¥Using .zip path for recordHar context option automatically zips the resulting HAR:

    context = browser.new_context(record_har_path="github.har.zip")
  • 如果你打算手动编辑 HAR,请考虑使用 "minimal" HAR 记录模式,该模式仅记录重放所必需的信息:

    ¥If you intend to edit HAR by hand, consider using the "minimal" HAR recording mode that only records information that is essential for replaying:

    context = browser.new_context(record_har_mode="minimal", record_har_path="har.har")
  • Playwright 现在可以在 Ubuntu 22 amd64 和 Ubuntu 22 arm64 上运行。

    ¥Playwright now runs on Ubuntu 22 amd64 and Ubuntu 22 arm64.

1.22 版本

¥Version 1.22

高亮

¥Highlights

Graphics

1.21 版本

¥Version 1.21

高亮

¥Highlights

行为改变

¥Behavior Changes

  • mcr.microsoft.com/playwright docker 镜像不再包含 Python。请使用 mcr.microsoft.com/playwright/python 作为 Playwright-ready docker 镜像并预装 Python。

    ¥The mcr.microsoft.com/playwright docker image no longer contains Python. Please use mcr.microsoft.com/playwright/python as a Playwright-ready docker image with pre-installed Python.

  • Playwright 现在支持通过 locator.set_input_files() API 上传大文件(数百 MB)。

    ¥Playwright now supports large file uploads (100s of MBs) via locator.set_input_files() API.

浏览器版本

¥Browser Versions

  • Chromium 101.0.4951.26

  • 火狐浏览器 98.0.2

    ¥Mozilla Firefox 98.0.2

  • 网络工具包 15.4

    ¥WebKit 15.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 100

    ¥Google Chrome 100

  • 微软 Edge 100

    ¥Microsoft Edge 100

1.20 版本

¥Version 1.20

高亮

¥Highlights

公告

¥Announcements

  • 我们现在发布指定的 Python docker 镜像 mcr.microsoft.com/playwright/python。如果你使用 Python,请切换到它。这是在我们的 javascript mcr.microsoft.com/playwright docker 镜像中包含 Python 的最后一个版本。

    ¥We now ship a designated Python docker image mcr.microsoft.com/playwright/python. Please switch over to it if you use Python. This is the last release that includes Python inside our javascript mcr.microsoft.com/playwright docker image.

  • v1.20 是接收 macOS 10.15 Catalina WebKit 更新的最后一个版本。请更新 macOS 以继续使用最新和最好的 WebKit!

    ¥v1.20 is the last release to receive WebKit update for macOS 10.15 Catalina. Please update macOS to keep using latest & greatest WebKit!

浏览器版本

¥Browser Versions

  • Chromium 101.0.4921.0

  • 火狐浏览器 97.0.1

    ¥Mozilla Firefox 97.0.1

  • 网络工具包 15.4

    ¥WebKit 15.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 99

    ¥Google Chrome 99

  • 微软 Edge 99

    ¥Microsoft Edge 99

1.19 版本

¥Version 1.19

高亮

¥Highlights

  • 定位器现在支持 has 选项,确保它内部包含另一个定位器:

    ¥Locator now supports a has option that makes sure it contains another locator inside:

    page.locator("article", has=page.locator(".highlight")).click()

    阅读 定位器文档 的更多内容

    ¥Read more in locator documentation

  • locator.page

    ¥New locator.page

  • page.screenshot()locator.screenshot() 现在自动隐藏闪烁的插入符号

    ¥page.screenshot() and locator.screenshot() now automatically hide blinking caret

  • Playwright Codegen 现在生成定位器和帧定位器

    ¥Playwright Codegen now generates locators and frame locators

浏览器版本

¥Browser Versions

  • Chromium 100.0.4863.0

  • 火狐浏览器 96.0.1

    ¥Mozilla Firefox 96.0.1

  • 网络工具包 15.4

    ¥WebKit 15.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 98

    ¥Google Chrome 98

  • 微软 Edge 98

    ¥Microsoft Edge 98

1.18 版本

¥Version 1.18

API 测试

¥API Testing

Playwright for Python 1.18 引入了新的 API 测试,可让你直接从 Python 向服务器发送请求!现在你可以:

¥Playwright for Python 1.18 introduces new API Testing that lets you send requests to the server directly from Python! Now you can:

  • 测试你的服务器 API

    ¥test your server API

  • 在测试中访问 Web 应用之前准备服务器端状态

    ¥prepare server side state before visiting the web application in a test

  • 在浏览器中运行某些操作后验证服务器端后置条件

    ¥validate server side post-conditions after running some actions in the browser

要代表 Playwright 页面触发请求,请使用新的 page.request API:

¥To do a request on behalf of Playwright's Page, use new page.request API:

# Do a GET request on behalf of page
res = page.request.get("http://example.com/foo.json")

阅读 我们的文档 中的更多内容。

¥Read more in our documentation.

Web 优先断言

¥Web-First Assertions

Playwright for Python 1.18 引入了 Web 优先断言

¥Playwright for Python 1.18 introduces Web-First Assertions.

考虑以下示例:

¥Consider the following example:

from playwright.sync_api import Page, expect

def test_status_becomes_submitted(page: Page) -> None:
# ..
page.locator("#submit-button").click()
expect(page.locator(".status")).to_have_text("Submitted")

Playwright 将使用选择器 .status 重新测试节点,直到获取的节点具有 "Submitted" 文本。它将重新获取节点并一遍又一遍地检查它,直到满足条件或达到超时。你可以将此超时作为一个选项传递。

¥Playwright will be re-testing the node with the selector .status until fetched Node has the "Submitted" text. It will be re-fetching the node and checking it over and over, until the condition is met or until the timeout is reached. You can pass this timeout as an option.

阅读 我们的文档 中的更多内容。

¥Read more in our documentation.

定位器改进

¥Locator Improvements

  • locator.drag_to()

  • 现在可以选择通过每个定位器包含的文本来过滤每个定位器:

    ¥Each locator can now be optionally filtered by the text it contains:

    page.locator("li", has_text="my item").locator("button").click()

    阅读 定位器文档 的更多内容

    ¥Read more in locator documentation

新的 API 和更改

¥New APIs & changes

浏览器版本

¥Browser Versions

  • Chromium 99.0.4812.0

  • 火狐浏览器 95.0

    ¥Mozilla Firefox 95.0

  • 网络工具包 15.4

    ¥WebKit 15.4

该版本还针对以下稳定渠道进行了测试:

¥This version was also tested against the following stable channels:

  • 谷歌浏览器 97

    ¥Google Chrome 97

  • 微软 Edge 97

    ¥Microsoft Edge 97

1.17 版本

¥Version 1.17

框架定位器

¥Frame Locators

Playwright 1.17 引入 帧定位器 - 页面上 iframe 的定位器。帧定位器捕获足以检索 iframe 的逻辑,然后定位该 iframe 中的元素。默认情况下,帧定位器是严格的,将等待 iframe 出现,并且可以在 Web 优先断言中使用。

¥Playwright 1.17 introduces frame locators - a locator to the iframe on the page. Frame locators capture the logic sufficient to retrieve the iframe and then locate elements in that iframe. Frame locators are strict by default, will wait for iframe to appear and can be used in Web-First assertions.

Graphics

帧定位器可以使用 page.frame_locator()locator.frame_locator() 方法创建。

¥Frame locators can be created with either page.frame_locator() or locator.frame_locator() method.

locator = page.frame_locator("my-frame").locator("text=Submit")
locator.click()

欲了解更多内容,请访问 我们的文档

¥Read more at our documentation.

跟踪查看器更新

¥Trace Viewer Update

Playwright Trace Viewer 现已在 https://trace.playwright.dev 在线提供!只需拖放 trace.zip 文件即可检查其内容。

¥Playwright Trace Viewer is now available online at https://trace.playwright.dev! Just drag-and-drop your trace.zip file to inspect its contents.

注意:跟踪文件没有上传到任何地方;trace.playwright.dev 是本地处理跟踪的 渐进式网络应用

¥NOTE: trace files are not uploaded anywhere; trace.playwright.dev is a progressive web application that processes traces locally.

  • Playwright 测试跟踪现在默认包括源(可以使用跟踪选项关闭这些源)

    ¥Playwright Test traces now include sources by default (these could be turned off with tracing option)

  • 跟踪查看器现在显示测试名称

    ¥Trace Viewer now shows test name

  • 包含浏览器详细信息的新跟踪元数据选项卡

    ¥New trace metadata tab with browser details

  • 快照现在有 URL 栏

    ¥Snapshots now have URL bar

image

HTML 报告更新

¥HTML Report Update

  • HTML 报告现在支持动态过滤

    ¥HTML report now supports dynamic filtering

  • 报告现在是一个静态 HTML 文件,可以通过电子邮件或作为 Slack 附件发送。

    ¥Report is now a single static HTML file that could be sent by e-mail or as a slack attachment.

image

Ubuntu ARM64 支持及更多

¥Ubuntu ARM64 support + more

  • Playwright 现在支持 Ubuntu 20.04 ARM64。现在,你可以在 Apple M1 和 Raspberry Pi 上的 Docker 内运行 Playwright 测试。

    ¥Playwright now supports Ubuntu 20.04 ARM64. You can now run Playwright tests inside Docker on Apple M1 and on Raspberry Pi.

  • 你现在可以使用 Playwright 在 Linux 上安装稳定版本的 Edge:

    ¥You can now use Playwright to install stable version of Edge on Linux:

    npx playwright install msedge

新 API

¥New APIs

  • 跟踪现在支持 'title' 选项

    ¥Tracing now supports a 'title' option

  • 页面导航支持新的 'commit' 等待选项

    ¥Page navigations support a new 'commit' waiting option

1.16 版本

¥Version 1.16

🎭 Playwright 库

¥🎭 Playwright Library

locator.wait_for

等待定位器解析为具有给定状态的单个元素。默认为 state: 'visible'

¥Wait for a locator to resolve to a single element with a given state. Defaults to the state: 'visible'.

使用列表时特别方便:

¥Comes especially handy when working with lists:

order_sent = page.locator("#order-sent")
order_sent.wait_for()

了解有关 locator.wait_for() 的更多信息。

¥Read more about locator.wait_for().

Docker 对 Arm64 的支持

¥Docker support for Arm64

Playwright Docker 镜像现已发布适用于 Arm64 的版本,因此可以在 Apple Silicon 上使用。

¥Playwright Docker image is now published for Arm64 so it can be used on Apple Silicon.

了解有关 Docker 集成 的更多信息。

¥Read more about Docker integration.

🎭 Playwright 踪迹查看器

¥🎭 Playwright Trace Viewer

  • 使用 npx playwright show-trace 运行跟踪查看器并将跟踪文件拖放到跟踪查看器 PWA

    ¥run trace viewer with npx playwright show-trace and drop trace files to the trace viewer PWA

  • 更好地对行动目标进行视觉归因

    ¥better visual attribution of action targets

了解有关 跟踪查看器 的更多信息。

¥Read more about Trace Viewer.

浏览器版本

¥Browser Versions

  • Chromium 97.0.4666.0

  • 火狐浏览器 93.0

    ¥Mozilla Firefox 93.0

  • 网络工具包 15.4

    ¥WebKit 15.4

此版本的 Playwright 还针对以下稳定通道进行了测试:

¥This version of Playwright was also tested against the following stable channels:

  • 谷歌浏览器 94

    ¥Google Chrome 94

  • 微软 Edge 94

    ¥Microsoft Edge 94

1.15 版本

¥Version 1.15

🖱️ 鼠标滚轮

¥🖱️ Mouse Wheel

通过使用 mouse.wheel(),你现在可以垂直或水平滚动。

¥By using mouse.wheel() you are now able to scroll vertically or horizontally.

📜 新的标头 API

¥📜 New Headers API

以前不可能获取响应的多个标头值。现在这是可能的,并且可以使用其他辅助函数:

¥Previously it was not possible to get multiple header values of a response. This is now possible and additional helper functions are available:

🌈 强制颜色模拟

¥🌈 Forced-Colors emulation

现在可以通过在 browser.new_context() 中传递或调用 page.emulate_media() 来模拟 forced-colors CSS 媒体功能。

¥Its now possible to emulate the forced-colors CSS media feature by passing it in the browser.new_context() or calling page.emulate_media().

新 API

¥New APIs

浏览器版本

¥Browser Versions

  • Chromium 96.0.4641.0

  • 火狐浏览器 92.0

    ¥Mozilla Firefox 92.0

  • 网络工具包 15.0

    ¥WebKit 15.0

1.14 版本

¥Version 1.14

⚡ 新 "strict" 模式

¥⚡️ New "strict" mode

选择器歧义是自动化测试中的一个常见问题。"strict" 模式确保你的选择器指向单个元素,否则抛出异常。

¥Selector ambiguity is a common problem in automation testing. "strict" mode ensures that your selector points to a single element and throws otherwise.

strict=true 传递到你的操作调用中以选择加入。

¥Pass strict=true into your action calls to opt in.

# This will throw if you have more than one button!
page.click("button", strict=True)

📍 新 定位器 API

¥📍 New Locators API

定位器表示页面上元素的视图。它捕获足以在任何给定时刻检索元素的逻辑。

¥Locator represents a view to the element(s) on the page. It captures the logic sufficient to retrieve the element at any given moment.

LocatorElementHandle 之间的区别在于后者指向特定元素,而 Locator 捕获如何检索该元素的逻辑。

¥The difference between the Locator and ElementHandle is that the latter points to a particular element, while Locator captures the logic of how to retrieve that element.

另外,定位器默认为 "strict"!

¥Also, locators are "strict" by default!

locator = page.locator("button")
locator.click()

documentation 中了解更多信息。

¥Learn more in the documentation.

🧩 实验性 ReactVue 选择器引擎

¥🧩 Experimental React and Vue selector engines

React 和 Vue 选择器允许通过组件名称和/或属性值来选择元素。语法与 属性选择器 非常相似,并且支持所有属性选择器运算符。

¥React and Vue selectors allow selecting elements by its component name and/or property values. The syntax is very similar to attribute selectors and supports all attribute selector operators.

page.locator("_react=SubmitButton[enabled=true]").click()
page.locator("_vue=submit-button[enabled=true]").click()

反应选择器文档vue 选择器文档 中了解更多信息。

¥Learn more in the react selectors documentation and the vue selectors documentation.

✨ 新的 nthvisible 选择器引擎

¥✨ New nth and visible selector engines

  • nth 选择器引擎相当于 :nth-match 伪类,但可以与其他选择器引擎组合。

    ¥nth selector engine is equivalent to the :nth-match pseudo class, but could be combined with other selector engines.

  • visible 选择器引擎相当于 :visible 伪类,但可以与其他选择器引擎组合。

    ¥visible selector engine is equivalent to the :visible pseudo class, but could be combined with other selector engines.

# select the first button among all buttons
button.click("button >> nth=0")
# or if you are using locators, you can use first, nth() and last
page.locator("button").first.click()

# click a visible button
button.click("button >> visible=true")

浏览器版本

¥Browser Versions

  • Chromium 94.0.4595.0

  • 火狐浏览器 91.0

    ¥Mozilla Firefox 91.0

  • 网络工具包 15.0

    ¥WebKit 15.0

1.13 版本

¥Version 1.13

Playwright

工具

¥Tools

  • Playwright Trace Viewer 现在显示参数、返回值和 console.log() 调用。

    ¥Playwright Trace Viewer now shows parameters, returned values and console.log() calls.

新的和大修的指南

¥New and Overhauled Guides

浏览器版本

¥Browser Versions

  • Chromium 93.0.4576.0

  • 火狐浏览器 90.0

    ¥Mozilla Firefox 90.0

  • 网络工具包 14.2

    ¥WebKit 14.2

新 Playwright API

¥New Playwright APIs

1.12 版本

¥Version 1.12

🧟‍♂️ Playwright 跟踪查看器简介

¥🧟‍♂️ Introducing Playwright Trace Viewer

Playwright 踪迹查看器 是一个新的 GUI 工具,可帮助探索脚本运行后记录的 Playwright 痕迹。Playwright 的踪迹让你可以检查:

¥Playwright Trace Viewer is a new GUI tool that helps exploring recorded Playwright traces after the script ran. Playwright traces let you examine:

  • 每个 Playwright 操作之前和之后的页面 DOM

    ¥page DOM before and after each Playwright action

  • 每个 Playwright 操作之前和之后的页面渲染

    ¥page rendering before and after each Playwright action

  • 脚本执行期间的浏览器网络

    ¥browser network during script execution

使用新的 browser_context.tracing API 记录跟踪:

¥Traces are recorded using the new browser_context.tracing API:

browser = chromium.launch()
context = browser.new_context()

# Start tracing before creating / navigating a page.
context.tracing.start(screenshots=True, snapshots=True)

page.goto("https://playwright.nodejs.cn")

# Stop tracing and export it into a zip archive.
context.tracing.stop(path = "trace.zip")

稍后使用 Playwright CLI 检查痕迹:

¥Traces are examined later with the Playwright CLI:

playwright show-trace trace.zip

这将打开以下 GUI:

¥That will open the following GUI:

image

👉 阅读 跟踪查看器文档 中的更多内容。

¥👉 Read more in trace viewer documentation.

浏览器版本

¥Browser Versions

  • Chromium 93.0.4530.0

  • 火狐浏览器 89.0

    ¥Mozilla Firefox 89.0

  • 网络工具包 14.2

    ¥WebKit 14.2

此版本的 Playwright 还针对以下稳定通道进行了测试:

¥This version of Playwright was also tested against the following stable channels:

  • 谷歌浏览器 91

    ¥Google Chrome 91

  • 微软 Edge 91

    ¥Microsoft Edge 91

新 API

¥New APIs

1.11 版本

¥Version 1.11

🎥 新视频:Playwright:现代 Web 的新测试自动化框架(slides)

¥🎥 New video: Playwright: A New Test Automation Framework for the Modern Web (slides)

  • 我们谈论了 Playwright

    ¥We talked about Playwright

  • 展示了幕后的工程工作

    ¥Showed engineering work behind the scenes

  • 进行了新功能的现场演示 ✨

    ¥Did live demos with new features ✨

  • 特别感谢 applitools 主办这次活动并邀请我们!

    ¥Special thanks to applitools for hosting the event and inviting us!

浏览器版本

¥Browser Versions

  • Chromium 92.0.4498.0

  • 火狐浏览器 89.0b6

    ¥Mozilla Firefox 89.0b6

  • 网络工具包 14.2

    ¥WebKit 14.2

新 API

¥New APIs

1.10 版本

¥Version 1.10

打包的浏览器版本

¥Bundled Browser Versions

  • Chromium 90.0.4430.0

  • 火狐浏览器 87.0b10

    ¥Mozilla Firefox 87.0b10

  • 网络工具包 14.2

    ¥WebKit 14.2

此版本的 Playwright 还针对以下稳定通道进行了测试:

¥This version of Playwright was also tested against the following stable channels:

  • 谷歌浏览器 89

    ¥Google Chrome 89

  • 微软 Edge 89

    ¥Microsoft Edge 89

新 API

¥New APIs

1.9 版本

¥Version 1.9

  • Playwright 检查器 是一个新的 GUI 工具,用于编写和调试测试。

    ¥Playwright Inspector is a new GUI tool to author and debug your tests.

    • 对 Playwright 脚本进行逐行调试,包括播放、暂停和单步执行。

      ¥Line-by-line debugging of your Playwright scripts, with play, pause and step-through.

    • 通过记录用户操作来编写新脚本。

      ¥Author new scripts by recording user actions.

    • 通过将鼠标悬停在元素上来为脚本生成元素选择器。

      ¥Generate element selectors for your script by hovering over elements.

    • 设置 PWDEBUG=1 环境变量以启动 Inspector

      ¥Set the PWDEBUG=1 environment variable to launch the Inspector

  • 在标题模式下使用 page.pause() 暂停脚本执行。暂停页面会启动 Playwright 检查器 进行调试。

    ¥Pause script execution with page.pause() in headed mode. Pausing the page launches Playwright Inspector for debugging.

  • CSS 选择器的新 has-text 伪类。:has-text("example") 匹配内部某处包含 "example" 的任何元素,可能在子元素或后代元素中。参见 更多例子

    ¥New has-text pseudo-class for CSS selectors. :has-text("example") matches any element containing "example" somewhere inside, possibly in a child or a descendant element. See more examples.

  • 除非配置了 dialog 事件的监听器,否则页面对话框现在会在执行期间自动关闭。了解更多 关于这个。

    ¥Page dialogs are now auto-dismissed during execution, unless a listener for dialog event is configured. Learn more about this.

  • Python Playwright 现已稳定,具有惯用的蛇形案例 API 和预构建的 Docker 镜像 以在 CI/CD 中运行测试。

    ¥Playwright for Python is now stable with an idiomatic snake case API and pre-built Docker image to run tests in CI/CD.

浏览器版本

¥Browser Versions

  • Chromium 90.0.4421.0

  • 火狐浏览器 86.0b10

    ¥Mozilla Firefox 86.0b10

  • 网络工具包 14.1

    ¥WebKit 14.1

新 API

¥New APIs

1.8 版本

¥Version 1.8

新 API

¥New APIs

浏览器版本

¥Browser Versions

  • Chromium 90.0.4392.0

  • 火狐浏览器 85.0b5

    ¥Mozilla Firefox 85.0b5

  • 网络工具包 14.1

    ¥WebKit 14.1

1.7 版本

¥Version 1.7

  • 新的 Java SDK:Java Playwright 现在与 JavaScriptPython.NET 绑定 同等。

    ¥New Java SDK: Playwright for Java is now on par with JavaScript, Python and .NET bindings.

  • 浏览器存储 API:新的便利 API 用于保存和加载浏览器存储状态(cookie、本地存储),以通过身份验证简化自动化场景。

    ¥Browser storage API: New convenience APIs to save and load browser storage state (cookies, local storage) to simplify automation scenarios with authentication.

  • 新的 CSS 选择器:我们听取了你对更灵活的选择器的反馈,并改进了选择器的实现。Playwright 1.7 引入了 新的 CSS 扩展,并且即将推出更多内容。

    ¥New CSS selectors: We heard your feedback for more flexible selectors and have revamped the selectors implementation. Playwright 1.7 introduces new CSS extensions and there's more coming soon.

  • 新网站:playwright.dev 的文档网站已更新,现在使用 Docusaurus 构建。

    ¥New website: The docs website at playwright.dev has been updated and is now built with Docusaurus.

  • 对苹果芯片的支持:适用于 WebKit 和 Chromium 的 Playwright 浏览器二进制文件现已针对 Apple Silicon 构建。

    ¥Support for Apple Silicon: Playwright browser binaries for WebKit and Chromium are now built for Apple Silicon.

新 API

¥New APIs

浏览器版本

¥Browser Versions

  • Chromium 89.0.4344.0

  • 火狐浏览器 84.0b9

    ¥Mozilla Firefox 84.0b9

  • 网络工具包 14.1

    ¥WebKit 14.1