Skip to content

Commit

Permalink
feat(roll): roll to Playwright 1.38.0 (#2699)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Sep 18, 2023
1 parent afee4e6 commit 24edb58
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 32 deletions.
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 -->117.0.5938.35<!-- GEN:stop --> ||||
| Chromium <!-- GEN:chromium-version -->118.0.5993.11<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->17.0<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->115.0<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->117.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.37.0</AssemblyVersion>
<PackageVersion>$(AssemblyVersion)</PackageVersion>
<DriverVersion>1.38.0-alpha-sep-5-2023</DriverVersion>
<DriverVersion>1.38.0</DriverVersion>
<ReleaseVersion>$(AssemblyVersion)</ReleaseVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<NoDefaultExcludes>true</NoDefaultExcludes>
Expand Down
11 changes: 11 additions & 0 deletions src/Playwright.Tests/BrowserContextEventsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,15 @@ void dialogHandler(object sender, IDialog e)
context.Dialog += dialogHandler;
return await tsc.Task;
}

[PlaywrightTest("browsercontext-events.spec.ts", "weberror event should work")]
public async Task WebErrorEventShouldWork()
{
var tsc = new TaskCompletionSource<IWebError>();
Context.WebError += (sender, e) => tsc.TrySetResult(e);
await Page.SetContentAsync(@"<script>throw new Error(""boom"")</script>");
var webError = await tsc.Task;
Assert.AreEqual(Page, webError.Page);
StringAssert.Contains("boom", webError.Error);
}
}
13 changes: 9 additions & 4 deletions src/Playwright.Tests/PageEvaluateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,16 @@ public async Task ShouldTransferArraysAsArraysNotObjects()
Assert.True(result);
}

[PlaywrightTest("page-evaluate.spec.ts", "should transfer maps as empty objects")]
public async Task ShouldTransferMapsAsEmptyObjects()
[PlaywrightTest("page-evaluate.spec.ts", "should transfer maps")]
public async Task ShouldTransferMaps()
{
dynamic result = await Page.EvaluateAsync<ExpandoObject>("a => a.x.constructor.name + ' ' + JSON.stringify(a.x), {x: new Map([[1, 2]])}");
Assert.IsEmpty(TypeDescriptor.GetProperties(result));
Assert.AreEqual(await Page.EvaluateAsync<Dictionary<string, object>>("() => new Map([[1, { test: 42n }]])"), new Dictionary<string, object> { });
}

[PlaywrightTest("page-evaluate.spec.ts", "should transfer sets")]
public async Task ShouldTransferSets()
{
Assert.AreEqual(await Page.EvaluateAsync<HashSet<object>>("() => new Set([1, { test: 42n }])"), new HashSet<object> { });
}

[PlaywrightTest("page-evaluate.spec.ts", "should modify global environment")]
Expand Down
6 changes: 3 additions & 3 deletions src/Playwright/API/Generated/IBrowserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ public partial interface IBrowserContext

/// <summary>
/// <para>
/// Emitted when unhandled exceptions occur on any pages created through this context.
/// To only listen for <c>pageError</c> events from a particular page, use <see cref="IPage.PageError"/>.
/// Emitted when exception is unhandled in any of the pages in this context. To listen
/// for errors from a particular page, use <see cref="IPage.PageError"/> instead.
/// </para>
/// </summary>
event EventHandler<IPageError> PageError;
event EventHandler<IWebError> WebError;

/// <summary>
/// <para>
Expand Down
7 changes: 4 additions & 3 deletions src/Playwright/API/Generated/IElementHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public partial interface IElementHandle : IJSHandle
/// is inside the <c>&lt;label&gt;</c> element that has an associated <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>,
/// the control will be filled instead.
/// </para>
/// <para>To send fine-grained keyboard events, use <see cref="IKeyboard.TypeAsync"/>.</para>
/// <para>To send fine-grained keyboard events, use <see cref="ILocator.PressSequentiallyAsync"/>.</para>
/// </summary>
/// <param name="value">
/// Value to set for the <c>&lt;input&gt;</c>, <c>&lt;textarea&gt;</c> or <c>[contenteditable]</c>
Expand Down Expand Up @@ -909,8 +909,9 @@ public partial interface IElementHandle : IJSHandle

/// <summary>
/// <para>
/// **DEPRECATED** Use locator-based <see cref="ILocator.PressSequentiallyAsync"/> instead.
/// Read more about <a href="https://playwright.dev/dotnet/docs/locators">locators</a>.
/// **DEPRECATED** In most cases, you should use <see cref="ILocator.FillAsync"/> instead.
/// You only need to press keys one by one if there is special keyboard handling on
/// the page - in this case use <see cref="ILocator.PressSequentiallyAsync"/>.
/// </para>
/// <para>
/// Focuses the element, and then sends a <c>keydown</c>, <c>keypress</c>/<c>input</c>,
Expand Down
7 changes: 4 additions & 3 deletions src/Playwright/API/Generated/IFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public partial interface IFrame
/// is inside the <c>&lt;label&gt;</c> element that has an associated <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>,
/// the control will be filled instead.
/// </para>
/// <para>To send fine-grained keyboard events, use <see cref="IFrame.TypeAsync"/>.</para>
/// <para>To send fine-grained keyboard events, use <see cref="ILocator.PressSequentiallyAsync"/>.</para>
/// </summary>
/// <param name="selector">
/// A selector to search for an element. If there are multiple elements satisfying the
Expand Down Expand Up @@ -1602,8 +1602,9 @@ public partial interface IFrame

/// <summary>
/// <para>
/// **DEPRECATED** Use locator-based <see cref="ILocator.PressSequentiallyAsync"/> instead.
/// Read more about <a href="https://playwright.dev/dotnet/docs/locators">locators</a>.
/// **DEPRECATED** In most cases, you should use <see cref="ILocator.FillAsync"/> instead.
/// You only need to press keys one by one if there is special keyboard handling on
/// the page - in this case use <see cref="ILocator.PressSequentiallyAsync"/>.
/// </para>
/// <para>
/// Sends a <c>keydown</c>, <c>keypress</c>/<c>input</c>, and <c>keyup</c> event for
Expand Down
6 changes: 6 additions & 0 deletions src/Playwright/API/Generated/IKeyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public partial interface IKeyboard
/// </code>
/// <para>Shortcut for <see cref="IKeyboard.DownAsync"/> and <see cref="IKeyboard.UpAsync"/>.</para>
/// </summary>
/// <remarks><para>In most cases, you should use <see cref="ILocator.PressAsync"/> instead.</para></remarks>
/// <param name="key">
/// Name of the key to press or a character to generate, such as <c>ArrowLeft</c> or
/// <c>a</c>.
Expand All @@ -201,6 +202,11 @@ public partial interface IKeyboard
/// </summary>
/// <remarks>
/// <para>
/// In most cases, you should use <see cref="ILocator.FillAsync"/> instead. You only
/// need to press keys one by one if there is special keyboard handling on the page
/// - in this case use <see cref="ILocator.PressSequentiallyAsync"/>.
/// </para>
/// <para>
/// Modifier keys DO NOT effect <c>keyboard.type</c>. Holding down <c>Shift</c> will
/// not type the text in upper case.
/// </para>
Expand Down
7 changes: 4 additions & 3 deletions src/Playwright/API/Generated/IPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ public partial interface IPage
/// is inside the <c>&lt;label&gt;</c> element that has an associated <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control">control</a>,
/// the control will be filled instead.
/// </para>
/// <para>To send fine-grained keyboard events, use <see cref="IPage.TypeAsync"/>.</para>
/// <para>To send fine-grained keyboard events, use <see cref="ILocator.PressSequentiallyAsync"/>.</para>
/// </summary>
/// <param name="selector">
/// A selector to search for an element. If there are multiple elements satisfying the
Expand Down Expand Up @@ -2470,8 +2470,9 @@ public partial interface IPage

/// <summary>
/// <para>
/// **DEPRECATED** Use locator-based <see cref="ILocator.PressSequentiallyAsync"/> instead.
/// Read more about <a href="https://playwright.dev/dotnet/docs/locators">locators</a>.
/// **DEPRECATED** In most cases, you should use <see cref="ILocator.FillAsync"/> instead.
/// You only need to press keys one by one if there is special keyboard handling on
/// the page - in this case use <see cref="ILocator.PressSequentiallyAsync"/>.
/// </para>
/// <para>
/// Sends a <c>keydown</c>, <c>keypress</c>/<c>input</c>, and <c>keyup</c> event for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ namespace Microsoft.Playwright;

/// <summary>
/// <para>
/// <see cref="IPageError"/> class represents objects created by context when there
/// are unhandled execeptions thrown on the pages and dispatched via the <see cref="IBrowserContext.PageError"/>
/// event.
/// <see cref="IWebError"/> class represents an unhandled exeception thrown in the page.
/// It is dispatched via the <see cref="IBrowserContext.WebError"/> event.
/// </para>
/// <code>
/// // Log all uncaught errors to the terminal<br/>
/// context.PageError += (_, pageerror) =&gt;<br/>
/// context.WebError += (_, webError) =&gt;<br/>
/// {<br/>
/// Console.WriteLine("Uncaught exception: " + pageerror.Error);<br/>
/// Console.WriteLine("Uncaught exception: " + webError.Error);<br/>
/// };
/// </code>
/// </summary>
public partial interface IPageError
public partial interface IWebError
{
/// <summary><para>The page that produced this unhandled exception, if any.</para></summary>
IPage? Page { get; }
Expand Down
4 changes: 2 additions & 2 deletions src/Playwright/Core/BrowserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ internal BrowserContext(IChannelOwner parent, string guid, BrowserContextInitial
{
var pageObject = e.Page?.Object;
var parsedError = string.IsNullOrEmpty(e.Error.Error.Stack) ? $"{e.Error.Error.Name}: {e.Error.Error.Message}" : e.Error.Error.Stack;
PageError?.Invoke(this, new PageError(pageObject, parsedError));
WebError?.Invoke(this, new WebError(pageObject, parsedError));
pageObject?.FirePageError(parsedError);
};
Channel.BindingCall += Channel_BindingCall;
Expand Down Expand Up @@ -169,7 +169,7 @@ public event EventHandler<IDialog> Dialog

public event EventHandler<IPage> Page;

public event EventHandler<IPageError> PageError;
public event EventHandler<IWebError> WebError;

public event EventHandler<IRequest> Request
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

namespace Microsoft.Playwright.Core;

internal class PageError : IPageError
internal class WebError : IWebError
{
public PageError(Page page, string error)
public WebError(Page page, string error)
{
Page = page;
Error = error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ private static object ParseEvaluateResultToExpando(JsonElement result, IDictiona
return new Regex(regex.GetProperty("p").ToString(), RegexOptionsExtensions.FromInlineFlags(regex.GetProperty("f").ToString()));
}

if (result.TryGetProperty("m", out var map))
{
var expando = new ExpandoObject();
refs.Add(map.GetProperty("id").GetInt32(), expando);
return expando;
}

if (result.TryGetProperty("se", out var set))
{
var expando = new ExpandoObject();
refs.Add(set.GetProperty("id").GetInt32(), expando);
return expando;
}

if (result.TryGetProperty("b", out var boolean))
{
return boolean.ToObject<bool>();
Expand All @@ -355,9 +369,7 @@ private static object ParseEvaluateResultToExpando(JsonElement result, IDictiona
var expando = new ExpandoObject();
refs.Add(result.GetProperty("id").GetInt32(), expando);
IDictionary<string, object> dict = expando;
var keyValues = obj.ToObject<KeyJsonElementValueObject[]>();

foreach (var kv in keyValues)
foreach (var kv in obj.ToObject<KeyJsonElementValueObject[]>())
{
dict[kv.K] = ParseEvaluateResultToExpando(kv.V, refs);
}
Expand Down

0 comments on commit 24edb58

Please sign in to comment.