Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->138.0.7204.23<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->139.0.7258.5<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->18.5<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->139.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->140.0.2<!-- GEN:stop --> | ✅ | ✅ | ✅ |

Playwright for .NET is the official language port of [Playwright](https://playwright.dev), the library to automate [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) with a single API. Playwright is built to enable cross-browser web automation that is **ever-green**, **capable**, **reliable** and **fast**.

Expand Down
2 changes: 1 addition & 1 deletion src/Common/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyVersion>1.53.0</AssemblyVersion>
<PackageVersion>$(AssemblyVersion)</PackageVersion>
<DriverVersion>1.53.1</DriverVersion>
<DriverVersion>1.54.0-alpha-2025-07-08</DriverVersion>
<ReleaseVersion>$(AssemblyVersion)</ReleaseVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<NoDefaultExcludes>true</NoDefaultExcludes>
Expand Down
50 changes: 23 additions & 27 deletions src/Playwright.TestingHarnessTest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Playwright.TestingHarnessTest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "playwright.testingharnesstest",
"private": true,
"devDependencies": {
"@playwright/test": "1.53.1",
"@playwright/test": "1.54.0-alpha-2025-07-08",
"@types/node": "^22.12.0",
"fast-xml-parser": "^4.5.0"
}
Expand Down
4 changes: 2 additions & 2 deletions src/Playwright.Tests/BrowserContextBasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ public async Task ShouldRespectDeviceScaleFactor()
{
await using var context = await Browser.NewContextAsync(new()
{
DeviceScaleFactor = 3
DeviceScaleFactor = 3.5F
});

var page = await context.NewPageAsync();
Assert.AreEqual(3, await page.EvaluateAsync<int>("window.devicePixelRatio"));
Assert.AreEqual(3.5F, await page.EvaluateAsync<float>("window.devicePixelRatio"));
}

[PlaywrightTest("browsercontext-basic.spec.ts", "should not allow deviceScaleFactor with null viewport")]
Expand Down
4 changes: 2 additions & 2 deletions src/Playwright.Tests/BrowserContextFetchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ public async Task ShouldSupportTimeoutOption()
{
await Task.Delay(5000);
});
var exception = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(async () => await Context.APIRequest.GetAsync(Server.Prefix + "/slow", new() { Timeout = 10 }));
StringAssert.Contains("Request timed out after 10ms", exception.Message);
var exception = await PlaywrightAssert.ThrowsAsync<TimeoutException>(() => Context.APIRequest.GetAsync(Server.Prefix + "/slow", new() { Timeout = 1000 }));
StringAssert.Contains("Timeout 1000ms exceeded", exception.Message);
}

[PlaywrightTest("browsercontext-fetch.spec.ts", "should dispose")]
Expand Down
4 changes: 2 additions & 2 deletions src/Playwright.Tests/GeolocationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ await Context.SetGeolocationAsync(new()
await using var context2 = await Browser.NewContextAsync(new()
{
Permissions = new[] { "geolocation" },
Geolocation = new() { Latitude = 20, Longitude = 20 },
Geolocation = new() { Latitude = 10.5F, Longitude = 11.5F },
});

var page2 = await context2.NewPageAsync();
Expand All @@ -88,7 +88,7 @@ await Context.SetGeolocationAsync(new()
@"() => new Promise(resolve => navigator.geolocation.getCurrentPosition(position => {
resolve({latitude: position.coords.latitude, longitude: position.coords.longitude});
}))");
AssertEqual(20, 20, geolocation2);
AssertEqual(10.5F, 11.5F, geolocation2);
}

[PlaywrightTest("geolocation.spec.ts", "should not modify passed default options object")]
Expand Down
4 changes: 2 additions & 2 deletions src/Playwright.Tests/GlobalFetchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public async Task ShouldSupportGlobalTimeoutOption()
{
var request = await Playwright.APIRequest.NewContextAsync(new() { Timeout = 100 });
Server.SetRoute("/empty.html", async request => await Task.Delay(5_000));
var exception = Assert.ThrowsAsync<PlaywrightException>(() => request.GetAsync(Server.EmptyPage));
StringAssert.Contains("Request timed out after 100ms", exception.Message);
var exception = Assert.ThrowsAsync<TimeoutException>(() => request.GetAsync(Server.EmptyPage));
StringAssert.Contains("Timeout 100ms exceeded", exception.Message);
await request.DisposeAsync();
}

Expand Down
7 changes: 7 additions & 0 deletions src/Playwright.Tests/InterceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ bool URLMatches(string baseURL, string url, string glob)
Assert.True(URLMatches("http://playwright.dev/foo", "http://playwright.dev/foo?bar", "\\\\?bar"));
Assert.True(URLMatches("http://first.host/", "http://second.host/foo", "**/foo"));
Assert.True(URLMatches("http://playwright.dev/", "http://localhost/", "*//localhost/"));

// Should work with baseURL and various non-http schemes.
Assert.True(URLMatches("http://playwright.dev/", "about:blank", "about:blank"));
Assert.False(URLMatches("http://playwright.dev/", "about:blank", "http://playwright.dev/"));
Assert.True(URLMatches("http://playwright.dev/", "about:blank", "about:*"));
Assert.True(URLMatches("http://playwright.dev/", "data:text/html,", "data:*/*"));
Assert.True(URLMatches("http://playwright.dev/", "file://path/to/file", "file://**"));
}

[PlaywrightTest("interception.spec.ts", "should intercept by glob")]
Expand Down
2 changes: 1 addition & 1 deletion src/Playwright.Tests/PageAddLocatorHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ await Page.EvaluateAsync(@"() =>
}");
var error = await PlaywrightAssert.ThrowsAsync<TimeoutException>(() => Page.Locator("#target").ClickAsync(new() { Timeout = 3000 }));
Assert.AreEqual(0, await Page.EvaluateAsync<int>("window.clicked"));
await Expect(Page.Locator("#interstitial")).ToBeVisibleAsync();
Assert.True(await Page.Locator("#interstitial").IsVisibleAsync());
Assert.AreEqual(1, called);
StringAssert.Contains("locator handler has finished, waiting for GetByRole(AriaRole.Button, new() { Name = \"close\" }) to be hidden", error.Message);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Playwright.Tests/PageRequestInterceptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ public async Task ShouldSupportTimeoutOptionInRouteFetch()
});
await Page.RouteAsync("**/*", async (route) =>
{
var error = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => route.FetchAsync(new() { Timeout = 1000 }));
Assert.True(error.Message.Contains("Request timed out after 1000ms"));
var error = await PlaywrightAssert.ThrowsAsync<TimeoutException>(() => route.FetchAsync(new() { Timeout = 1000 }));
Assert.True(error.Message.Contains("Timeout 1000ms exceeded"));
});
var error = await PlaywrightAssert.ThrowsAsync<TimeoutException>(() => Page.GotoAsync(Server.Prefix + "/slow", new() { Timeout = 2000 }));
Assert.True(error.Message.Contains("Timeout 2000ms exceeded"));
Expand Down
21 changes: 21 additions & 0 deletions src/Playwright.Tests/SelectorsRegisterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ public async Task ShouldWork()
StringAssert.Contains("Unknown engine \"tAG\" while parsing selector tAG=DIV", exception.Message);
}

[PlaywrightTest("selectors-register.spec.ts", "should throw \"already registered\" error when registering")]
public async Task ShouldThrowAlreadyRegisteredErrorWhenRegistering()
{
const string createSelector = @"({
create(root, target) {
return target.nodeName;
},
query(root, selector) {
return root.querySelector(selector);
},
queryAll(root, selector) {
return Array.from(root.querySelectorAll(selector));
}
})";

await TestUtils.RegisterEngineAsync(Playwright, "alreadyRegistered", createSelector);

var exception = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => Playwright.Selectors.RegisterAsync("alreadyRegistered", new() { Script = createSelector }));
StringAssert.Contains("\"alreadyRegistered\" selector engine has been already registered", exception.Message);
}

[PlaywrightTest("selectors-register.spec.ts", "should work with path")]
public async Task ShouldWorkWithPath()
{
Expand Down
4 changes: 3 additions & 1 deletion src/Playwright.Tests/TracingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ await Context.Tracing.StartAsync(new()
await page.ClickAsync("\"Click\"");
await page.Mouse.MoveAsync(20, 20);
await page.Mouse.DblClickAsync(20, 30);
await page.APIRequest.GetAsync(Server.Prefix + "/empty.html");
await page.Keyboard.InsertTextAsync("abc");
await page.WaitForTimeoutAsync(2000); // Give it some time to produce screenshots.
await page.CloseAsync();
Expand All @@ -64,6 +65,7 @@ await Expect(traceViewer.ActionTitles).ToHaveTextAsync([
new Regex(@"Click"),
new Regex(@"Mouse move"),
new Regex(@"Double click"),
new Regex(@"GET ""/empty.html"""),
new Regex(@"Insert ""abc"""),
new Regex(@"Wait for timeout"),
new Regex(@"Close")
Expand Down Expand Up @@ -404,7 +406,7 @@ class TraceViewerPage(IPage page)

public ILocator ActionTitles => Page.Locator(".action-title");

public ILocator StackFrames => Page.GetByTestId("stack-trace-list").Locator(".list-view-entry");
public ILocator StackFrames => Page.GetByRole(AriaRole.List, new() { Name = "Stack trace" }).GetByRole(AriaRole.Listitem);

public async Task SelectActionAsync(string title, int ordinal = 0)
{
Expand Down
36 changes: 36 additions & 0 deletions src/Playwright.Tests/UnrouteBehaviorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,40 @@ await Page.RouteAsync(new Regex(".*"), (route) =>
await Page.CloseAsync();
await route.FulfillAsync(new() { Status = (int)HttpStatusCode.OK });
}

[PlaywrightTest("unroute-behavior.spec.ts", "should not continue requests in flight (page)")]
public async Task ShouldNotContinueRequestsInFlightPage()
{
await Page.GotoAsync(Server.EmptyPage);

var routePromise = new TaskCompletionSource<IRoute>();
await Page.RouteAsync(new Regex(".*"), async (route) =>
{
routePromise.SetResult(route);
await Page.WaitForTimeoutAsync(3000);
await route.FulfillAsync(new() { Status = (int)HttpStatusCode.OK });
});

Page.EvaluateAsync("() => fetch('/')").IgnoreException();
await routePromise.Task;
await Page.UnrouteAllAsync(new() { Behavior = UnrouteBehavior.Wait });
}

[PlaywrightTest("unroute-behavior.spec.ts", "should not continue requests in flight (context)")]
public async Task ShouldNotContinueRequestsInFlightContext()
{
await Page.GotoAsync(Server.EmptyPage);

var routePromise = new TaskCompletionSource<IRoute>();
await Context.RouteAsync(new Regex(".*"), async (route) =>
{
routePromise.SetResult(route);
await Page.WaitForTimeoutAsync(3000);
await route.FulfillAsync(new() { Status = (int)HttpStatusCode.OK });
});

Page.EvaluateAsync("() => fetch('/')").IgnoreException();
await routePromise.Task;
await Context.UnrouteAllAsync(new() { Behavior = UnrouteBehavior.Wait });
}
}
5 changes: 3 additions & 2 deletions src/Playwright/API/Generated/IBrowserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ public partial interface IBrowserContext

/// <summary>
/// <para>
/// Returns the browser instance of the context. If it was launched as a persistent
/// context null gets returned.
/// Gets the browser instance that owns the context. Returns <c>null</c> if the context
/// is created outside of normal browser, e.g. Android or Electron.
/// </para>
/// </summary>
IBrowser? Browser { get; }
Expand Down Expand Up @@ -471,6 +471,7 @@ public partial interface IBrowserContext
/// <item><description><c>'notifications'</c></description></item>
/// <item><description><c>'payment-handler'</c></description></item>
/// <item><description><c>'storage-access'</c></description></item>
/// <item><description><c>'local-fonts'</c></description></item>
/// </list>
/// </param>
/// <param name="options">Call options</param>
Expand Down
14 changes: 14 additions & 0 deletions src/Playwright/API/Generated/IMouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ namespace Microsoft.Playwright;
/// The Mouse class operates in main-frame CSS pixels relative to the top-left corner
/// of the viewport.
/// </para>
/// <para>
/// If you want to debug where the mouse moved, you can use the <a href="https://playwright.dev/dotnet/docs/trace-viewer-intro">Trace
/// viewer</a> or <a href="https://playwright.dev/dotnet/docs/running-tests">Playwright
/// Inspector</a>. A red dot showing the location of the mouse will be shown for every
/// mouse action.
/// </para>
/// <para>Every <c>page</c> object has its own Mouse, accessible with <see cref="IPage.Mouse"/>.</para>
/// <code>
/// await Page.Mouse.MoveAsync(0, 0);<br/>
Expand All @@ -42,6 +48,14 @@ namespace Microsoft.Playwright;
/// await Page.Mouse.UpAsync();
/// </code>
/// </summary>
/// <remarks>
/// <para>
/// If you want to debug where the mouse moved, you can use the <a href="https://playwright.dev/dotnet/docs/trace-viewer-intro">Trace
/// viewer</a> or <a href="https://playwright.dev/dotnet/docs/running-tests">Playwright
/// Inspector</a>. A red dot showing the location of the mouse will be shown for every
/// mouse action.
/// </para>
/// </remarks>
public partial interface IMouse
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ public partial class BrowserContextCookiesResult
[Required]
[JsonPropertyName("sameSite")]
public SameSiteAttribute SameSite { get; set; } = default!;

/// <summary><para></para></summary>
[JsonPropertyName("partitionKey")]
public string? PartitionKey { get; set; }
}
9 changes: 9 additions & 0 deletions src/Playwright/API/Generated/Types/Cookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ public partial class Cookie
/// <summary><para>Optional.</para></summary>
[JsonPropertyName("sameSite")]
public SameSiteAttribute? SameSite { get; set; }

/// <summary>
/// <para>
/// For partitioned third-party cookies (aka <a href="https://developer.mozilla.org/en-US/docs/Web/Privacy/Guides/Privacy_sandbox/Partitioned_cookies">CHIPS</a>),
/// the partition key. Optional.
/// </para>
/// </summary>
[JsonPropertyName("partitionKey")]
public string? PartitionKey { get; set; }
}
Loading
Loading