Skip to content

Commit

Permalink
chore(roll): roll Playwright to v1.49.0 (#3056)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Nov 19, 2024
1 parent 8f071a8 commit 7797511
Show file tree
Hide file tree
Showing 29 changed files with 699 additions and 116 deletions.
6 changes: 3 additions & 3 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 -->130.0.6723.31<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->18.0<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->131.0<!-- GEN:stop --> ||||
| Chromium <!-- GEN:chromium-version -->131.0.6778.33<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->18.2<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->132.0<!-- 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.48.0</AssemblyVersion>
<PackageVersion>$(AssemblyVersion)</PackageVersion>
<DriverVersion>1.48.1</DriverVersion>
<DriverVersion>1.49.0</DriverVersion>
<ReleaseVersion>$(AssemblyVersion)</ReleaseVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<NoDefaultExcludes>true</NoDefaultExcludes>
Expand Down
105 changes: 105 additions & 0 deletions src/Playwright.Tests/PageAriaSnapshotTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace Microsoft.Playwright.Tests;

public class PageAriaSnapshotTests : PageTestEx
{
private string _unshift(string snapshot)
{
var lines = snapshot.Split('\n');
var whitespacePrefixLength = 100;
foreach (var line in lines)
{
if (string.IsNullOrWhiteSpace(line))
continue;
var match = System.Text.RegularExpressions.Regex.Match(line, @"^(\s*)");
if (match.Success && match.Groups[1].Value.Length < whitespacePrefixLength)
whitespacePrefixLength = match.Groups[1].Value.Length;
break;
}
return string.Join('\n', lines.Where(t => !string.IsNullOrWhiteSpace(t)).Select(line => line.Substring(whitespacePrefixLength)));
}

private async Task CheckAndMatchSnapshot(ILocator locator, string snapshot)
{
Assert.AreEqual(_unshift(snapshot), await locator.AriaSnapshotAsync());
await Expect(locator).ToMatchAriaSnapshotAsync(snapshot);
}

[PlaywrightTest("page-aria-snapshot.spec.ts", "should snapshot")]
public async Task ShouldSnapshot()
{
await Page.SetContentAsync("<h1>title</h1>");
await CheckAndMatchSnapshot(Page.Locator("body"), @"
- heading ""title"" [level=1]
");
}

[PlaywrightTest("page-aria-snapshot.spec.ts", "should snapshot list")]
public async Task ShouldSnapshotList()
{
await Page.SetContentAsync(@"
<h1>title</h1>
<h1>title 2</h1>
");
await CheckAndMatchSnapshot(Page.Locator("body"), @"
- heading ""title"" [level=1]
- heading ""title 2"" [level=1]
");
}

[PlaywrightTest("page-aria-snapshot.spec.ts", "should snapshot list with accessible name")]
public async Task ShouldSnapshotListWithAccessibleName()
{
await Page.SetContentAsync(@"
<ul aria-label=""my list"">
<li>one</li>
<li>two</li>
</ul>
");
await CheckAndMatchSnapshot(Page.Locator("body"), @"
- list ""my list"":
- listitem: one
- listitem: two
");
}

[PlaywrightTest("page-aria-snapshot.spec.ts", "should snapshot complex")]
public async Task ShouldSnapshotComplex()
{
await Page.SetContentAsync(@"
<ul>
<li>
<a href='about:blank'>link</a>
</li>
</ul>
");
await CheckAndMatchSnapshot(Page.Locator("body"), @"
- list:
- listitem:
- link ""link""
");
}
}
27 changes: 27 additions & 0 deletions src/Playwright.Tests/PageRouteWebSocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,31 @@ await AssertAreEqualWithRetriesAsync(() => Page.EvaluateAsync<string[]>("() => w
"close code=3008 reason=oops wasClean=true",
]);
}

[PlaywrightTest("page-route-web-socket.spec.ts", "should work with baseURL")]
public async Task ShouldWorkWithBaseURL()
{
var context = await Browser.NewContextAsync(new() { BaseURL = $"http://localhost:{Server.Port}" });
var page = await context.NewPageAsync();

await page.RouteWebSocketAsync("/ws", ws =>
{
ws.OnMessage(message =>
{
ws.Send(message.Text);
});
});

await SetupWS(page, Server.Port, "blob");

await page.EvaluateAsync(@"async () => {
await window.wsOpened;
window.ws.send('echo');
}");
await AssertAreEqualWithRetriesAsync(() => page.EvaluateAsync<string[]>("() => window.log"), new[]
{
"open",
$"message: data=echo origin=ws://localhost:{Server.Port} lastEventId=",
});
}
}
34 changes: 34 additions & 0 deletions src/Playwright.Tests/TracingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,40 @@ string[] ResourceNames(Dictionary<string, byte[]> resources)
}
}

[PlaywrightTest("tracing.spec.ts", "should show tracing.group in the action list with location")]
public async Task ShouldShowTracingGroupInActionList()
{
using var tracesDir = new TempDirectory();
await Context.Tracing.StartAsync();
var page = await Context.NewPageAsync();

await Context.Tracing.GroupAsync("outer group");
await page.GotoAsync("data:text/html,<!DOCTYPE html><body><div>Hello world</div></body>");
await Context.Tracing.GroupAsync("inner group 1");
await page.Locator("body").ClickAsync();
await Context.Tracing.GroupEndAsync();
await Context.Tracing.GroupAsync("inner group 2");
await Expect(page.GetByText("Hello")).ToBeVisibleAsync();
await Context.Tracing.GroupEndAsync();
await Context.Tracing.GroupEndAsync();

var tracePath = Path.Combine(tracesDir.Path, "trace.zip");
await Context.Tracing.StopAsync(new() { Path = tracePath });

var (events, resources) = ParseTrace(tracePath);
var actions = GetActions(events);

Assert.AreEqual(new[] {
"BrowserContext.NewPageAsync",
"outer group",
"Page.GotoAsync",
"inner group 1",
"Locator.ClickAsync",
"inner group 2",
"LocatorAssertions.ToBeVisibleAsync"
}, actions);
}

private static (IReadOnlyList<TraceEventEntry> Events, Dictionary<string, byte[]> Resources) ParseTrace(string path)
{
Dictionary<string, byte[]> resources = new();
Expand Down
24 changes: 22 additions & 2 deletions src/Playwright/API/Generated/IClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ public partial interface IClock
/// Makes <c>Date.now</c> and <c>new Date()</c> return fixed fake time at all times,
/// keeps all the timers running.
/// </para>
/// <para>
/// Use this method for simple scenarios where you only need to test with a predefined
/// time. For more advanced scenarios, use <see cref="IClock.InstallAsync"/> instead.
/// Read docs on <a href="https://playwright.dev/dotnet/docs/clock">clock emulation</a>
/// to learn more.
/// </para>
/// <para>**Usage**</para>
/// <code>
/// await page.Clock.SetFixedTimeAsync(DateTime.Now);<br/>
Expand All @@ -200,6 +206,12 @@ public partial interface IClock
/// Makes <c>Date.now</c> and <c>new Date()</c> return fixed fake time at all times,
/// keeps all the timers running.
/// </para>
/// <para>
/// Use this method for simple scenarios where you only need to test with a predefined
/// time. For more advanced scenarios, use <see cref="IClock.InstallAsync"/> instead.
/// Read docs on <a href="https://playwright.dev/dotnet/docs/clock">clock emulation</a>
/// to learn more.
/// </para>
/// <para>**Usage**</para>
/// <code>
/// await page.Clock.SetFixedTimeAsync(DateTime.Now);<br/>
Expand All @@ -211,7 +223,11 @@ public partial interface IClock
Task SetFixedTimeAsync(DateTime time);

/// <summary>
/// <para>Sets current system time but does not trigger any timers.</para>
/// <para>
/// Sets system time, but does not trigger any timers. Use this to test how the web
/// page reacts to a time shift, for example switching from summer to winter time, or
/// changing time zones.
/// </para>
/// <para>**Usage**</para>
/// <code>
/// await page.Clock.SetSystemTimeAsync(DateTime.Now);<br/>
Expand All @@ -223,7 +239,11 @@ public partial interface IClock
Task SetSystemTimeAsync(string time);

/// <summary>
/// <para>Sets current system time but does not trigger any timers.</para>
/// <para>
/// Sets system time, but does not trigger any timers. Use this to test how the web
/// page reacts to a time shift, for example switching from summer to winter time, or
/// changing time zones.
/// </para>
/// <para>**Usage**</para>
/// <code>
/// await page.Clock.SetSystemTimeAsync(DateTime.Now);<br/>
Expand Down
7 changes: 1 addition & 6 deletions src/Playwright/API/Generated/IKeyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ namespace Microsoft.Playwright;
/// await page.Keyboard.PressAsync("Shift+A");
/// </code>
/// <para>An example to trigger select-all with the keyboard</para>
/// <code>
/// // on Windows and Linux<br/>
/// await page.Keyboard.PressAsync("Control+A");<br/>
/// // on macOS<br/>
/// await page.Keyboard.PressAsync("Meta+A");
/// </code>
/// <code>await page.Keyboard.PressAsync("ControlOrMeta+A");</code>
/// </summary>
public partial interface IKeyboard
{
Expand Down
29 changes: 29 additions & 0 deletions src/Playwright/API/Generated/ILocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,35 @@ public partial interface ILocator
/// <param name="locator">Additional locator to match.</param>
ILocator And(ILocator locator);

/// <summary>
/// <para>
/// Captures the aria snapshot of the given element. Read more about <a href="https://playwright.dev/dotnet/docs/aria-snapshots">aria
/// snapshots</a> and <see cref="ILocatorAssertions.ToMatchAriaSnapshotAsync"/> for
/// the corresponding assertion.
/// </para>
/// <para>**Usage**</para>
/// <code>await page.GetByRole(AriaRole.Link).AriaSnapshotAsync();</code>
/// <para>**Details**</para>
/// <para>
/// This method captures the aria snapshot of the given element. The snapshot is a string
/// that represents the state of the element and its children. The snapshot can be used
/// to assert the state of the element in the test, or to compare it to state in the
/// future.
/// </para>
/// <para>
/// The ARIA snapshot is represented using <a href="https://yaml.org/spec/1.2.2/">YAML</a>
/// markup language:
/// </para>
/// <list type="bullet">
/// <item><description>The keys of the objects are the roles and optional accessible names of the elements.</description></item>
/// <item><description>The values are either text content or an array of child elements.</description></item>
/// <item><description>Generic static text can be represented with the <c>text</c> key.</description></item>
/// </list>
/// <para>Below is the HTML markup and the respective ARIA snapshot:</para>
/// </summary>
/// <param name="options">Call options</param>
Task<string> AriaSnapshotAsync(LocatorAriaSnapshotOptions? options = default);

/// <summary>
/// <para>
/// Calls <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur">blur</a>
Expand Down
19 changes: 19 additions & 0 deletions src/Playwright/API/Generated/ILocatorAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,25 @@ public partial interface ILocatorAssertions
/// <param name="values">Expected options currently selected.</param>
/// <param name="options">Call options</param>
Task ToHaveValuesAsync(IEnumerable<Regex> values, LocatorAssertionsToHaveValuesOptions? options = default);

/// <summary>
/// <para>
/// Asserts that the target element matches the given <a href="https://playwright.dev/dotnet/docs/aria-snapshots">accessibility
/// snapshot</a>.
/// </para>
/// <para>**Usage**</para>
/// <code>
/// await page.GotoAsync("https://demo.playwright.dev/todomvc/");<br/>
/// await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(@"<br/>
/// - heading ""todos""<br/>
/// - textbox ""What needs to be done?""<br/>
/// ");
/// </code>
/// </summary>
/// <param name="expected">
/// </param>
/// <param name="options">Call options</param>
Task ToMatchAriaSnapshotAsync(string expected, LocatorAssertionsToMatchAriaSnapshotOptions? options = default);
}

#nullable disable
14 changes: 6 additions & 8 deletions src/Playwright/API/Generated/IPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,6 @@ public partial interface IPage
/// await page.EvaluateAsync("matchMedia('(prefers-color-scheme: dark)').matches");<br/>
/// // → true<br/>
/// await page.EvaluateAsync("matchMedia('(prefers-color-scheme: light)').matches");<br/>
/// // → false<br/>
/// await page.EvaluateAsync("matchMedia('(prefers-color-scheme: no-preference)').matches");<br/>
/// // → false
/// </code>
/// </summary>
Expand Down Expand Up @@ -2187,8 +2185,8 @@ public partial interface IPage
/// </para>
/// <code>
/// await page.RouteWebSocketAsync("/ws", ws =&gt; {<br/>
/// ws.OnMessage(message =&gt; {<br/>
/// if (message == "request")<br/>
/// ws.OnMessage(frame =&gt; {<br/>
/// if (frame.Text == "request")<br/>
/// ws.Send("response");<br/>
/// });<br/>
/// });
Expand All @@ -2214,8 +2212,8 @@ public partial interface IPage
/// </para>
/// <code>
/// await page.RouteWebSocketAsync("/ws", ws =&gt; {<br/>
/// ws.OnMessage(message =&gt; {<br/>
/// if (message == "request")<br/>
/// ws.OnMessage(frame =&gt; {<br/>
/// if (frame.Text == "request")<br/>
/// ws.Send("response");<br/>
/// });<br/>
/// });
Expand All @@ -2241,8 +2239,8 @@ public partial interface IPage
/// </para>
/// <code>
/// await page.RouteWebSocketAsync("/ws", ws =&gt; {<br/>
/// ws.OnMessage(message =&gt; {<br/>
/// if (message == "request")<br/>
/// ws.OnMessage(frame =&gt; {<br/>
/// if (frame.Text == "request")<br/>
/// ws.Send("response");<br/>
/// });<br/>
/// });
Expand Down
9 changes: 4 additions & 5 deletions src/Playwright/API/Generated/IRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ public partial interface IRoute
/// </code>
/// <para>**Details**</para>
/// <para>
/// Note that any overrides such as <see cref="IRoute.ContinueAsync"/> or <see cref="IRoute.ContinueAsync"/>
/// only apply to the request being routed. If this request results in a redirect, overrides
/// will not be applied to the new redirected request. If you want to propagate a header
/// through redirects, use the combination of <see cref="IRoute.FetchAsync"/> and <see
/// cref="IRoute.FulfillAsync"/> instead.
/// The <see cref="IRoute.ContinueAsync"/> option applies to both the routed request
/// and any redirects it initiates. However, <see cref="IRoute.ContinueAsync"/>, <see
/// cref="IRoute.ContinueAsync"/>, and <see cref="IRoute.ContinueAsync"/> only apply
/// to the original request and are not carried over to redirected requests.
/// </para>
/// <para>
/// <see cref="IRoute.ContinueAsync"/> will immediately send the request to the network,
Expand Down
Loading

0 comments on commit 7797511

Please sign in to comment.