发行说明
版本 1.52
¥Version 1.52
高亮
¥Highlights
-
新的方法 Expect(Locator).ToContainClassAsync(),以符合人机工程学的方式在元素上声明单独的类名。
¥New method Expect(Locator).ToContainClassAsync() to ergonomically assert individual class names on the element.
await Expect(Page.GetByRole(AriaRole.Listitem, new() { Name = "Ship v1.52" })).ToContainClassAsync("done");
-
Aria 快照 新增两个属性:
/children
用于严格匹配,/url
用于链接。¥Aria Snapshots got two new properties:
/children
for strict matching and/url
for links.await Expect(locator).ToMatchAriaSnapshotAsync(@"
- list
- /children: equal
- listitem: Feature A
- listitem:
- link ""Feature B"":
- /url: ""https://playwright.nodejs.cn""
");
杂项
¥Miscellaneous
-
ApiRequest.NewContextAsync() 中的新选项 MaxRedirects 用于控制最大重定向次数。
¥New option MaxRedirects in ApiRequest.NewContextAsync() to control the maximum number of redirects.
-
Locator.AriaSnapshotAsync() 中的新选项 参考 用于为快照中的每个元素生成引用,稍后可用于定位元素。
¥New option Ref in Locator.AriaSnapshotAsync() to generate reference for each element in the snapshot which can later be used to locate the element.
重大变化
¥Breaking Changes
-
像 Page.RouteAsync() 这样的方法中的 Glob URL 模式不再支持
?
和[]
。我们建议改用正则表达式。¥Glob URL patterns in methods like Page.RouteAsync() do not support
?
and[]
anymore. We recommend using regular expressions instead. -
方法 Route.ContinueAsync() 不再允许覆盖
Cookie
标头。如果提供了Cookie
标头,它将被忽略,并从浏览器的 Cookie 存储中加载 Cookie。要设置自定义 Cookie,请使用 BrowserContext.AddCookiesAsync()。¥Method Route.ContinueAsync() does not allow to override the
Cookie
header anymore. If aCookie
header is provided, it will be ignored, and the cookie will be loaded from the browser's cookie store. To set custom cookies, use BrowserContext.AddCookiesAsync(). -
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
-
BrowserContext.StorageStateAsync() 的新选项 IndexedDB 允许保存和恢复 IndexedDB 内容。当你的应用使用 IndexedDB API 存储身份验证令牌(如 Firebase 身份验证)时很有用。
¥New option IndexedDB for BrowserContext.StorageStateAsync() allows to save and restore IndexedDB contents. Useful when your application uses IndexedDB API to store authentication tokens, like Firebase Authentication.
以下是 身份验证指南 之后的示例:
¥Here is an example following the authentication guide:
// Save storage state into the file. Make sure to include IndexedDB.
await context.StorageStateAsync(new()
{
Path = "../../../playwright/.auth/state.json",
IndexedDB = true
});
// Create a new context with the saved storage state.
var context = await browser.NewContextAsync(new()
{
StorageStatePath = "../../../playwright/.auth/state.json"
}); -
Locator.Filter() 的新选项 可见的 允许仅匹配可见元素。
¥New option Visible for Locator.Filter() allows matching only visible elements.
// Ignore invisible todo items.
var todoItems = Page.GetByTestId("todo-item").Filter(new() { Visible = true });
// Check there are exactly 3 visible ones.
await Expect(todoItems).ToHaveCountAsync(3); -
方法 Page.EmulateMediaAsync() 和 Browser.NewContextAsync() 的新选项
Contrast
允许模拟prefers-contrast
媒体功能。¥New option
Contrast
for methods Page.EmulateMediaAsync() and Browser.NewContextAsync() allows to emulate theprefers-contrast
media feature. -
新选项 FailOnStatusCode 使通过 APIRequestContext 发送的所有获取请求都抛出除 2xx 和 3xx 之外的响应代码。
¥New option FailOnStatusCode makes all fetch requests made through the APIRequestContext throw on response codes other than 2xx and 3xx.
浏览器版本
¥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
支持 Xunit
¥Support for Xunit
-
通过 Microsoft.Playwright.Xunit 支持 xUnit 2.8+。请关注我们的 入门 指南了解更多信息。
¥Support for xUnit 2.8+ via Microsoft.Playwright.Xunit. Follow our Getting Started guide to learn more.
杂项
¥Miscellaneous
-
添加了方法 Expect(Locator).ToHaveAccessibleErrorMessageAsync() 来断言定位器指向具有给定 咏叹调错误消息 的元素。
¥Added method Expect(Locator).ToHaveAccessibleErrorMessageAsync() to assert the Locator points to an element with a given aria errormessage.
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 theDisplay canvas content
UI setting. -
Call
和Network
面板现在显示额外的时间信息。¥
Call
andNetwork
panels now display additional time information.
重点
¥Breaking
-
如果目标元素不是
<input>
、<select>
或其他可编辑元素,则 Expect(Locator).ToBeEditableAsync() 和 Locator.IsEditableAsync() 现在会抛出异常。¥Expect(Locator).ToBeEditableAsync() and Locator.IsEditableAsync() now throw if the target element is not
<input>
,<select>
, or a number of other editable elements.
浏览器版本
¥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).ToMatchAriaSnapshotAsync() 通过与预期的可访问性树(以 YAML 表示)进行比较来验证页面结构。
¥New assertion Expect(Locator).ToMatchAriaSnapshotAsync() verifies page structure by comparing to an expected accessibility tree, represented as YAML.
await page.GotoAsync("https://playwright.nodejs.cn");
await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(@"
- 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.AriaSnapshotAsync() 来生成此断言。
¥You can generate this assertion with Test Generator or by calling Locator.AriaSnapshotAsync().
在 aria 快照指南 中了解更多信息。
¥Learn more in the aria snapshots guide.
跟踪组
¥Tracing groups
新方法 Tracing.GroupAsync() 允许你在跟踪查看器中直观地对操作进行分组。
¥New method Tracing.GroupAsync() allows you to visually group actions in the trace viewer.
// All actions between GroupAsync and GroupEndAsync
// will be shown in the trace viewer as a group.
await Page.Context.Tracing.GroupAsync("Open Playwright.dev > API");
await Page.GotoAsync("https://playwright.nodejs.cn/");
await Page.GetByRole(AriaRole.Link, new() { Name = "API" }).ClickAsync();
await Page.Context.Tracing.GroupEndAsync();
重点:chrome
和 msedge
通道切换到新的无头模式
¥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
:
-
chrome
、chrome-dev
、chrome-beta
或chrome-canary
¥
chrome
,chrome-dev
,chrome-beta
, orchrome-canary
-
msedge
、msedge-dev
、msedge-beta
或msedge-canary
¥
msedge
,msedge-dev
,msedge-beta
, ormsedge-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.
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<Playwright>
<BrowserName>chromium</BrowserName>
<LaunchOptions>
<Channel>chromium</Channel>
</LaunchOptions>
</Playwright>
</RunSettings>
dotnet test -- Playwright.BrowserName=chromium Playwright.LaunchOptions.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.
浏览器版本
¥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.RouteWebSocketAsync() 和 BrowserContext.RouteWebSocketAsync() 允许拦截、修改和模拟在页面中发起的 WebSocket 连接。下面是一个简单的示例,通过使用 "response"
响应 "request"
来模拟 WebSocket 通信。
¥New methods Page.RouteWebSocketAsync() and BrowserContext.RouteWebSocketAsync() 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"
.
await page.RouteWebSocketAsync("/ws", ws => {
ws.OnMessage(frame => {
if (frame.Text == "request")
ws.Send("response");
});
});
详细信息请参见 WebSocketRoute。
¥See WebSocketRoute for more details.
UI 更新
¥UI updates
-
HTML 报告中用于注释和测试位置的新 "copy" 按钮。
¥New "copy" buttons for annotations and test location in the HTML report.
-
像 Route.FulfillAsync() 这样的路由方法调用不再显示在报告和跟踪查看器中。你可以在网络选项卡中查看哪些网络请求被路由。
¥Route method calls like Route.FulfillAsync() 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
-
新方法 Page.RequestGCAsync() 可能有助于检测内存泄漏。
¥New method Page.RequestGCAsync() may help detect memory leaks.
-
APIRequestContext 发送的请求现在在 HAR 中记录详细的时间和安全信息。
¥Requests made by APIRequestContext now record detailed timing and security information in the HAR.
浏览器版本
¥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
杂项
¥Miscellaneous
-
mcr.microsoft.com/playwright/dotnet:v1.47.0
现在提供基于 Ubuntu 24.04 Noble 的 Playwright 图片。要使用基于 22.04 jammy 的图片,请改用mcr.microsoft.com/playwright/dotnet:v1.47.0-jammy
。¥The
mcr.microsoft.com/playwright/dotnet:v1.47.0
now serves a Playwright image based on Ubuntu 24.04 Noble. To use the 22.04 jammy-based image, please usemcr.microsoft.com/playwright/dotnet: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. -
现在可以通过将 ClientCertificates.Cert 和 ClientCertificates.Key 作为字节数组(而不是文件路径)传递,从内存传递 TLS 客户端证书。
¥TLS client certificates can now be passed from memory by passing ClientCertificates.Cert and ClientCertificates.Key as byte arrays instead of file paths.
-
Locator.SelectOptionAsync() 中的 NoWaitAfter 已被弃用。
¥NoWaitAfter in Locator.SelectOptionAsync() 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 tomacos-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.NewContextAsync() 和 ApiRequest.NewContextAsync() 的参数提供。以下代码片段为 https://example.com
设置了客户端证书:
¥You can provide client certificates as a parameter of Browser.NewContextAsync() and ApiRequest.NewContextAsync(). The following snippet sets up a client certificate for https://example.com
:
var context = await Browser.NewContextAsync(new() {
ClientCertificates = [
new() {
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.ContinueAsync()。
¥New setting to show/hide routing actions like Route.ContinueAsync().
-
请求方法和状态显示在网络详细信息选项卡中。
¥Request method and status are shown in the network details tab.
-
新按钮用于将源文件位置复制到剪贴板。
¥New button to copy source file location to clipboard.
-
元数据窗格现在显示
BaseURL
。¥Metadata pane now displays the
BaseURL
.
杂项
¥Miscellaneous
-
ApiRequestContext.FetchAsync() 中的新
maxRetries
选项可在ECONNRESET
网络错误时重试。¥New
maxRetries
option in ApiRequestContext.FetchAsync() which retries on theECONNRESET
network error.
浏览器版本
¥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.
await Page.Clock.InstallAsync(new()
{
TimeDate = new DateTime(2024, 2, 2, 8, 0, 0)
});
await Page.GotoAsync("http://localhost:3333");
// Pretend that the user closed the laptop lid and opened it again at 10am.
// Pause the time once reached that point.
await Page.Clock.PauseAtAsync(new DateTime(2024, 2, 2, 10, 0, 0));
// Assert the page state.
await Expect(Page.GetByTestId("current-time")).ToHaveTextAsync("2/2/2024, 10:00:00 AM");
// Close the laptop lid again and open it at 10:30am.
await Page.Clock.FastForwardAsync("30:00");
await Expect(Page.GetByTestId("current-time")).ToHaveTextAsync("2/2/2024, 10:30:00 AM");
详细信息请参见 时钟指南。
¥See the clock guide for more details.
杂项
¥Miscellaneous
-
方法 Locator.SetInputFilesAsync() 现在支持上传
<input type=file webkitdirectory>
元素的目录。¥Method Locator.SetInputFilesAsync() now supports uploading a directory for
<input type=file webkitdirectory>
elements.await page.GetByLabel("Upload directory").SetInputFilesAsync("mydir");
-
现在,Locator.ClickAsync() 或 Locator.PressAsync() 等多种方法都支持
ControlOrMeta
修饰键。此键在 macOS 上映射到Meta
,在 Windows 和 Linux 上映射到Control
。¥Multiple methods like Locator.ClickAsync() or Locator.PressAsync() now support a
ControlOrMeta
modifier key. This key maps toMeta
on macOS and maps toControl
on Windows and Linux.// Press the common keyboard shortcut Control+S or Meta+S to trigger a "Save" operation.
await page.Keyboard.PressAsync("ControlOrMeta+S"); -
ApiRequest.NewContextAsync() 中的新属性
httpCredentials.send
允许始终发送Authorization
标头或仅在响应401 Unauthorized
时发送它。¥New property
httpCredentials.send
in ApiRequest.NewContextAsync() that allows to either always send theAuthorization
header or only send it in response to401 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
-
Expect(Locator).ToHaveAccessibleNameAsync() 检查元素是否具有指定的可访问名称:
¥Expect(Locator).ToHaveAccessibleNameAsync() checks if the element has the specified accessible name:
var locator = Page.GetByRole(AriaRole.Button);
await Expect(locator).ToHaveAccessibleNameAsync("Submit"); -
Expect(Locator).ToHaveAccessibleDescriptionAsync() 检查元素是否具有指定的可访问描述:
¥Expect(Locator).ToHaveAccessibleDescriptionAsync() checks if the element has the specified accessible description:
var locator = Page.GetByRole(AriaRole.Button);
await Expect(locator).ToHaveAccessibleDescriptionAsync("Upload a photo"); -
Expect(Locator).ToHaveRoleAsync() 检查元素是否具有指定的 ARIA 角色:
¥Expect(Locator).ToHaveRoleAsync() checks if the element has the specified ARIA role:
var locator = Page.GetByTestId("save-button");
await Expect(locator).ToHaveRoleAsync(AriaRole.Button);
定位器处理程序
¥Locator handler
-
执行使用 Page.AddLocatorHandlerAsync() 添加的处理程序后,Playwright 现在将等待,直到触发处理程序的覆盖不再可见。你可以使用新的
NoWaitAfter
选项选择退出此行为。¥After executing the handler added with Page.AddLocatorHandlerAsync(), Playwright will now wait until the overlay that triggered the handler is not visible anymore. You can opt-out of this behavior with the new
NoWaitAfter
option. -
你可以在 Page.AddLocatorHandlerAsync() 中使用新的
Times
选项来指定处理程序应运行的最大次数。¥You can use new
Times
option in Page.AddLocatorHandlerAsync() to specify maximum number of times the handler should be run. -
Page.AddLocatorHandlerAsync() 中的处理程序现在接受定位器作为参数。
¥The handler in Page.AddLocatorHandlerAsync() now accepts the locator as argument.
-
用于删除先前添加的定位器处理程序的新 Page.RemoveLocatorHandlerAsync() 方法。
¥New Page.RemoveLocatorHandlerAsync() method for removing previously added locator handlers.
var locator = Page.GetByText("This interstitial covers the button");
await Page.AddLocatorHandlerAsync(locator, async (overlay) =>
{
await overlay.Locator("#close").ClickAsync();
}, new() { Times = 3, NoWaitAfter = true });
// Run your tests that can be interrupted by the overlay.
// ...
await Page.RemoveLocatorHandlerAsync(locator);
其他选项
¥Miscellaneous options
-
新方法 FormData.Append() 允许在
APIRequestContext.FetchAsync()
中的Multipart
选项中指定同名的重复字段:¥New method FormData.Append() allows to specify repeating fields with the same name in
Multipart
option inAPIRequestContext.FetchAsync()
:var formData = Context.APIRequest.CreateFormData();
formData.Append("file", new FilePayload()
{
Name = "f1.js",
MimeType = "text/javascript",
Buffer = System.Text.Encoding.UTF8.GetBytes("var x = 2024;")
});
formData.Append("file", new FilePayload()
{
Name = "f2.txt",
MimeType = "text/plain",
Buffer = System.Text.Encoding.UTF8.GetBytes("hello")
});
var response = await Context.APIRequest.PostAsync("https://example.com/uploadFiles", new() { Multipart = formData }); -
Expect(Page).ToHaveURLAsync() 现在支持
IgnoreCase
option。¥Expect(Page).ToHaveURLAsync() now supports
IgnoreCase
option.
浏览器版本
¥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
-
方法 BrowserContext.ClearCookiesAsync() 现在支持过滤器以仅删除一些 cookie。
¥Method BrowserContext.ClearCookiesAsync() now supports filters to remove only some cookies.
// Clear all cookies.
await Context.ClearCookiesAsync();
// New: clear cookies with a particular name.
await Context.ClearCookiesAsync(new() { Name = "session-id" });
// New: clear cookies for a particular domain.
await Context.ClearCookiesAsync(new() { Domain = "my-origin.com" }); -
新属性 Locator.ContentFrame 将 Locator 对象转换为 FrameLocator 对象。当你在某处获得了 Locator 对象,并且稍后想要与框架内的内容进行交互时,这会很有用。
¥New property Locator.ContentFrame 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.
var locator = Page.Locator("iframe[name='embedded']");
// ...
var frameLocator = locator.ContentFrame;
await frameLocator.GetByRole(AriaRole.Button).ClickAsync(); -
新属性 FrameLocator.Owner 将 FrameLocator 对象转换为 Locator 对象。当你在某处获得了 FrameLocator 对象,并且稍后想要与
iframe
元素进行交互时,这会很有用。¥New property 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.var frameLocator = page.FrameLocator("iframe[name='embedded']");
// ...
var locator = frameLocator.Owner;
await Expect(locator).ToBeVisibleAsync();
浏览器版本
¥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.AddLocatorHandlerAsync() 注册一个回调,当指定元素变得可见时将调用该回调,并且可能会阻止 Playwright 操作。回调可以摆脱覆盖。以下是一个在 Cookie 对话框出现时关闭该对话框的示例。
¥New method Page.AddLocatorHandlerAsync() 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.
await Page.AddLocatorHandlerAsync(
Page.GetByRole(AriaRole.Heading, new() { Name = "Hej! You are in control of your cookies." }),
async () =>
{
await Page.GetByRole(AriaRole.Button, new() { Name = "Accept all" }).ClickAsync();
});
// Write the test as usual.
await Page.GotoAsync("https://www.ikea.com/");
await Page.GetByRole(AriaRole.Link, new() { Name = "Collection of blue and white" }).ClickAsync();
await Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Light and easy" })).ToBeVisibleAsync();
新 API
¥New APIs
-
Page.PdfAsync() 接受两个新选项 标签 和 大纲。
¥Page.PdfAsync() accepts two new options Tagged and Outline.
公告
¥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
-
新方法 Page.UnrouteAllAsync() 删除了 Page.RouteAsync() 和 Page.RouteFromHARAsync() 注册的所有路由。(可选)允许等待正在进行的路由完成,或忽略其中的任何错误。
¥New method Page.UnrouteAllAsync() removes all routes registered by Page.RouteAsync() and Page.RouteFromHARAsync(). Optionally allows to wait for ongoing routes to finish, or ignore any errors from them.
-
新方法 BrowserContext.UnrouteAllAsync() 删除了 BrowserContext.RouteAsync() 和 BrowserContext.RouteFromHARAsync() 注册的所有路由。(可选)允许等待正在进行的路由完成,或忽略其中的任何错误。
¥New method BrowserContext.UnrouteAllAsync() removes all routes registered by BrowserContext.RouteAsync() and BrowserContext.RouteFromHARAsync(). Optionally allows to wait for ongoing routes to finish, or ignore any errors from them.
-
Page.ScreenshotAsync() 中的新选项 样式 和 Locator.ScreenshotAsync() 中的新选项 样式 可在截屏前将自定义 CSS 添加到页面。
¥New options Style in Page.ScreenshotAsync() and Style in Locator.ScreenshotAsync() to add custom CSS to the page before taking a screenshot.
浏览器版本
¥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
生成断言的新工具:
¥New tools to generate assertions:
-
"断言可见性" 工具生成 Expect(Locator).ToBeVisibleAsync()。
¥"Assert visibility" tool generates Expect(Locator).ToBeVisibleAsync().
-
"断言值" 工具生成 Expect(Locator).ToHaveValueAsync()。
¥"Assert value" tool generates Expect(Locator).ToHaveValueAsync().
-
"断言文本" 工具生成 Expect(Locator).ToContainTextAsync()。
¥"Assert text" tool generates Expect(Locator).ToContainTextAsync().
以下是带有断言的生成测试的示例:
¥Here is an example of a generated test with assertions:
await Page.GotoAsync("https://playwright.nodejs.cn/");
await Page.GetByRole(AriaRole.Link, new() { Name = "Get started" }).ClickAsync();
await Expect(Page.GetByLabel("Breadcrumbs").GetByRole(AriaRole.List)).ToContainTextAsync("Installation");
await Expect(Page.GetByLabel("Search")).ToBeVisibleAsync();
await Page.GetByLabel("Search").ClickAsync();
await Page.GetByPlaceholder("Search docs").FillAsync("locator");
await Expect(Page.GetByPlaceholder("Search docs")).ToHaveValueAsync("locator");
新 API
¥New APIs
-
Page.CloseAsync() 中的选项 原因、BrowserContext.CloseAsync() 中的选项 原因 和 Browser.CloseAsync() 中的选项 原因。报告因关闭而中断的所有操作的关闭原因。
¥Options Reason in Page.CloseAsync(), Reason in BrowserContext.CloseAsync() and Reason in Browser.CloseAsync(). Close reason is reported for all operations interrupted by the closure.
-
BrowserType.LaunchPersistentContextAsync() 中的选项 FirefoxUserPrefs。
¥Option FirefoxUserPrefs in BrowserType.LaunchPersistentContextAsync().
其他变更
¥Other Changes
-
方法 Download.PathAsync() 和 Download.CreateReadStreamAsync() 会因下载失败和取消而引发错误。
¥Methods Download.PathAsync() and Download.CreateReadStreamAsync() throw an error for failed and cancelled downloads.
-
Playwright docker 镜像 现已搭载 .NET 8(全新 LTS)。
¥Playwright docker image now comes with .NET 8 (new LTS).
浏览器版本
¥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
-
放大时间范围。
¥Zoom into time range.
-
网络面板重新设计。
¥Network panel redesign.
新 API
¥New APIs
弃用
¥Deprecations
-
以下方法已被弃用:Page.TypeAsync()、Frame.TypeAsync()、Locator.TypeAsync() 和 ElementHandle.TypeAsync()。请使用 Locator.FillAsync(),这样速度更快。仅当页面上有特殊键盘处理并且需要逐个按键时才使用 Locator.PressSequentiallyAsync()。
¥The following methods were deprecated: Page.TypeAsync(), Frame.TypeAsync(), Locator.TypeAsync() and ElementHandle.TypeAsync(). Please use Locator.FillAsync() instead which is much faster. Use Locator.PressSequentiallyAsync() only if there is a special keyboard handling on the page, and you need to press keys one-by-one.
浏览器版本
¥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
📚 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.04 | Debian 11 | Debian 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.ScreenshotAsync() 和 Locator.ScreenshotAsync() 新增选项
MaskColor
,用于更改默认遮罩颜色。¥New option
MaskColor
for methods Page.ScreenshotAsync() and Locator.ScreenshotAsync() to change default masking color. -
用于卸载浏览器二进制文件的新
uninstall
CLI 命令:¥New
uninstall
CLI command to uninstall browser binaries:$ pwsh bin/Debug/netX/playwright.ps1 uninstall # remove browsers installed by this installation
$ pwsh bin/Debug/netX/playwright.ps1 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
-
新建 Locator.And() 以创建与两个定位器匹配的定位器。
¥New Locator.And() to create a locator that matches both locators.
var button = page.GetByRole(AriaRole.BUTTON).And(page.GetByTitle("Subscribe"));
-
新事件 BrowserContext.Console 和 BrowserContext.Dialog 用于订阅给定浏览器上下文中任何页面的任何对话框和控制台消息。使用新方法 ConsoleMessage.Page 和 Dialog.Page 来查明事件源。
¥New events BrowserContext.Console and BrowserContext.Dialog to subscribe to any dialogs and console messages from any page from the given browser context. Use the new methods ConsoleMessage.Page and Dialog.Page to pin-point event source.
浏览器版本
¥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:
var newEmail = Page.GetByRole(AriaRole.Button, new() { Name = "New email" });
var dialog = Page.GetByText("Confirm security settings");
await Expect(newEmail.Or(dialog)).ToBeVisibleAsync();
if (await dialog.IsVisibleAsync())
await Page.GetByRole(AriaRole.Button, new() { Name = "Dismiss" }).ClickAsync();
await newEmail.ClickAsync(); -
使用 Locator.Filter() 中的新选项 HasNot 和 HasNotText|HasNotTextRegex 来查找不符合某些条件的元素。
¥Use new options HasNot and HasNotText|HasNotTextRegex in Locator.Filter() to find elements that do not match certain conditions.
var rowLocator = Page.Locator("tr");
await rowLocator
.Filter(new() { HasNotText = "text in column 1" })
.Filter(new() { HasNot = Page.GetByRole(AriaRole.Button, new() { Name = "column 2 button" })})
.ScreenshotAsync(); -
使用新的 Web 优先断言 Expect(Locator).ToBeAttachedAsync() 确保该元素存在于页面的 DOM 中。不要与确保该元素既附加又可见的 Expect(Locator).ToBeVisibleAsync() 混淆。
¥Use new web-first assertion Expect(Locator).ToBeAttachedAsync() to ensure that the element is present in the page's DOM. Do not confuse with the Expect(Locator).ToBeVisibleAsync() that ensures that element is both attached & visible.
新 API
¥New APIs
-
Locator.Filter() 中的新选项 HasNot
¥New option HasNot in Locator.Filter()
-
Locator.Filter() 中的新选项 HasNotText|HasNotTextRegex
¥New option HasNotText|HasNotTextRegex in Locator.Filter()
-
Route.FetchAsync() 中的新选项 超时
¥New option Timeout in Route.FetchAsync()
⚠️ 重大改变
¥⚠️ Breaking change
-
mcr.microsoft.com/playwright/dotnet:v1.33.0
现在提供基于 Ubuntu Jammy 的 Playwright 映像。要使用基于焦点的图片,请改用mcr.microsoft.com/playwright/dotnet:v1.33.0-focal
。¥The
mcr.microsoft.com/playwright/dotnet:v1.33.0
now serves a Playwright image based on Ubuntu Jammy. To use the focal-based image, please usemcr.microsoft.com/playwright/dotnet: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
-
Page.RouteFromHARAsync() 和 BrowserContext.RouteFromHARAsync() 中的新选项 UpdateMode 和 UpdateContent。
¥New options UpdateMode and UpdateContent in Page.RouteFromHARAsync() and BrowserContext.RouteFromHARAsync().
-
链接现有定位器对象,请参阅 定位器文档 了解详细信息。
¥Chaining existing locator objects, see locator docs for details.
-
方法 Tracing.StartChunkAsync() 中的新选项 名称。
¥New option Name in method Tracing.StartChunkAsync().
浏览器版本
¥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).ToBeInViewportAsync() 确保定位器指向与视口相交的元素。
¥New assertion Expect(Locator).ToBeInViewportAsync() ensures that locator points to an element that intersects viewport, according to the intersection observer API.
var locator = Page.GetByRole(AriaRole.Button);
// Make sure at least some part of element intersects viewport.
await Expect(locator).ToBeInViewportAsync();
// Make sure element is fully outside of viewport.
await Expect(locator).Not.ToBeInViewportAsync();
// Make sure that at least half of the element intersects viewport.
await Expect(locator).ToBeInViewportAsync(new() { Ratio = 0.5 }); -
新方法 BrowserContext.NewCDPSessionAsync() 和 Browser.NewBrowserCDPSessionAsync() 分别为页面和浏览器创建 Chrome 开发者工具协议 会话。
¥New methods BrowserContext.NewCDPSessionAsync() and Browser.NewBrowserCDPSessionAsync() create a Chrome DevTools Protocol session for the page and browser respectively.
杂项
¥Miscellaneous
-
现在可以在单独的窗口中打开跟踪查看器中的 DOM 快照。
¥DOM snapshots in trace viewer can be now opened in a separate window.
-
方法 Route.FetchAsync() 的新选项 MaxRedirects。
¥New option MaxRedirects for method Route.FetchAsync().
-
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.FulfillAsync() 的新方法 Route.FetchAsync() 和新选项
Json
:¥New method Route.FetchAsync() and new option
Json
for Route.FulfillAsync():await Page.RouteAsync("**/api/settings", async route => {
// Fetch original settings.
var response = await route.FetchAsync();
// Force settings theme to a predefined value.
var json = await response.JsonAsync<MyDataType>();
json.Theme = "Solarized";
// Fulfill with modified data.
await route.FulfillAsync(new() {
Json = json
});
}); -
用于迭代所有匹配元素的新方法 Locator.AllAsync():
¥New method Locator.AllAsync() to iterate over all matching elements:
// Check all checkboxes!
var checkboxes = Page.GetByRole(AriaRole.Checkbox);
foreach (var checkbox in await checkboxes.AllAsync())
await checkbox.CheckAsync(); -
Locator.SelectOptionAsync() 现在按值或标签匹配:
¥Locator.SelectOptionAsync() matches now by value or label:
<select multiple>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>await element.SelectOptionAsync("Red");
浏览器版本
¥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.
新 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.GetByText() 按文本内容定位。
¥Page.GetByText() to locate by text content.
-
Page.GetByRole() 通过 ARIA 角色、ARIA 属性 和 可访问的名称 定位。
¥Page.GetByRole() to locate by ARIA role, ARIA attributes and accessible name.
-
Page.GetByLabel() 通过关联标签的文本定位表单控件。
¥Page.GetByLabel() to locate a form control by associated label's text.
-
Page.GetByTestId() 根据
data-testid
属性定位元素(可以配置其他属性)。¥Page.GetByTestId() to locate an element based on its
data-testid
attribute (other attribute can be configured). -
Page.GetByPlaceholder() 通过占位符定位输入。
¥Page.GetByPlaceholder() to locate an input by placeholder.
-
Page.GetByAltText() 通过文本替代来定位元素(通常是图片)。
¥Page.GetByAltText() to locate an element, usually image, by its text alternative.
-
Page.GetByTitle() 通过标题定位元素。
¥Page.GetByTitle() to locate an element by its title.
await page.GetByLabel("User Name").FillAsync("John");
await page.GetByLabel("Password").FillAsync("secret-password");
await page.GetByRole(AriaRole.Button, new() { NameString = "Sign in" }).ClickAsync();
await Expect(Page.GetByText("Welcome, John!")).ToBeVisibleAsync();
所有相同的方法也可用于 Locator、FrameLocator 和 Frame 类。
¥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).ToHaveAttributeAsync() 不再与缺失的属性匹配。例如,当
button
没有disabled
属性时,以下代码片段将会成功。¥Expect(Locator).ToHaveAttributeAsync() with an empty value does not match missing attribute anymore. For example, the following snippet will succeed when
button
does not have adisabled
attribute.await Expect(Page.GetByRole(AriaRole.Button)).ToHaveAttributeAsync("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
-
Expect(Locator).ToBeEnabledAsync() 的新选项
Enabled
。¥New option
Enabled
for Expect(Locator).ToBeEnabledAsync(). -
Expect(Locator).ToHaveTextAsync() 现在刺穿开放的暗影根部。
¥Expect(Locator).ToHaveTextAsync() now pierces open shadow roots.
-
Expect(Locator).ToBeEditableAsync() 的新选项
Editable
。¥New option
Editable
for Expect(Locator).ToBeEditableAsync(). -
Expect(Locator).ToBeVisibleAsync() 的新选项
Visible
。¥New option
Visible
for Expect(Locator).ToBeVisibleAsync(). -
Expect(Response).ToBeOKAsync() 现已可用。
¥Expect(Response).ToBeOKAsync() is now available.
其他亮点
¥Other highlights
-
用于 ApiRequestContext.GetAsync() 和其他限制重定向计数的新选项
MaxRedirects
。¥New option
MaxRedirects
for ApiRequestContext.GetAsync() and others to limit redirect count. -
Codegen 现在支持 MSTest 和 NUnit 框架。
¥Codegen now supports MSTest and NUnit frameworks.
-
现在支持 ASP.NET。
¥ASP .NET is now supported.
行为改变
¥Behavior Change
许多 Playwright API 已经支持 WaitUntil: WaitUntilState.DOMContentLoaded
选项。例如:
¥A bunch of Playwright APIs already support the WaitUntil: WaitUntilState.DOMContentLoaded
option. For example:
await Page.GotoAsync("https://playwright.nodejs.cn", new() { WaitUntil = WaitUntilState.DOMContentLoaded });
在 1.26 之前,这将等待所有 iframe 触发 DOMContentLoaded
事件。
¥Prior to 1.26, this would wait for all iframes to fire the DOMContentLoaded
event.
为了与 Web 规范保持一致,WaitUntilState.DOMContentLoaded
值仅等待目标框架触发 'DOMContentLoaded'
事件。使用 WaitUntil: WaitUntilState.Load
等待所有 iframe。
¥To align with web specification, the WaitUntilState.DOMContentLoaded
value only waits for the target frame to fire the 'DOMContentLoaded'
event. Use WaitUntil: WaitUntilState.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
新的 .runsettings 文件支持
¥New .runsettings file support
Microsoft.Playwright.NUnit
和 Microsoft.Playwright.MSTest
现在将在运行端到端测试时考虑 .runsettings
文件并通过 CLI 传递的设置。请参阅 documentation,查看受支持设置的完整列表。
¥Microsoft.Playwright.NUnit
and Microsoft.Playwright.MSTest
will now consider the .runsettings
file and passed settings via the CLI when running end-to-end tests. See in the documentation for a full list of supported settings.
以下代码现在可以正常工作:
¥The following does now work:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Playwright -->
<Playwright>
<BrowserName>chromium</BrowserName>
<ExpectTimeout>5000</ExpectTimeout>
<LaunchOptions>
<Headless>true</Headless>
<Channel>msedge</Channel>
</LaunchOptions>
</Playwright>
<!-- General run configuration -->
<RunConfiguration>
<EnvironmentVariables>
<!-- For debugging selectors, it's recommend to set the following environment variable -->
<DEBUG>pw:api</DEBUG>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
公告
¥Announcements
-
🪦 这是支持 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.04 | Ubuntu 22.04 | Debian 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
API 测试
¥API Testing
Playwright for .NET 1.23 引入了新的 API 测试,可让你直接从 .NET 向服务器发送请求!现在你可以:
¥Playwright for .NET 1.23 introduces new API Testing that lets you send requests to the server directly from .NET! 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.APIRequest API:
¥To do a request on behalf of Playwright's Page, use new Page.APIRequest API:
// Do a GET request on behalf of page
var response = await Page.APIRequest.GetAsync("http://example.com/foo.json");
Console.WriteLine(response.Status);
Console.WriteLine(response.StatusText);
Console.WriteLine(response.Ok);
Console.WriteLine(response.Headers["Content-Type"]);
Console.WriteLine(await response.TextAsync());
Console.WriteLine((await response.JsonAsync())?.GetProperty("foo").GetString());
在我们的 API 测试指南 中了解更多相关信息。
¥Read more about it in our API testing guide.
网络重播
¥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:
pwsh bin/Debug/netX/playwright.ps1 open --save-har=example.har --save-har-glob="**/api/**" https://example.com
或者,你可以通过编程方式记录 HAR:
¥Alternatively, you can record HAR programmatically:
var context = await browser.NewContextAsync(new()
{
RecordHarPath = harPath,
RecordHarUrlFilterString = "**/api/**",
});
// ... Perform actions ...
// Close context to ensure HAR is saved to disk.
context.CloseAsync();
使用新方法 Page.RouteFromHARAsync() 或 BrowserContext.RouteFromHARAsync() 提供来自 HAR 文件的匹配响应:
¥Use the new methods Page.RouteFromHARAsync() or BrowserContext.RouteFromHARAsync() to serve matching responses from the HAR file:
await context.RouteFromHARAsync("example.har");
阅读 我们的文档 中的更多内容。
¥Read more in our documentation.
高级路由
¥Advanced Routing
你现在可以使用 Route.FallbackAsync() 推迟路由到其他处理程序。
¥You can now use Route.FallbackAsync() to defer routing to other handlers.
考虑以下示例:
¥Consider the following example:
// Remove a header from all requests.
await page.RouteAsync("**/*", async route =>
{
var headers = route.Request.Headers;
headers.Remove("X-Secret");
await route.ContinueAsync(new() { Headers = headers });
});
// Abort all images.
await page.RouteAsync("**/*", async route =>
{
if (route.Request.ResourceType == "image")
{
await route.AbortAsync();
}
else
{
await route.FallbackAsync();
}
});
请注意,新方法 Page.RouteFromHARAsync() 和 BrowserContext.RouteFromHARAsync() 也参与路由并且可以推迟。
¥Note that the new methods Page.RouteFromHARAsync() and BrowserContext.RouteFromHARAsync() also participate in routing and could be deferred to.
Web 优先断言更新
¥Web-First Assertions Update
-
新方法 Expect(Locator).ToHaveValuesAsync() 断言
<select multiple>
元素的所有选定值。¥New method Expect(Locator).ToHaveValuesAsync() that asserts all selected values of
<select multiple>
element. -
方法 Expect(Locator).ToContainTextAsync() 和 Expect(Locator).ToHaveTextAsync() 现在接受
ignoreCase
选项。¥Methods Expect(Locator).ToContainTextAsync() and Expect(Locator).ToHaveTextAsync() now accept
ignoreCase
option.
杂项
¥Miscellaneous
-
如果有一个 Service Worker 挡住了你的路,你现在可以使用新的上下文选项
serviceWorkers
轻松禁用它:¥If there's a service worker that's in your way, you can now easily disable it with a new context option
serviceWorkers
:var context = await Browser.NewContextAsync(new()
{
ServiceWorkers = ServiceWorkerPolicy.Block
}); -
使用
.zip
路径作为recordHar
上下文选项会自动压缩生成的 HAR:¥Using
.zip
path forrecordHar
context option automatically zips the resulting HAR:var context = await Browser.NewContextAsync(new() { RecordHarPath = "example.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:var context = await Browser.NewContextAsync(new() { RecordHarPath = "example.har", RecordHarMode = HarMode.Minimal });
-
Playwright 现在可以在 Ubuntu 22 amd64 和 Ubuntu 22 arm64 上运行。
¥Playwright now runs on Ubuntu 22 amd64 and Ubuntu 22 arm64.
-
Playwright for .NET 现在支持 linux-arm64,并为其提供了一个 arm64 Ubuntu 20.04 Docker 镜像。
¥Playwright for .NET now supports linux-arm64 and provides a arm64 Ubuntu 20.04 Docker image for it.
1.22 版本
¥Version 1.22
高亮
¥Highlights
-
允许按 ARIA 角色、ARIA 属性 和 可访问的名称 选择元素的角色选择器。
¥Role selectors that allow selecting elements by their ARIA role, ARIA attributes and accessible name.
// Click a button with accessible name "log in"
await page.Locator("role=button[name='log in']").ClickAsync();阅读 我们的文档 中的更多内容。
¥Read more in our documentation.
-
用于过滤现有定位器的新 Locator.Filter() API
¥New Locator.Filter() API to filter an existing locator
var buttons = page.Locator("role=button");
// ...
var submitLocator = buttons.Filter(new() { HasText = "Sign up" });
await submitLocator.ClickAsync();
1.21 版本
¥Version 1.21
高亮
¥Highlights
-
新的角色选择器允许通过 ARIA 角色、ARIA 属性 和 可访问的名称 选择元素。
¥New role selectors that allow selecting elements by their ARIA role, ARIA attributes and accessible name.
// Click a button with accessible name "log in"
await page.Locator("role=button[name='log in']").ClickAsync();阅读 我们的文档 中的更多内容。
¥Read more in our documentation.
-
Page.ScreenshotAsync() 中的新
scale
选项适用于较小尺寸的屏幕截图。¥New
scale
option in Page.ScreenshotAsync() for smaller sized screenshots. -
Page.ScreenshotAsync() 中的新
caret
选项用于控制文本插入符。默认为"hide"
。¥New
caret
option in Page.ScreenshotAsync() to control text caret. Defaults to"hide"
. -
我们现在提供指定的 .NET Docker 镜像
mcr.microsoft.com/playwright/dotnet
。阅读 我们的文档 中的更多内容。¥We now ship a designated .NET docker image
mcr.microsoft.com/playwright/dotnet
. Read more in our documentation.
行为改变
¥Behavior Changes
-
Playwright 现在支持通过 Locator.SetInputFilesAsync() API 上传大文件(数百 MB)。
¥Playwright now supports large file uploads (100s of MBs) via Locator.SetInputFilesAsync() 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
Web 优先断言
¥Web-First Assertions
Playwright for .NET 1.20 引入了 Web 优先断言。
¥Playwright for .NET 1.20 introduces Web-First Assertions.
考虑以下示例:
¥Consider the following example:
using System.Threading.Tasks;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;
namespace PlaywrightTests;
[TestFixture]
public class ExampleTests : PageTest
{
[Test]
public async Task StatusBecomesSubmitted()
{
await Expect(Page.Locator(".status")).ToHaveTextAsync("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.
其他更新
¥Other Updates
-
方法 Page.ScreenshotAsync()、Locator.ScreenshotAsync() 和 ElementHandle.ScreenshotAsync() 的新选项:
¥New options for methods Page.ScreenshotAsync(), Locator.ScreenshotAsync() and ElementHandle.ScreenshotAsync():
-
选项
ScreenshotAnimations.Disabled
倒回所有 CSS 动画并转换到一致的状态¥Option
ScreenshotAnimations.Disabled
rewinds all CSS animations and transitions to a consistent state -
选项
mask: Locator[]
屏蔽给定元素,用粉红色#FF00FF
框覆盖它们。¥Option
mask: Locator[]
masks given elements, overlaying them with pink#FF00FF
boxes.
-
-
Locator.HighlightAsync() 直观地显示元素以便于调试。
¥Locator.HighlightAsync() visually reveals element(s) for easier debugging.
公告
¥Announcements
-
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:await Page.Locator("article", new() { Has = Page.Locator(".highlight") }).ClickAsync();
阅读 定位器文档 的更多内容
¥Read more in locator documentation
-
¥New Locator.Page
-
Page.ScreenshotAsync() 和 Locator.ScreenshotAsync() 现在自动隐藏闪烁的插入符号
¥Page.ScreenshotAsync() and Locator.ScreenshotAsync() 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
定位器改进
¥Locator Improvements
-
现在可以选择通过每个定位器包含的文本来过滤每个定位器:
¥Each locator can now be optionally filtered by the text it contains:
await Page.Locator("li", new() { HasTextString = "My Item" })
.Locator("button").click();阅读 定位器文档 的更多内容
¥Read more in locator documentation
新的 API 和更改
¥New APIs & changes
-
AcceptDownloads
选项现在默认为true
。¥
AcceptDownloads
option now defaults totrue
. -
用于将源代码嵌入到跟踪中的
Sources
选项。¥
Sources
option to embed sources into traces.
浏览器版本
¥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.
帧定位器可以使用 Page.FrameLocator() 或 Locator.FrameLocator() 方法创建。
¥Frame locators can be created with either Page.FrameLocator() or Locator.FrameLocator() method.
var locator = page.FrameLocator("#my-frame").Locator("text=Submit");
await locator.ClickAsync();
欲了解更多内容,请访问 我们的文档。
¥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
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.
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:
pwsh bin/Debug/netX/playwright.ps1 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.WaitForAsync
等待定位器解析为具有给定状态的单个元素。默认为 state: 'visible'
。
¥Wait for a locator to resolve to a single element with a given state. Defaults to the state: 'visible'
.
var orderSent = page.Locator("#order-sent");
orderSent.WaitForAsync();
了解有关 Locator.WaitForAsync() 的更多信息。
¥Read more about Locator.WaitForAsync().
🎭 Playwright 踪迹查看器
¥🎭 Playwright Trace Viewer
-
使用
pwsh bin/Debug/netX/playwright.ps1 show-trace
运行跟踪查看器并将跟踪文件拖放到跟踪查看器 PWA¥run trace viewer with
pwsh bin/Debug/netX/playwright.ps1 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.WheelAsync(),你现在可以垂直或水平滚动。
¥By using Mouse.WheelAsync() 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.NewContextAsync() 中传递或调用 Page.EmulateMediaAsync() 来模拟 forced-colors
CSS 媒体功能。
¥Its now possible to emulate the forced-colors
CSS media feature by passing it in the Browser.NewContextAsync() or calling Page.EmulateMediaAsync().
新 API
¥New APIs
-
Page.RouteAsync() 接受新的
times
选项来指定该路由应匹配的次数。¥Page.RouteAsync() accepts new
times
option to specify how many times this route should be matched. -
引入 Page.SetCheckedAsync() 和 Locator.SetCheckedAsync() 是为了设置复选框的选中状态。
¥Page.SetCheckedAsync() and Locator.SetCheckedAsync() were introduced to set the checked state of a checkbox.
-
Request.SizesAsync() 返回给定 http 请求的资源大小信息。
¥Request.SizesAsync() Returns resource size information for given http request.
-
Tracing.StartChunkAsync() - 开始一个新的跟踪块。
¥Tracing.StartChunkAsync() - Start a new trace chunk.
-
Tracing.StopChunkAsync() - 停止新的跟踪块。
¥Tracing.StopChunkAsync() - Stops a new trace chunk.
重要 ⚠
¥Important ⚠
-
⬆ 我们的 CLI 工具不再支持 .NET Core Apps 2.1。截至 2021 年 8 月 31 日,.NET Core 2.1 不再是 不再支持,不会收到任何安全更新。我们已决定改进 CLI,并要求至少使用 .NET Core 3.1 版本。
¥⬆ .NET Core Apps 2.1 are no longer supported for our CLI tooling. As of August 31st, 2021, .NET Core 2.1 is no longer supported and will not receive any security updates. We've decided to move the CLI forward and require .NET Core 3.1 as a minimum.
浏览器版本
¥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.
在你的操作调用中设置 setStrict(true)
以选择加入。
¥Set setStrict(true)
in your action calls to opt in.
// This will throw if you have more than one button!
await page.Locator("button", new() { 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.
Locator 和 ElementHandle 之间的区别在于后者指向特定元素,而 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!
var locator = page.Locator("button");
await locator.ClickAsync();
在 documentation 中了解更多信息。
¥Learn more in the documentation.
🧩 实验性 React 和 Vue 选择器引擎
¥🧩 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.
await page.Locator("_react=SubmitButton[enabled=true]").ClickAsync();
await page.Locator("_vue=submit-button[enabled=true]").ClickAsync();
在 反应选择器文档 和 vue 选择器文档 中了解更多信息。
¥Learn more in the react selectors documentation and the vue selectors documentation.
✨ 新的 nth
和 visible
选择器引擎
¥✨ 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
await button.ClickAsync("button >> nth=0");
// or if you are using locators, you can use First, Nth() and Last
await page.Locator("button").First.ClickAsync();
// click a visible button
await button.ClickAsync("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
-
🖖 通过 Page.DragAndDropAsync() API 提供编程式拖放支持。
¥🖖 Programmatic drag-and-drop support via the Page.DragAndDropAsync() API.
-
🔎 增强型 HAR,具有请求和响应的正文大小。通过 Browser.NewContextAsync() 中的
recordHar
选项使用。¥🔎 Enhanced HAR with body sizes for requests and responses. Use via
recordHar
option in Browser.NewContextAsync().
工具
¥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
-
Browser.NewContextAsync() 和 Browser.NewPageAsync() 中的新
baseURL
选项¥new
baseURL
option in Browser.NewContextAsync() and Browser.NewPageAsync() -
Response.SecurityDetailsAsync() 和 Response.ServerAddrAsync()
¥Response.SecurityDetailsAsync() and Response.ServerAddrAsync()
-
Page.InputValueAsync()、Frame.InputValueAsync() 和 ElementHandle.InputValueAsync()
¥Page.InputValueAsync(), Frame.InputValueAsync() and ElementHandle.InputValueAsync()
-
Page.FillAsync()、Frame.FillAsync() 和 ElementHandle.FillAsync() 中的新
force
选项¥new
force
option in Page.FillAsync(), Frame.FillAsync(), and ElementHandle.FillAsync() -
Page.SelectOptionAsync()、Frame.SelectOptionAsync() 和 ElementHandle.SelectOptionAsync() 中的新
force
选项¥new
force
option in Page.SelectOptionAsync(), Frame.SelectOptionAsync(), and ElementHandle.SelectOptionAsync()
1.12 版本
¥Version 1.12
高亮
¥Highlights
-
Playwright for .NET v1.12 现已稳定!
¥Playwright for .NET v1.12 is now stable!
-
¥Ships with the codegen and trace viewer tools out-of-the-box
浏览器版本
¥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