發行說明
版本 1.55
錄製測試
- 自動
ToBeVisibleAsync()
斷言:Codegen 現在可以為常見的 UI 互動產生自動ToBeVisibleAsync()
斷言。此功能可以在 Codegen 設定 UI 中啟用。
重大變更
- ⚠️ 已移除對 Chromium 擴充功能 manifest v2 的支援。
其他
- 新增對 Debian 13 "Trixie" 的支援。
- 新增對 Xunit v3 的支援,作為
Microsoft.Playwright.Xunit.v3
的一部分 - 新增對 MSTest v4 的支援,作為
Microsoft.Playwright.MSTest.v4
的一部分
瀏覽器版本
- Chromium 140.0.7339.16
- Mozilla Firefox 141.0
- WebKit 26.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 139
- Microsoft Edge 139
版本 1.54
重點
-
在 BrowserContext.CookiesAsync() 和 BrowserContext.AddCookiesAsync() 中新增 cookie 屬性
PartitionKey
。此屬性允許儲存和還原分割的 cookies。請參閱 CHIPS MDN 文章 以取得更多資訊。請注意,瀏覽器對 cookie 分割有不同的支援和預設值。 -
在多個指令中新增選項
--user-data-dir
。您可以指定相同的使用者資料目錄來重複使用瀏覽狀態,例如驗證,在不同的會話之間。pwsh bin/Debug/netX/playwright.ps1 codegen --user-data-dir=./user-data
-
pwsh bin/Debug/netX/playwright.ps1 open
不再開啟測試錄製器。請改用pwsh bin/Debug/netX/playwright.ps1 codegen
。
瀏覽器版本
- Chromium 139.0.7258.5
- Mozilla Firefox 140.0.2
- WebKit 26.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 140
- Microsoft Edge 140
版本 1.53
追蹤檢視器和 HTML 報告器更新
-
追蹤檢視器中的新步驟:
-
新方法 Locator.Describe() 用於描述定位器,在追蹤檢視器中使用。
var button = Page.GetByTestId("btn-sub").Describe("Subscribe button");
await button.ClickAsync(); -
pwsh bin/Debug/netX/playwright.ps1 install --list
現在會列出所有已安裝的瀏覽器、版本和位置。
瀏覽器版本
- Chromium 138.0.7204.4
- Mozilla Firefox 139.0
- WebKit 18.5
此版本也對以下穩定頻道進行了測試:
- Google Chrome 137
- Microsoft Edge 137
版本 1.52
重點
-
新方法 Expect(Locator).ToContainClassAsync() 用於人體工學地斷言元素上的個別類別名稱。
await Expect(Page.GetByRole(AriaRole.Listitem, new() { Name = "Ship v1.52" })).ToContainClassAsync("done");
-
Aria Snapshots 獲得兩個新屬性:
/children
用於嚴格匹配和/url
用於連結。await Expect(locator).ToMatchAriaSnapshotAsync(@"
- list
- /children: equal
- listitem: Feature A
- listitem:
- link ""Feature B"":
- /url: ""https://playwright.dev""
");
其他
- ApiRequest.NewContextAsync() 中的新選項 MaxRedirects 用於控制重定向的最大次數。
重大變更
- Page.RouteAsync() 等方法中的 Glob URL 模式不再支援
?
和[]
。我們建議改用正規表示式。 - 方法 Route.ContinueAsync() 不再允許覆寫
Cookie
標頭。如果提供了Cookie
標頭,它將被忽略,cookie 將從瀏覽器的 cookie 儲存區載入。若要設定自訂 cookie,請使用 BrowserContext.AddCookiesAsync()。 - macOS 13 現已棄用,將不再接收 WebKit 更新。請升級到更新的 macOS 版本以繼續受益於最新的 WebKit 改進。
瀏覽器版本
- Chromium 136.0.7103.25
- Mozilla Firefox 137.0
- WebKit 18.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 135
- Microsoft Edge 135
版本 1.51
重點
-
新選項 IndexedDB 用於 BrowserContext.StorageStateAsync() 允許儲存和還原 IndexedDB 內容。當您的應用程式使用 IndexedDB API 儲存身份驗證權杖(如 Firebase Authentication)時很有用。
以下是遵循身份驗證指南的範例:
// 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"
}); -
新選項 Visible 用於 Locator.Filter() 允許只匹配可見元素。
// 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); -
新選項
Contrast
用於方法 Page.EmulateMediaAsync() 和 Browser.NewContextAsync() 允許模擬prefers-contrast
媒體功能。 -
新選項 FailOnStatusCode 讓所有透過 APIRequestContext 發出的 fetch 請求在回應代碼不是 2xx 和 3xx 時拋出例外。
瀏覽器版本
- Chromium 134.0.6998.35
- Mozilla Firefox 135.0
- WebKit 18.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 133
- Microsoft Edge 133
版本 1.50
支援Xunit
- 透過 Microsoft.Playwright.Xunit 支援xUnit 2.8+。請參考我們的開始使用指南以了解更多。
其他
- Added 方法 Expect(Locator).ToHaveAccessibleErrorMessageAsync() to assert the Locator points to an element with a given aria errormessage.
UI 更新
- Codegen 中用於選取元素以產生 aria 快照的新按鈕。
- 其他詳細資訊(如按下的按鍵)現在會與追蹤中的動作 API 呼叫一起顯示。
- 在追蹤中顯示
canvas
內容容易出錯。顯示功能現在預設停用,可透過Display canvas content
UI 設定啟用。 Call
和Network
面板現在顯示其他時間資訊。
重大變更
- Expect(Locator).ToBeEditableAsync() 和 Locator.IsEditableAsync() 現在在目標元素不是
<input>
、<select>
或其他可編輯元素時會拋出例外。
瀏覽器版本
- Chromium 133.0.6943.16
- Mozilla Firefox 134.0
- WebKit 18.2
此版本也對以下穩定頻道進行了測試:
- Google Chrome 132
- Microsoft Edge 132
版本 1.49
Aria 快照
新斷言 Expect(Locator).ToMatchAriaSnapshotAsync() 透過與預期的無障礙樹狀結構(以 YAML 表示)進行比較來驗證頁面結構。
await page.GotoAsync("https://playwright.dev");
await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(@"
- banner:
- heading /Playwright enables reliable/ [level=1]
- link ""開始使用""
- link ""Star microsoft/playwright on GitHub""
- main:
- img ""Browsers (Chromium, Firefox, WebKit)""
- heading ""Any browser • Any platform • One API""
");
您可以使用 測試產生器 或呼叫 Locator.AriaSnapshotAsync() 來產生此斷言。
在 aria 快照指南 中了解更多。
追蹤群組
新方法 Tracing.GroupAsync() 允許您在追蹤檢視器中視覺化地群組動作。
// 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.dev/");
await Page.GetByRole(AriaRole.Link, new() { Name = "API" }).ClickAsync();
await Page.Context.Tracing.GroupEndAsync();
Breaking: chrome
和 msedge
頻道切換到新的無頭模式
如果您在 playwright.config.ts
中使用以下任一頻道,此變更會影響您:
chrome
,chrome-dev
,chrome-beta
, orchrome-canary
msedge
,msedge-dev
,msedge-beta
, ormsedge-canary
更新到 Playwright v1.49 後,執行您的測試套件。如果仍然通過,您就可以繼續使用。如果不是,您可能需要更新您的快照,並調整一些關於 PDF 檢視器和擴充功能的測試程式碼。 請參閱...以取得更多詳細資訊.
嘗試新的 Chromium 無頭模式
您可以透過使用 'chromium'
頻道選擇新的無頭模式。如 官方 Chrome 文件所述:
另一方面,新的無頭模式是真正的 Chrome 瀏覽器,因此更真實、可靠,並提供更多功能。這使其更適合高精度的端到端網頁應用程式測試或瀏覽器擴充功能測試。
請參閱 issue #33566 以查看您可能遇到的破壞性變更清單以及有關 Chromium headless 的更多詳細資訊。如果您在選擇加入後看到任何問題,請提交 issue。
<?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
其他
- Ubuntu 20.04 和 Debian 11 上的 WebKit 將不再有更新。我們建議將您的作業系統更新到較新版本。
<canvas>
元素在快照內現在會繪製預覽。
瀏覽器版本
- Chromium 131.0.6778.33
- Mozilla Firefox 132.0
- WebKit 18.2
此版本也對以下穩定頻道進行了測試:
- Google Chrome 130
- Microsoft Edge 130
版本 1.48
WebSocket 路由
新方法s Page.RouteWebSocketAsync() 和 BrowserContext.RouteWebSocketAsync() 允許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 以取得更多詳細資訊。
UI 更新
- HTML 報告中註釋和測試位置的新「複製」按鈕。
- 路由方法呼叫(如 Route.FulfillAsync())不再顯示在報告和追蹤檢視器中。您可以在網路標籤中查看哪些網路請求被路由。
- 網路標籤中請求的新「複製為 cURL」和「複製為 fetch」按鈕。
其他
- 新方法 Page.RequestGCAsync() may help detect memory leaks.
- APIRequestContext 發出的請求現在在 HAR 中記錄詳細的時間和安全資訊。
瀏覽器版本
- Chromium 130.0.6723.19
- Mozilla Firefox 130.0
- WebKit 18.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 129
- Microsoft Edge 129
版本 1.47
網路分頁改進
追蹤檢視器中的網路頁籤有幾項不錯的改進:
- filtering by asset type and URL
- better display of query string parameters
- preview of font assets
其他
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
。- Playwright Docker 映像的
:latest
/:focal
/:jammy
標籤不再發布。請固定到特定版本以獲得更好的穩定性和可重現性。 - TLS 用戶端憑證現在可以透過傳遞 ClientCertificates.Cert 和 ClientCertificates.Key 作為位元組陣列而非檔案路徑從記憶體傳遞。
- Locator.SelectOptionAsync() 中的 NoWaitAfter 已被棄用。
- 我們已看到 WebKit 中的 WebGL 在 GitHub Actions
macos-13
上運作異常的回報。我們建議將 GitHub Actions 升級到macos-14
。
瀏覽器版本
- Chromium 129.0.6668.29
- Mozilla Firefox 130.0
- WebKit 18.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 128
- Microsoft Edge 128
版本 1.46
TLS Client Certificates
Playwright 現在允許提供用戶端憑證,以便伺服器可以根據 TLS 用戶端驗證的規定來驗證它們。
您可以將用戶端憑證作為 Browser.NewContextAsync() 和 ApiRequest.NewContextAsync() 的參數提供。以下程式碼片段設定 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",
}
]
});
追蹤檢視器更新
- 文字附件的內容現在會在附件窗格中內嵌呈現。
- 新設定以顯示/隱藏路由動作,如 Route.ContinueAsync()。
- Request 方法 and status are shown in the network details tab.
- 複製源檔案位置到剪貼簿的新按鈕。
- Metadata pane 現在顯示
BaseURL
。
其他
- ApiRequestContext.FetchAsync() 中的新
maxRetries
選項,在ECONNRESET
網路錯誤時重試。
瀏覽器版本
- Chromium 128.0.6613.18
- Mozilla Firefox 128.0
- WebKit 18.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 127
- Microsoft Edge 127
版本 1.45
時鐘
利用新的 Clock API 允許在測試中操控和控制時間以驗證與時間相關的行為。此 API 涵蓋許多常見場景,包括:
- 使用預定義的時間進行測試;
- 保持一致的時間和計時器;
- 監控不活動;
- 手動推進時間。
// 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");
請參閱 時鐘指南 以取得更多詳細資訊。
其他
-
方法 Locator.SetInputFilesAsync() 現在支援uploading a directory for
<input type=file webkitdirectory>
elements.await page.GetByLabel("Upload directory").SetInputFilesAsync("mydir");
-
多個方法(如 Locator.ClickAsync() or Locator.PressAsync() 現在支援a
ControlOrMeta
modifier key. 此鍵 對應到Meta
on macOS and 對應到Control
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"); -
新屬性
httpCredentials.send
在 ApiRequest.NewContextAsync() 中,允許永遠傳送Authorization
標頭或僅在回應401 Unauthorized
時傳送。 -
Playwright 現在支援在 Ubuntu 24.04 上的 Chromium、Firefox 和 WebKit。
-
v1.45是最後一個接收receive WebKit update for macOS 12 Monterey. 請更新macOS以繼續使用the latest WebKit.
瀏覽器版本
- Chromium 127.0.6533.5
- Mozilla Firefox 127.0
- WebKit 17.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 126
- Microsoft Edge 126
版本 1.44
新的 API
無障礙斷言
-
Expect(Locator).ToHaveAccessibleNameAsync() 檢查元素是否具有指定的無障礙名稱:
var locator = Page.GetByRole(AriaRole.Button);
await Expect(locator).ToHaveAccessibleNameAsync("Submit"); -
Expect(Locator).ToHaveAccessibleDescriptionAsync() 檢查元素是否具有指定的無障礙描述:
var locator = Page.GetByRole(AriaRole.Button);
await Expect(locator).ToHaveAccessibleDescriptionAsync("Upload a photo"); -
Expect(Locator).ToHaveRoleAsync() 檢查元素是否具有指定的 ARIA 角色:
var locator = Page.GetByTestId("save-button");
await Expect(locator).ToHaveRoleAsync(AriaRole.Button);
定位器處理器
- 執行透過 Page.AddLocatorHandlerAsync() 新增的處理器後,Playwright 現在會等待直到觸發處理器的覆蓋層不再可見。您可以使用新的
NoWaitAfter
選項來選擇退出此行為。 - 您可以在 Page.AddLocatorHandlerAsync() 中使用新的
Times
選項來指定處理器應執行的最大次數。 - Page.AddLocatorHandlerAsync() 中的處理器現在接受定位器作為參數。
- 新的 Page.RemoveLocatorHandlerAsync() 方法用於移除先前新增的定位器處理器。
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 });
// 執行可能被覆蓋層中斷的測試。
// ...
await Page.RemoveLocatorHandlerAsync(locator);
其他選項
-
新方法 FormData.Append() 允許在
APIRequestContext.FetchAsync()
的Multipart
選項中指定相同名稱的重複欄位: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
選項.
瀏覽器版本
- Chromium 125.0.6422.14
- Mozilla Firefox 125.0.1
- WebKit 17.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 124
- Microsoft Edge 124
版本 1.43
新的 API
-
方法 BrowserContext.ClearCookiesAsync() 現在支援篩選器 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 物件,然後想要與框架內的內容互動時,這會很有用。
var locator = Page.Locator("iframe[name='embedded']");
// ...
var frameLocator = locator.ContentFrame;
await frameLocator.GetByRole(AriaRole.Button).ClickAsync(); -
新屬性 FrameLocator.Owner 將 FrameLocator 物件轉換為 Locator。當您在某處獲得 FrameLocator 物件,然後想要與
iframe
元素互動時,這會很有用。var frameLocator = page.FrameLocator("iframe[name='embedded']");
// ...
var locator = frameLocator.Owner;
await Expect(locator).ToBeVisibleAsync();
瀏覽器版本
- Chromium 124.0.6367.8
- Mozilla Firefox 124.0
- WebKit 17.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 123
- Microsoft Edge 123
版本 1.42
新的定位器處理器
新方法 Page.AddLocatorHandlerAsync() 註冊一個回呼函數,當指定元素變為可見且可能阻擋 Playwright 動作時會被調用。回呼函數可以移除覆蓋層。以下是一個當 cookie 對話框出現時關閉它的範例。
// 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
- Page.PdfAsync() 接受兩個新選項 Tagged 和 Outline。
公告
- ⚠️ 不再支援Ubuntu 18。
瀏覽器版本
- Chromium 123.0.6312.4
- Mozilla Firefox 123.0
- WebKit 17.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 122
- Microsoft Edge 123
版本 1.41
新的 API
- 新方法 Page.UnrouteAllAsync() 移除由 Page.RouteAsync() 和 Page.RouteFromHARAsync() 註冊的所有路由。可選擇等待進行中的路由完成,或忽略來自它們的任何錯誤。
- 新方法 BrowserContext.UnrouteAllAsync() 移除由 BrowserContext.RouteAsync() 和 BrowserContext.RouteFromHARAsync() 註冊的所有路由。可選擇等待進行中的路由完成,或忽略來自它們的任何錯誤。
- 新選項s Style in Page.ScreenshotAsync() 和 Style in Locator.ScreenshotAsync()以新增custom CSS to the page在執行...之前a screenshot.
瀏覽器版本
- Chromium 121.0.6167.57
- Mozilla Firefox 121.0
- WebKit 17.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 120
- Microsoft Edge 120
版本 1.40
測試產生器更新
新的產生斷言工具:
- "Assert visibility" 工具產生 Expect(Locator).ToBeVisibleAsync()。
- "Assert value" 工具產生 Expect(Locator).ToHaveValueAsync()。
- "Assert text" 工具產生 Expect(Locator).ToContainTextAsync()。
以下是產生的測試與斷言範例:
await Page.GotoAsync("https://playwright.dev/");
await Page.GetByRole(AriaRole.Link, new() { Name = "開始使用" }).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
- Options Reason in Page.CloseAsync(), Reason in BrowserContext.CloseAsync() 和 Reason in Browser.CloseAsync(). Close reason is reported for all operations interrupted by the closure.
- 選項 FirefoxUserPrefs in BrowserType.LaunchPersistentContextAsync().
其他變更
- Methods Download.PathAsync() 和 Download.CreateReadStreamAsync() throw an error for failed and cancelled downloads.
- Playwright docker image現在comes with .NET 8 (new LTS).
瀏覽器版本
- Chromium 120.0.6099.28
- Mozilla Firefox 119.0
- WebKit 17.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 119
- Microsoft Edge 119
版本 1.39
長青瀏覽器更新。
瀏覽器版本
- Chromium 119.0.6045.9
- Mozilla Firefox 118.0.1
- WebKit 17.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 118
- Microsoft Edge 118
版本 1.38
追蹤檢視器更新
- 放大到時間範圍。
- 網路面板重新設計。
新的 API
棄用
- 以下方法已棄用:Page.TypeAsync()、Frame.TypeAsync()、Locator.TypeAsync() 和 ElementHandle.TypeAsync()。請改用速度更快的 Locator.FillAsync()。只有在頁面有特殊的鍵盤處理需求,需要逐一按鍵時,才使用 Locator.PressSequentiallyAsync()。
瀏覽器版本
- Chromium 117.0.5938.62
- Mozilla Firefox 117.0
- WebKit 17.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 116
- Microsoft Edge 116
版本 1.37
📚 Debian 12 Bookworm 支援
Playwright 現在支援 Debian 12 Bookworm 在 x86_64 和 arm64 上的 Chromium、Firefox 和 WebKit。如果您遇到任何問題,請告訴我們!
Linux 支援如下:
Ubuntu 20.04 | Ubuntu 22.04 | Debian 11 | Debian 12 | |
---|---|---|---|---|
Chromium | ✅ | ✅ | ✅ | ✅ |
WebKit | ✅ | ✅ | ✅ | ✅ |
Firefox | ✅ | ✅ | ✅ | ✅ |
瀏覽器版本
- Chromium 116.0.5845.82
- Mozilla Firefox 115.0
- WebKit 17.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 115
- Microsoft Edge 115
版本 1.36
🏝️ 夏季維護版本。
瀏覽器版本
- Chromium 115.0.5790.75
- Mozilla Firefox 115.0
- WebKit 17.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 114
- Microsoft Edge 114
版本 1.35
重點
-
新選項
MaskColor
用於方法Page.ScreenshotAsync() 和 Locator.ScreenshotAsync() 以變更預設遮罩顏色。 -
新的
uninstall
CLI 命令用於解除安裝瀏覽器二進位檔:$ 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
瀏覽器版本
- Chromium 115.0.5790.13
- Mozilla Firefox 113.0
- WebKit 16.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 114
- Microsoft Edge 114
版本 1.34
重點
-
新的 Locator.And() 用於建立符合兩個定位器的定位器。
var button = page.GetByRole(AriaRole.BUTTON).And(page.GetByTitle("Subscribe"));
-
新事件 BrowserContext.Console 和 BrowserContext.Dialog 用於訂閱來自給定瀏覽器上下文中任何頁面的對話框和主控台訊息。使用新方法 ConsoleMessage.Page 和 Dialog.Page 精確定位事件來源。
瀏覽器版本
- Chromium 114.0.5735.26
- Mozilla Firefox 113.0
- WebKit 16.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 113
- Microsoft Edge 113
版本 1.33
定位器更新
-
使用 Locator.Or() 建立符合兩個定位器其中之一的定位器。考慮這樣的場景:您想要點選「New email」按鈕,但有時會出現安全設定對話框。在這種情況下,您可以等待「New email」按鈕或對話框,並相應地採取行動:
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 來尋找不符合特定條件的元素。
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(); -
使用新的網頁優先斷言 Expect(Locator).ToBeAttachedAsync() 確保元素存在於頁面的 DOM 中。不要與 Expect(Locator).ToBeVisibleAsync() 混淆,後者確保元素既附加又可見。
新的 API
- Locator.Or()
- 新選項 HasNot in Locator.Filter()
- 新選項 HasNotText|HasNotTextRegex in Locator.Filter()
- Expect(Locator).ToBeAttachedAsync()
- 新選項 Timeout in Route.FetchAsync()
⚠️ 重大變更
mcr.microsoft.com/playwright/dotnet:v1.33.0
現在提供基於 Ubuntu Jammy 的 Playwright 映像。若要使用基於 focal 的映像,請改用mcr.microsoft.com/playwright/dotnet:v1.33.0-focal
。
瀏覽器版本
- Chromium 113.0.5672.53
- Mozilla Firefox 112.0
- WebKit 16.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 112
- Microsoft Edge 112
版本 1.32
新的 API
- 新選項s UpdateMode 和 UpdateContent in Page.RouteFromHARAsync() 和 BrowserContext.RouteFromHARAsync().
- Chaining existing locator objects, see locator docs for details.
- 新選項 Name in 方法 Tracing.StartChunkAsync().
瀏覽器版本
- Chromium 112.0.5615.29
- Mozilla Firefox 111.0
- WebKit 16.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 111
- Microsoft Edge 111
版本 1.31
新的 API
-
新的斷言 Expect(Locator).ToBeInViewportAsync() 確保定位器指向與視埠相交的元素,根據交集觀察器 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 }); -
新方法s BrowserContext.NewCDPSessionAsync() 和 Browser.NewBrowserCDPSessionAsync() create a Chrome DevTools Protocol session for the page and browser respectively.
其他
- 追蹤檢視器中的 DOM 快照現在可以在單獨的視窗中開啟。
- 新選項 MaxRedirects 用於方法 Route.FetchAsync().
- Playwright 現在支援 Debian 11 arm64.
- Official docker images現在include Node 18 instead of Node 16.
瀏覽器版本
- Chromium 111.0.5563.19
- Mozilla Firefox 109.0
- WebKit 16.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 110
- Microsoft Edge 110
版本 1.30
瀏覽器版本
- Chromium 110.0.5481.38
- Mozilla Firefox 108.0.2
- WebKit 16.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 109
- Microsoft Edge 109
版本 1.29
新的 API
-
新方法 Route.FetchAsync() 和新選項
Json
用於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() 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() matches現在by value or label:
<select multiple>
<選項 value="red">Red</選項>
<選項 value="green">Green</選項>
<選項 value="blue">Blue</選項>
</select>await element.SelectOptionAsync("Red");
瀏覽器版本
- Chromium 109.0.5414.46
- Mozilla Firefox 107.0
- WebKit 16.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 108
- Microsoft Edge 108
版本 1.28
Playwright 工具
- CodeGen 中的即時定位器。 使用「探索」工具為頁面上的任何元素產生定位器。
新的 API
瀏覽器版本
- Chromium 108.0.5359.29
- Mozilla Firefox 106.0
- WebKit 16.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 107
- Microsoft Edge 107
版本 1.27
定位器
使用這些新 API 編寫定位器是一種樂趣:
- Page.GetByText() 透過文字內容定位。
- Page.GetByRole() 透過 ARIA role、ARIA attributes 和 accessible name 定位。
- Page.GetByLabel()以定位a form control by associated label's text.
- Page.GetByTestId() 用於根據其
data-testid
屬性定位元素(可配置其他屬性)。 - Page.GetByPlaceholder()以定位an input by placeholder.
- Page.GetByAltText()以定位an element, usually image, by its text alternative.
- Page.GetByTitle()以定位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 類別中也都可以使用。
其他重點
- 如 v1.25 中所宣布,Ubuntu 18 將在 2022 年 12 月起不再受支援。除此之外,從下一個 Playwright 版本開始,Ubuntu 18 上將不會有 WebKit 更新。
行為變更
-
Expect(Locator).ToHaveAttributeAsync() 使用空值不再比對缺少的屬性。例如,當
button
沒有disabled
屬性時,以下程式碼片段將會成功。await Expect(Page.GetByRole(AriaRole.Button)).ToHaveAttributeAsync("disabled", "");
瀏覽器版本
- Chromium 107.0.5304.18
- Mozilla Firefox 105.0.1
- WebKit 16.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 106
- Microsoft Edge 106
版本 1.26
斷言
- 新選項
Enabled
for Expect(Locator).ToBeEnabledAsync(). - Expect(Locator).ToHaveTextAsync()現在pierces open shadow roots.
- 新選項
Editable
for Expect(Locator).ToBeEditableAsync(). - 新選項
Visible
for Expect(Locator).ToBeVisibleAsync(). - Expect(Response).ToBeOKAsync() 現在可用.
其他重點
- 新選項
MaxRedirects
for ApiRequestContext.GetAsync()和其他方法以limit redirect count. - Codegen 現在支援MSTest and NUnit frameworks.
- 現在支援ASP .NET。
行為變更
許多 Playwright API 已經支援 WaitUntil: WaitUntilState.DOMContentLoaded
選項。例如:
await Page.GotoAsync("https://playwright.dev", new() { WaitUntil = WaitUntilState.DOMContentLoaded });
在 1.26 之前,這將等待所有 iframe 觸發 DOMContentLoaded
事件。
為了與網頁規範保持一致,WaitUntilState.DOMContentLoaded
值只會等待目標框架觸發 'DOMContentLoaded'
事件。使用 WaitUntil: WaitUntilState.Load
來等待所有 iframe。
瀏覽器版本
- Chromium 106.0.5249.30
- Mozilla Firefox 104.0
- WebKit 16.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 105
- Microsoft Edge 105
版本 1.25
New .runsettings file的支援
Microsoft.Playwright.NUnit
和 Microsoft.Playwright.MSTest
現在會在執行端對端測試時考慮 .runsettings
檔案和透過 CLI 傳遞的設定。請參閱文件以取得支援設定的完整清單。
以下現在可以正常運作:
<?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以設定the following environment variable -->
<DEBUG>pw:api</DEBUG>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
公告
- 🪦 這是最後一個支援macOS 10.15 的版本(自 1.21 起已棄用)。
- ⚠️ Ubuntu 18 現已棄用,將從 2022 年 12 月起不再受支援。
瀏覽器版本
- Chromium 105.0.5195.19
- Mozilla Firefox 103.0
- WebKit 16.0
此版本也對以下穩定頻道進行了測試:
- Google Chrome 104
- Microsoft Edge 104
版本 1.24
🐂 Debian 11 Bullseye Support
Playwright 現在支援 Debian 11 Bullseye 在 x86_64 上的 Chromium、Firefox 和 WebKit。如果您遇到任何問題,請告訴我們!
Linux 支援如下:
| | Ubuntu 20.04 | Ubuntu 22.04 | Debian 11 | :--- | :---: | :---: | :---: | :---: | | Chromium | ✅ | ✅ | ✅ | | WebKit | ✅ | ✅ | ✅ | | Firefox | ✅ | ✅ | ✅ |
新的介紹文件
我們重寫了入門文件,使其更專注於端對端測試。請在 playwright.dev.
版本 1.23
API 測試
Playwright for .NET 1.23 引入新的 API 測試,讓您可以直接從 .NET 向伺服器發送請求!現在您可以:
- test your server API
- 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 執行請求,請使用新的 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 測試指南.
網路重播
現在您可以將網路流量錄製到 HAR 檔案中,並在測試中重複使用此流量。
將網路錄製到 HAR 檔案:
pwsh bin/Debug/netX/playwright.ps1 open --save-har=example.har --save-har-glob="**/api/**" https://example.com
或者,您可以透過程式方式錄製 HAR:
var context = await browser.NewContextAsync(new()
{
RecordHarPath = harPath,
RecordHarUrlFilterString = "**/api/**",
});
// ... Perform actions ...
// 關閉上下文以確保 HAR 儲存到磁碟。
context.CloseAsync();
使用新方法 Page.RouteFromHARAsync() 或 BrowserContext.RouteFromHARAsync() 從 HAR 檔案提供符合的回應:
await context.RouteFromHARAsync("example.har");
在 我們的文件.
進階路由
您現在可以使用 Route.FallbackAsync() 將路由移交給其他處理器。
請考慮以下範例:
// 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() 也會參與路由處理,並且可以被延遲。
Web-First 斷言更新
- 新方法 Expect(Locator).ToHaveValuesAsync() 用於斷言
<select multiple>
元素的所有選取值。 - 方法 Expect(Locator).ToContainTextAsync() 和 Expect(Locator).ToHaveTextAsync() 現在接受
ignoreCase
選項。
其他
-
如果有阻礙您的 Service Worker,您現在可以透過新的上下文選項
serviceWorkers
輕鬆停用它:var context = await Browser.NewContextAsync(new()
{
ServiceWorkers = ServiceWorkerPolicy.Block
}); -
Using
.zip
path forrecordHar
context 選項 自動壓縮 the resulting HAR:var context = await Browser.NewContextAsync(new() { RecordHarPath = "example.har.zip" });
-
如果您打算手動編輯 HAR,請考慮使用僅記錄重播所需基本資訊的
"minimal"
HAR 記錄模式:var context = await Browser.NewContextAsync(new() { RecordHarPath = "example.har", RecordHarMode = HarMode.Minimal });
-
Playwright 現在在 Ubuntu 22 amd64 和 Ubuntu 22 arm64 上執行。
-
Playwright for .NET 現在支援 linux-arm64 and provides a arm64 Ubuntu 20.04 Docker image for it.
版本 1.22
重點
-
角色選擇器,允許依據 ARIA role、ARIA attributes 和 accessible name 選擇元素。
// Click a button with accessible name "log in"
await page.Locator("role=button[name='log in']").ClickAsync();在 我們的文件.
-
新的 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
重點
-
新的角色選擇器,允許依據 ARIA role、ARIA attributes 和 accessible name 選擇元素。
// Click a button with accessible name "log in"
await page.Locator("role=button[name='log in']").ClickAsync();在 我們的文件.
-
New
scale
選項 in Page.ScreenshotAsync() for smaller sized screenshots. -
New
caret
選項 in Page.ScreenshotAsync() 控制 text caret. Defaults to"hide"
. -
We現在ship a designated .NET docker image
mcr.microsoft.com/playwright/dotnet
. 在 我們的文件.
行為變更
- Playwright 現在透過 Locator.SetInputFilesAsync() API 支援大型檔案上傳(數百 MB)。
瀏覽器版本
- Chromium 101.0.4951.26
- Mozilla Firefox 98.0.2
- WebKit 15.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 100
- Microsoft Edge 100
版本 1.20
Web-First 斷言
Playwright for .NET 1.20 引入了 Web-First 斷言。
請考慮以下範例:
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"
文字。它會重複擷取節點並檢查,直到滿足條件或達到逾時為止。您可以將此逾時作為選項傳遞。
在 我們的文件.
其他更新
- 新選項s用於方法Page.ScreenshotAsync(), Locator.ScreenshotAsync() 和 ElementHandle.ScreenshotAsync():
- 選項
ScreenshotAnimations.Disabled
將所有 CSS 動畫和轉場重置為一致狀態 - 選項
mask: Locator[]
遮罩指定的元素,在其上方覆蓋粉色#FF00FF
方框。
- 選項
- Locator.HighlightAsync()視覺化地顯示element(s)以便更輕鬆地debugging.
公告
- v1.20是最後一個接收receive WebKit update for macOS 10.15 Catalina. 請更新macOS以繼續使用latest & greatest WebKit!
瀏覽器版本
- Chromium 101.0.4921.0
- Mozilla Firefox 97.0.1
- WebKit 15.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 99
- Microsoft Edge 99
版本 1.19
重點
-
Locator 現在支援
has
選項,確保它在內部包含另一個定位器:await Page.Locator("article", new() { Has = Page.Locator(".highlight") }).ClickAsync();
在定位器文件中閱讀更多
-
新的 Locator.Page
-
Page.ScreenshotAsync() 和 Locator.ScreenshotAsync() 現在會自動隱藏閃爍的游標
-
Playwright Codegen 現在會產生定位器和框架定位器
瀏覽器版本
- Chromium 100.0.4863.0
- Mozilla Firefox 96.0.1
- WebKit 15.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 98
- Microsoft Edge 98
版本 1.18
定位器改進
-
每個定位器現在可以選擇性地依其包含的文字進行篩選:
await Page.Locator("li", new() { HasTextString = "My Item" })
.Locator("button").click();在定位器文件中閱讀更多
新的 API 與變更
AcceptDownloads
選項現在預設為true
。Sources
選項 to embed sources into traces.
瀏覽器版本
- Chromium 99.0.4812.0
- Mozilla Firefox 95.0
- WebKit 15.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 97
- Microsoft Edge 97
版本 1.17
框架定位器
Playwright 1.17 引入了框架定位器 - 用於頁面上 iframe 的定位器。框架定位器捕獲足以擷取 iframe
然後在該 iframe 中定位元素的邏輯。框架定位器預設為嚴格模式,會等待 iframe
出現,並可用於 Web-First 斷言。
框架定位器可以使用 Page.FrameLocator() 或 Locator.FrameLocator() 方法建立。
var locator = page.FrameLocator("#my-frame").Locator("text=Submit");
await locator.ClickAsync();
在我們的文件閱讀更多。
追蹤檢視器更新
Playwright 追蹤檢視器現在可在線上使用,網址為 https://trace.playwright.dev!只需拖放您的 trace.zip
檔案即可檢查其內容。
NOTE: trace files are not uploaded anywhere; trace.playwright.dev is a progressive web application that processes traces locally.
- Playwright 測試追蹤現在預設包含原始碼(這些可以透過追蹤選項關閉)
- 追蹤檢視器現在顯示測試名稱
- 含有瀏覽器詳細資訊的新追蹤中繼資料標籤
- 快照現在有 URL 列
HTML Report Update
- HTML report 現在支援dynamic filtering
- 報告現在是單一靜態 HTML 檔案,可透過電子郵件傳送或作為 slack 附件。
Ubuntu ARM64 支援與更多功能
-
Playwright 現在支援 Ubuntu 20.04 ARM64。您現在可以在 Apple M1 的 Docker 內和 Raspberry Pi 上執行 Playwright 測試。
-
您現在可以使用 Playwright 在 Linux 上安裝穩定版本的 Edge:
pwsh bin/Debug/netX/playwright.ps1 install msedge
新的 API
版本 1.16
🎭 Playwright Library
Locator.WaitForAsync
等待定位器解析為具有給定狀態的單一元素。預設為 state: 'visible'
。
var orderSent = page.Locator("#order-sent");
orderSent.WaitForAsync();
🎭 Playwright Trace Viewer
- 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
瀏覽器版本
- Chromium 97.0.4666.0
- Mozilla Firefox 93.0
- WebKit 15.4
此版本也對以下穩定頻道進行了測試:
- Google Chrome 94
- Microsoft Edge 94
版本 1.15
🖱️ Mouse Wheel
透過使用 Mouse.WheelAsync(),您現在可以垂直或水平滾動。
📜 新的 Headers API
以前無法取得回應的多個標頭值。現在這是可能的,並提供了額外的輔助函數:
- Request.AllHeadersAsync()
- Request.HeadersArrayAsync()
- Request.HeaderValueAsync()
- Response.AllHeadersAsync()
- Response.HeadersArrayAsync()
- Response.HeaderValueAsync()
- Response.HeaderValuesAsync()
🌈 Forced-Colors emulation
現在可以透過在 Browser.NewContextAsync() 中傳遞它或呼叫 Page.EmulateMediaAsync() 來模擬 forced-colors
CSS 媒體功能。
新的 API
- Page.RouteAsync() 接受新的
times
選項,以指定此路由應匹配多少次。 - Page.SetCheckedAsync() 和 Locator.SetCheckedAsync() 被引入以設定the checked state of a checkbox.
- Request.SizesAsync() 回傳 resource size information for given http request.
- Tracing.StartChunkAsync() - Start a new trace chunk.
- Tracing.StopChunkAsync() - Stops a new trace chunk.
Important ⚠
- ⬆ .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.
瀏覽器版本
- Chromium 96.0.4641.0
- Mozilla Firefox 92.0
- WebKit 15.0
版本 1.14
⚡️ New "strict" mode
選擇器歧義是自動化測試中的常見問題。「嚴格」模式確保您的選擇器指向單一元素,否則會拋出例外。
在您的動作呼叫中設定 setStrict(true)
以啟用。
// This will throw if you have more than one button!
await page.Locator("button", new() { Strict = true });
📍 新的 Locators API
Locator 代表頁面上元素的檢視。它捕獲在任何時刻擷取元素所需的邏輯。
Locator 和 ElementHandle 之間的差異在於,後者指向特定元素,而 Locator 捕獲如何擷取該元素的邏輯。
Also, locators are "strict" by default!
var locator = page.Locator("button");
await locator.ClickAsync();
在文件中了解更多。
🧩 Experimental React 和 Vue selector engines
React 和 Vue 選擇器允許按組件名稱和/或屬性值選擇元素。語法與屬性選擇器非常相似,並支援所有屬性選擇器運算子。
await page.Locator("_react=SubmitButton[enabled=true]").ClickAsync();
await page.Locator("_vue=submit-button[enabled=true]").ClickAsync();
在 react 選擇器文件 和 vue 選擇器文件 中了解更多。
✨ New nth
和 visible
selector engines
nth
selector engine is equivalent to the:nth-match
pseudo class, but could be combined with other selector engines.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");
瀏覽器版本
- Chromium 94.0.4595.0
- Mozilla Firefox 91.0
- WebKit 15.0
版本 1.13
Playwright
- 🖖 Programmatic drag-and-drop support via the Page.DragAndDropAsync() API.
- 🔎 Enhanced HAR具有請求和回應的主體大小. 透過
recordHar
選項 in Browser.NewContextAsync(). 使用
工具
- Playwright Trace Viewer現在shows parameters, returned values and
console.log()
calls.
新增與重新編寫的指南
瀏覽器版本
- Chromium 93.0.4576.0
- Mozilla Firefox 90.0
- WebKit 14.2
新的 Playwright API
- new
baseURL
選項 in Browser.NewContextAsync() 和 Browser.NewPageAsync() - Response.SecurityDetailsAsync() 和 Response.ServerAddrAsync()
- Page.DragAndDropAsync() 和 Frame.DragAndDropAsync()
- Download.CancelAsync()
- Page.InputValueAsync(), Frame.InputValueAsync() 和 ElementHandle.InputValueAsync()
- new
force
選項 in Page.FillAsync(), Frame.FillAsync(), 和 ElementHandle.FillAsync() - new
force
選項 in Page.SelectOptionAsync(), Frame.SelectOptionAsync(), 和 ElementHandle.SelectOptionAsync()
版本 1.12
重點
- Playwright for .NET v1.12 is現在stable!
- Ships with the codegen 和 trace viewer tools out-of-the-box
瀏覽器版本
- Chromium 93.0.4530.0
- Mozilla Firefox 89.0
- WebKit 14.2
此版本也對以下穩定頻道進行了測試:
- Google Chrome 91
- Microsoft Edge 91