From 8769f58049565689cb0ac1362eb1695d216e07fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 18:40:28 -0300 Subject: [PATCH 1/9] Port Playwright's check, wait-for-url, locator-list and selectors-text tests (Refs #1060) The testbed gets the /content route and Playwright's test assets (with its LICENSE and NOTICE), and the first four of upstream's Playwright page test files run against them. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- COMPATIBILITY.md | 1 + tests/E2E.Agent.Tests/PlaywrightRoutes.cs | 72 +++++++ tests/E2E.Agent.Tests/Testbed.cs | 2 +- tests/E2E.NUnit.Tests/Check/PageCheckTests.cs | 160 ++++++++++++++ tests/E2E.NUnit.Tests/E2E.NUnit.Tests.csproj | 2 + tests/E2E.NUnit.Tests/Helpers/Helpers.cs | 69 ++++++ .../LocatorList/LocatorListTests.cs | 27 +++ .../SelectorsText/SelectorsTextTests.cs | 62 ++++++ .../Testbed/playwright/LICENSE | 202 ++++++++++++++++++ .../E2E.NUnit.Tests/Testbed/playwright/NOTICE | 5 + .../Testbed/playwright/assets/empty.html | 0 .../Testbed/playwright/assets/grid.html | 66 ++++++ .../WaitForUrl/PageWaitForUrlTests.cs | 127 +++++++++++ 13 files changed, 794 insertions(+), 1 deletion(-) create mode 100644 tests/E2E.Agent.Tests/PlaywrightRoutes.cs create mode 100644 tests/E2E.NUnit.Tests/Check/PageCheckTests.cs create mode 100644 tests/E2E.NUnit.Tests/Helpers/Helpers.cs create mode 100644 tests/E2E.NUnit.Tests/LocatorList/LocatorListTests.cs create mode 100644 tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/LICENSE create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/NOTICE create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/empty.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/grid.html create mode 100644 tests/E2E.NUnit.Tests/WaitForUrl/PageWaitForUrlTests.cs diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 7f77ebc47..1bdd8a6c4 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -162,6 +162,7 @@ Differences: - Upstream's docs site pages that have no counterpart in the port: the page objects page (`docs/page-objects.mdx`, moved to `/page-object-model` in `d30114a`), `e2e feedback` and the `docs/reference/cli.mdx` text about its opt-out variables (`4c1e2e8`), and `examples/` with its registry (`b3ae3a4`, `38b802d`, `a29edcb`, `b54646f`). The migration guides (`docs/migrate/*.mdx`, `8537abc`) are ported: see [Migration guides](#migration-guides). The docs site has .NET-only guides for upstream's five example apps of `caf51eb` (tester-army/e2e#1497: i18n, file upload, location, biometrics, deep links), under [Examples](docs-site/src/content/docs/examples/index.mdx). They are not ports: that commit only adds registry entries that link to separate repositories, so there was no guide text. Each page writes C# tests for the upstream app. The self-healing deep dive (`6fa99ea`) is ported as the [Self-healing tests](README.md#self-healing-tests) section of the guide, since the port has no docs pages for the cache, the trace page, or executors to link to. Known gap: only `e2e explore` prints a run summary, since it is the one command that feeds a run to `ListReporter` (see [List reporter](#list-reporter)): the `Cache 4 replayed · 1 handed off · 1 missed` row is `Format.CacheText` over `Format.StepsCacheTally` (`E2E.Cli`, upstream's `cacheText` and `stepsCacheTally` of `report/format.ts`), which an exploration, with its cache off, never fills, and a test run does not print ([#799](https://github.com/hardkoded/e2e-dotnet/issues/799)) - Parallel workers and serial suites - `test.fail` and the `fail` test option (tester-army/e2e#1539, `732ea8a`): a test expected to fail, whose product failure passes and whose pass fails with `UNEXPECTED_PASS`. It lives in upstream's test registry, scheduler, retry, and reporters (`settleExpectedFailure` runs on a finished attempt), and the port has none of them. NUnit and xUnit v3 own the verdict and the retries, and neither has an expected-failure outcome, so a port would need a new public API of its own +- Playwright's page tests in the testbed suite (tester-army/e2e#1505, `bdf769b`) are ported in slices (hardkoded/e2e-dotnet#1060), as the `playwright` category of `tests/E2E.NUnit.Tests`, against the playground's `/content` route and Playwright's test assets (Apache-2.0, `Testbed/playwright/`, with Playwright's `LICENSE` and `NOTICE`). A test upstream marks `{ fail: 'reason' }` keeps its assertions inside the test-only `Helpers.ExpectedToFailAsync`, which passes while the body fails and fails once it passes. Ported so far: `check`, `wait-for-url`, `locator-list`, and `selectors-text` (one test is such a known difference, hardkoded/e2e-dotnet#1062). - Serial groups (upstream tester-army/e2e#1056, #1470): serial runs, group retries, and skipping the rest of a group after a failure belong to the test runner, which is NUnit or xUnit here, so the port keeps no serial groups. The schema has `serialAttempt.cutRetry` and the serial verdict is read from it, but nothing in the port writes a serial attempt: see [Report document](#report-document) - The out-of-process engine protocol (upstream tester-army/e2e#1232, [#873](https://github.com/hardkoded/e2e-dotnet/issues/873)): the port has no runner and no worker pool, so there is no engine process to talk to. An engine is written in .NET against `IEngine` - Diff-only observations for a custom executor's own model turns. The built-in agent has them (#1022): `#id` lines on the opening screen and on `observe`, and a diff after each action (see [MCP server](#mcp-server) for the presenter). `ExecutorObservation.Text`, which an executor reads from `Observe`, keeps the full `[ref=…]` snapshot, cut at the observation byte budget (see [Agents](#agents)), and a node is addressed by its ref there (`new ExecutorTarget("e12")`), so a custom executor has no presenter of its own. Upstream gives every executor the `#id` view. diff --git a/tests/E2E.Agent.Tests/PlaywrightRoutes.cs b/tests/E2E.Agent.Tests/PlaywrightRoutes.cs new file mode 100644 index 000000000..c27600fb8 --- /dev/null +++ b/tests/E2E.Agent.Tests/PlaywrightRoutes.cs @@ -0,0 +1,72 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using System.Net; +using System.Text; + +namespace E2E.Playground; + +/// +/// The routes of the tests ported from Playwright, a port of upstream's apps/testbed/app/playwright/routes.mjs: +/// its test assets (copied from microsoft/playwright tests/assets at v1.64.1, Apache-2.0, under +/// Testbed/playwright/assets next to the test assembly) and the dynamic routes its test server sets per test. +/// The playground serves them for any path it has no page for. This port has /content and the assets so far. +/// +internal static class PlaywrightRoutes +{ + private static readonly string Root = Path.Combine(AppContext.BaseDirectory, "Testbed", "playwright", "assets"); + + private static readonly Dictionary Types = new(StringComparer.Ordinal) + { + [".html"] = "text/html", + [".js"] = "text/javascript", + [".css"] = "text/css", + [".json"] = "application/json", + [".png"] = "image/png", + [".pdf"] = "application/pdf", + [".svg"] = "image/svg+xml", + [".txt"] = "text/plain", + }; + + /// Serves one request: a dynamic route, else an asset, else a 404. + public static async Task HandleAsync(HttpListenerContext context) + { + var response = context.Response; + var path = context.Request.Url!.AbsolutePath; + if (path == "/content") + { + var html = context.Request.QueryString["html"] ?? ""; + response.ContentType = "text/html; charset=utf-8"; + await WriteAsync(response, FromBase64Url(html)).ConfigureAwait(false); + return; + } + + var file = Path.GetFullPath(Path.Combine(Root, Uri.UnescapeDataString(path).TrimStart('/'))); + if (!file.StartsWith(Root + Path.DirectorySeparatorChar, StringComparison.Ordinal) || !File.Exists(file)) + { + response.StatusCode = 404; + response.ContentType = "text/plain"; + await WriteAsync(response, Encoding.UTF8.GetBytes("Not found")).ConfigureAwait(false); + return; + } + + response.ContentType = Types.GetValueOrDefault(Path.GetExtension(file), "application/octet-stream"); + response.AddHeader("Cache-Control", "no-store"); + await WriteAsync(response, await File.ReadAllBytesAsync(file).ConfigureAwait(false)).ConfigureAwait(false); + } + + private static byte[] FromBase64Url(string value) + { + var padded = value.Replace('-', '+').Replace('_', '/'); + padded = padded.PadRight(padded.Length + ((4 - (padded.Length % 4)) % 4), '='); + var bytes = new byte[padded.Length]; + return Convert.TryFromBase64String(padded, bytes, out var written) ? bytes[..written] : []; + } + + private static async Task WriteAsync(HttpListenerResponse response, byte[] bytes) + { + response.ContentLength64 = bytes.Length; + await response.OutputStream.WriteAsync(bytes).ConfigureAwait(false); + } +} diff --git a/tests/E2E.Agent.Tests/Testbed.cs b/tests/E2E.Agent.Tests/Testbed.cs index acdb010f7..d2a2336cf 100644 --- a/tests/E2E.Agent.Tests/Testbed.cs +++ b/tests/E2E.Agent.Tests/Testbed.cs @@ -1014,7 +1014,7 @@ await WriteHtmlAsync(response, "Dashboard", """ } else { - response.StatusCode = 404; + await PlaywrightRoutes.HandleAsync(context).ConfigureAwait(false); } response.Close(); diff --git a/tests/E2E.NUnit.Tests/Check/PageCheckTests.cs b/tests/E2E.NUnit.Tests/Check/PageCheckTests.cs new file mode 100644 index 000000000..174b0c70e --- /dev/null +++ b/tests/E2E.NUnit.Tests/Check/PageCheckTests.cs @@ -0,0 +1,160 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.Check; + +/// +/// test.describe('page check') of upstream's apps/testbed/tests/check.e2e.ts (Playwright's page-check.spec.ts). +/// Not ported, as upstream: should check the label with position (no position), trial run should not check and trial run +/// should not uncheck (no trial), should check the box using setChecked (no setChecked). +/// +public sealed class PageCheckTests : PlaywrightTest +{ + private static readonly string[] AriaRoles = ["checkbox", "menuitemcheckbox", "option", "radio", "switch", "menuitemradio", "treeitem"]; + + [Test] + public async Task Should_check_the_box() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").CheckAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.checkbox.checked"), Is.True); + } + + [Test] + public async Task Should_not_check_the_checked_box() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").CheckAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.checkbox.checked"), Is.True); + } + + [Test] + public async Task Should_uncheck_the_box() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").UncheckAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.checkbox.checked"), Is.False); + } + + [Test] + public async Task Should_not_uncheck_the_unchecked_box() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").UncheckAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.checkbox.checked"), Is.False); + } + + [Test] + public async Task Should_check_radio() + { + await Browser.GotoAsync(Content(""" + one + two + three + """)); + await Browser.Locator("#two").CheckAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.two.checked"), Is.True); + } + + [Test] + public async Task Should_check_radio_by_aria_role() + { + await Browser.GotoAsync(Content(""" + + + """)); + await Browser.Locator("div").CheckAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.checkbox.getAttribute('aria-checked')"), Is.EqualTo("true")); + } + + // Upstream: { fail: '`uncheck` refuses a `role=radio`, where Playwright clicks it and refuses only a native radio' }. + [Test] + public async Task Should_uncheck_radio_by_aria_role() + { + await ExpectedToFailAsync(async () => + { + await Browser.GotoAsync(Content(""" + + + """)); + await Browser.Locator("div").UncheckAsync(); + Equal("false", await Browser.EvaluateAsync("() => window.checkbox.getAttribute('aria-checked')")); + }); + } + + [Test] + public async Task Should_check_the_box_by_aria_role() + { + foreach (var role in AriaRoles) + { + await Browser.GotoAsync(Content($$""" +
CHECKBOX
+ + """)); + await Browser.Locator("div").CheckAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.checkbox.getAttribute('aria-checked')"), Is.EqualTo("true")); + } + } + + // Upstream: { fail: '`uncheck` refuses a `role=radio`, where Playwright clicks it and refuses only a native radio' }. + [Test] + public async Task Should_uncheck_the_box_by_aria_role() + { + await ExpectedToFailAsync(async () => + { + foreach (var role in AriaRoles) + { + await Browser.GotoAsync(Content($$""" +
CHECKBOX
+ + """)); + await Browser.Locator("div").UncheckAsync(); + Equal("false", await Browser.EvaluateAsync("() => window.checkbox.getAttribute('aria-checked')")); + } + }); + } + + [Test] + public async Task Should_throw_when_not_a_checkbox() + { + await Browser.GotoAsync(Content("
Check me
")); + var error = await Assert.CatchAsync(() => Browser.Locator("div").CheckAsync()); + Assert.That(error!.Message, Does.Contain("Not a checkbox or radio button")); + } + + [Test] + public async Task Should_throw_when_not_a_checkbox_2() + { + await Browser.GotoAsync(Content("
Check me
")); + var error = await Assert.CatchAsync(() => Browser.Locator("div").CheckAsync()); + Assert.That(error!.Message, Does.Contain("Not a checkbox or radio button")); + } + + [Test] + public async Task Should_check_the_box_inside_a_button() + { + await Browser.GotoAsync(Content("
")); + await Browser.Locator("input").CheckAsync(); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('input').checked"), Is.True); + Assert.That(await Browser.Locator("input").IsCheckedAsync(), Is.True); + } + + [Test] + public async Task Should_throw_when_trying_to_uncheck_radio_button() + { + await Browser.GotoAsync(Content("")); + var error = await Assert.CatchAsync(() => Browser.Locator("#radio").UncheckAsync()); + Assert.That(error!.Message, Does.Contain("uncheck cannot clear a radio button")); + } +} diff --git a/tests/E2E.NUnit.Tests/E2E.NUnit.Tests.csproj b/tests/E2E.NUnit.Tests/E2E.NUnit.Tests.csproj index ae5cb97ad..b71222b73 100644 --- a/tests/E2E.NUnit.Tests/E2E.NUnit.Tests.csproj +++ b/tests/E2E.NUnit.Tests/E2E.NUnit.Tests.csproj @@ -16,7 +16,9 @@ + + diff --git a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs new file mode 100644 index 000000000..994ac1351 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs @@ -0,0 +1,69 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using System.Text; + +namespace E2E.NUnit.Tests; + +/// +/// The helpers of the tests ported from Playwright, upstream's apps/testbed/tests/helpers.ts: +/// content and PREFIX. is .NET-only (see its summary). +/// +internal static class Helpers +{ + /// The app's origin, Playwright's server.PREFIX in the tests ported from it. + public static string PREFIX => E2E.Playground.Testbed.Url; + + /// A path that serves as a page, for Playwright's page.setContent(html). + public static string Content(string html) => + "/content?html=" + Convert.ToBase64String(Encoding.UTF8.GetBytes(html)).TrimEnd('=').Replace('+', '-').Replace('/', '_'); + + /// + /// An equality check for a body run by . It throws: an NUnit assertion inside a test body is + /// recorded as a failure of the test even when the body catches it. + /// + public static void Equal(T expected, T actual) + { + if (!EqualityComparer.Default.Equals(expected, actual)) + { + throw new InvalidOperationException($"Expected {expected}, but was {actual}."); + } + } + + /// + /// Runs the body of a test upstream marks { fail: 'reason' }, a known difference from Playwright: the test passes while + /// still fails, and fails once it passes, so the marker is removed. The port has no fail test option + /// (see COMPATIBILITY.md), and NUnit has no expected-failure outcome. + /// + public static async Task ExpectedToFailAsync(Func body) + { + try + { + await body().ConfigureAwait(false); + } + catch (Exception ex) when (ex is not OperationCanceledException) + { + return; + } + + Assert.Fail("UNEXPECTED_PASS: the test is marked as a known difference from Playwright, and it passed. Remove the marker."); + } +} + +/// +/// The base of the classes ported from Playwright's page tests: the playground as the base URL, the cache off, and the playwright +/// category (upstream's tags: ['playwright']). +/// +[Category("playwright")] +public abstract class PlaywrightTest : E2ETest +{ + private static readonly E2EConfig FixtureConfig = E2EConfig.Parse( + """{ "cache": { "mode": "off" } }""", + AppContext.BaseDirectory, + _ => null); + + protected override E2EConfig Config => FixtureConfig; + + protected override string? BaseUrl => E2E.Playground.Testbed.Url; +} diff --git a/tests/E2E.NUnit.Tests/LocatorList/LocatorListTests.cs b/tests/E2E.NUnit.Tests/LocatorList/LocatorListTests.cs new file mode 100644 index 000000000..9d25b0898 --- /dev/null +++ b/tests/E2E.NUnit.Tests/LocatorList/LocatorListTests.cs @@ -0,0 +1,27 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.LocatorList; + +/// +/// test.describe('locator list') of upstream's apps/testbed/tests/locator-list.e2e.ts (Playwright's +/// locator-list.spec.ts). div >> p is the CSS div p. +/// +public sealed class LocatorListTests : PlaywrightTest +{ + [Test] + public async Task Locator_all_should_work() + { + await Browser.GotoAsync(Content("

A

B

C

")); + var texts = new List(); + foreach (var p in await Browser.Locator("div p").AllAsync()) + { + texts.Add(await p.TextContentAsync()); + } + + Assert.That(texts, Is.EqualTo(new[] { "A", "B", "C" })); + } +} diff --git a/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs b/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs new file mode 100644 index 000000000..30eb20b81 --- /dev/null +++ b/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs @@ -0,0 +1,62 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using System.Text.RegularExpressions; +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.SelectorsText; + +/// +/// test.describe('selectors text') of upstream's apps/testbed/tests/selectors-text.e2e.ts (Playwright's +/// selectors-text.spec.ts). locator(css, { hasText }) is a locator Filter(hasText). The 20 other tests are not +/// ported, as upstream: they need Playwright's text= selectors, :text pseudo-classes, >> chains, or element handles. +/// +public sealed partial class SelectorsTextTests : PlaywrightTest +{ + [Test] + public async Task Text_is_should_ignore_comments() + { + await Browser.GotoAsync(Content(""" +
hello + + world
+ """)); + Assert.That(await Browser.Locator("div").Filter(hasText: "hello world").GetAttributeAsync("id"), Is.EqualTo("me")); + Assert.That(await Screen.GetByText("hello world").GetAttributeAsync("id"), Is.EqualTo("me")); + } + + // Known difference, hardkoded/e2e-dotnet#1062: the first getByText('hello') match has no `id`. + [Test] + public async Task HasText_and_internal_text_should_match_full_node_text_in_strict_mode() + { + await ExpectedToFailAsync(async () => + { + await Browser.GotoAsync(Content(""" +
helloworld
+
hello
+ """)); + await Expect.That(Screen.GetByText("helloworld")).ToHaveAttributeAsync("id", "div1"); + await Expect.That(Screen.GetByText("hello")).ToHaveAttributeAsync("id", "div2"); + await Expect.That(Browser.Locator("div").Filter(hasText: HelloWorld())).ToHaveAttributeAsync("id", "div1"); + await Expect.That(Browser.Locator("div").Filter(hasText: Hello())).ToHaveAttributeAsync("id", "div2"); + + await Browser.GotoAsync(Content(""" +
helloworld
+
hello
+ """)); + await Expect.That(Screen.GetByText("helloworld")).ToHaveAttributeAsync("id", "div1"); + Equal("span1", await Screen.GetByText("hello").Nth(0).GetAttributeAsync("id")); + Equal("span2", await Screen.GetByText("hello").Nth(1).GetAttributeAsync("id")); + await Expect.That(Screen.GetByText("hello")).ToHaveCountAsync(2); + await Expect.That(Browser.Locator("div").Filter(hasText: HelloWorld())).ToHaveAttributeAsync("id", "div1"); + await Expect.That(Browser.Locator("div").Filter(hasText: Hello())).ToHaveAttributeAsync("id", "div2"); + }); + } + + [GeneratedRegex(@"^helloworld$")] + private static partial Regex HelloWorld(); + + [GeneratedRegex(@"^hello$")] + private static partial Regex Hello(); +} diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/LICENSE b/tests/E2E.NUnit.Tests/Testbed/playwright/LICENSE new file mode 100644 index 000000000..4ace03ddb --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Portions Copyright (c) Microsoft Corporation. + Portions Copyright 2017 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/NOTICE b/tests/E2E.NUnit.Tests/Testbed/playwright/NOTICE new file mode 100644 index 000000000..814ec1696 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/NOTICE @@ -0,0 +1,5 @@ +Playwright +Copyright (c) Microsoft Corporation + +This software contains code derived from the Puppeteer project (https://github.com/puppeteer/puppeteer), +available under the Apache 2.0 license (https://github.com/puppeteer/puppeteer/blob/master/LICENSE). diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/empty.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/empty.html new file mode 100644 index 000000000..e69de29bb diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/grid.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/grid.html new file mode 100644 index 000000000..8345f429b --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/grid.html @@ -0,0 +1,66 @@ + + + diff --git a/tests/E2E.NUnit.Tests/WaitForUrl/PageWaitForUrlTests.cs b/tests/E2E.NUnit.Tests/WaitForUrl/PageWaitForUrlTests.cs new file mode 100644 index 000000000..29bb79f45 --- /dev/null +++ b/tests/E2E.NUnit.Tests/WaitForUrl/PageWaitForUrlTests.cs @@ -0,0 +1,127 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using System.Text.RegularExpressions; +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.WaitForUrl; + +/// +/// test.describe('page wait for url') of upstream's apps/testbed/tests/wait-for-url.e2e.ts (Playwright's +/// page-wait-for-url.spec.ts). Not ported, as upstream: should work with both domcontentloaded and load, should work with +/// commit, should work with commit and about:blank (no waitUntil), should work on frame (no frame.waitForURL). +/// +public sealed partial class PageWaitForUrlTests : PlaywrightTest +{ + private static string EmptyPage => $"{PREFIX}/empty.html"; + + [Test] + public async Task Should_work() + { + await Browser.GotoAsync(EmptyPage); + await Browser.EvaluateAsync("(url) => { window.location.href = url; }", $"{PREFIX}/grid.html"); + await Browser.WaitForURLAsync("/grid.html"); + } + + [Test] + public async Task Should_respect_timeout() + { + // e2e opens no page before the first goto, where Playwright starts on about:blank. + await Browser.GotoAsync(EmptyPage); + var promise = Assert.CatchAsync(() => Browser.WaitForURLAsync("/frame.html", TimeSpan.FromMilliseconds(2500))); + await Browser.GotoAsync(EmptyPage); + var error = await promise; + Assert.That(error!.Message, Does.Contain("frame.html")); + } + + [Test] + public async Task Should_work_with_clicking_on_anchor_links() + { + await Browser.GotoAsync(EmptyPage); + await Browser.GotoAsync(Content("foobar")); + await Browser.Locator("a").TapAsync(); + await Browser.WaitForURLAsync(FoobarSuffix()); + } + + [Test] + public async Task Should_work_with_history_pushState() + { + await Browser.GotoAsync(EmptyPage); + await Browser.GotoAsync(Content(""" + SPA + + """)); + await Browser.Locator("a").TapAsync(); + await Browser.WaitForURLAsync("/wow.html"); + Assert.That(await Browser.UrlAsync(), Is.EqualTo($"{PREFIX}/wow.html")); + } + + [Test] + public async Task Should_work_with_history_replaceState() + { + await Browser.GotoAsync(EmptyPage); + await Browser.GotoAsync(Content(""" + SPA + + """)); + await Browser.Locator("a").TapAsync(); + await Browser.WaitForURLAsync("/replaced.html"); + Assert.That(await Browser.UrlAsync(), Is.EqualTo($"{PREFIX}/replaced.html")); + } + + [Test] + public async Task Should_work_with_DOM_history_back_history_forward() + { + await Browser.GotoAsync(EmptyPage); + await Browser.GotoAsync(Content(""" + back + forward + + """)); + Assert.That(await Browser.UrlAsync(), Is.EqualTo($"{PREFIX}/second.html")); + + await Browser.Locator("a#back").TapAsync(); + await Browser.WaitForURLAsync("/first.html"); + Assert.That(await Browser.UrlAsync(), Is.EqualTo($"{PREFIX}/first.html")); + + await Browser.Locator("a#forward").TapAsync(); + await Browser.WaitForURLAsync("/second.html"); + Assert.That(await Browser.UrlAsync(), Is.EqualTo($"{PREFIX}/second.html")); + } + + [Test] + public async Task Should_work_with_url_match_for_same_document_navigations() + { + await Browser.GotoAsync(EmptyPage); + var resolved = false; + var waitPromise = Task.Run(async () => + { + await Browser.WaitForURLAsync(ThirdHtml()); + resolved = true; + }); + Assert.That(resolved, Is.False); + await Browser.EvaluateAsync("() => { history.pushState({}, '', '/first.html'); }"); + Assert.That(resolved, Is.False); + await Browser.EvaluateAsync("() => { history.pushState({}, '', '/second.html'); }"); + Assert.That(resolved, Is.False); + await Browser.EvaluateAsync("() => { history.pushState({}, '', '/third.html'); }"); + await waitPromise; + Assert.That(resolved, Is.True); + } + + [GeneratedRegex(@"#foobar$")] + private static partial Regex FoobarSuffix(); + + [GeneratedRegex(@"third\.html")] + private static partial Regex ThirdHtml(); +} From b9f92cf450fe125e214362320fa98dd8fbc18cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 18:43:21 -0300 Subject: [PATCH 2/9] Link the routes into the xUnit test project and pin the known difference of expected failures (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.NUnit.Tests/Check/PageCheckTests.cs | 4 ++-- tests/E2E.NUnit.Tests/Helpers/Helpers.cs | 5 +++-- tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs | 2 +- tests/E2E.XUnit.V3.Tests/E2E.XUnit.V3.Tests.csproj | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/E2E.NUnit.Tests/Check/PageCheckTests.cs b/tests/E2E.NUnit.Tests/Check/PageCheckTests.cs index 174b0c70e..0895e69e9 100644 --- a/tests/E2E.NUnit.Tests/Check/PageCheckTests.cs +++ b/tests/E2E.NUnit.Tests/Check/PageCheckTests.cs @@ -76,7 +76,7 @@ await Browser.GotoAsync(Content(""" [Test] public async Task Should_uncheck_radio_by_aria_role() { - await ExpectedToFailAsync(async () => + await ExpectedToFailAsync("uncheck", async () => { await Browser.GotoAsync(Content(""" @@ -109,7 +109,7 @@ await Browser.GotoAsync(Content($$""" [Test] public async Task Should_uncheck_the_box_by_aria_role() { - await ExpectedToFailAsync(async () => + await ExpectedToFailAsync("uncheck", async () => { foreach (var role in AriaRoles) { diff --git a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs index 994ac1351..da38a9b5c 100644 --- a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs +++ b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs @@ -33,10 +33,10 @@ public static void Equal(T expected, T actual) /// /// Runs the body of a test upstream marks { fail: 'reason' }, a known difference from Playwright: the test passes while - /// still fails, and fails once it passes, so the marker is removed. The port has no fail test option + /// still fails with a message that contains , and fails once it passes, so the marker is removed. The port has no fail test option /// (see COMPATIBILITY.md), and NUnit has no expected-failure outcome. /// - public static async Task ExpectedToFailAsync(Func body) + public static async Task ExpectedToFailAsync(string failure, Func body) { try { @@ -44,6 +44,7 @@ public static async Task ExpectedToFailAsync(Func body) } catch (Exception ex) when (ex is not OperationCanceledException) { + Assert.That(ex.Message, Does.Contain(failure), "the body failed, but not with the known difference"); return; } diff --git a/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs b/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs index 30eb20b81..c14218e4a 100644 --- a/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs +++ b/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs @@ -30,7 +30,7 @@ await Browser.GotoAsync(Content(""" [Test] public async Task HasText_and_internal_text_should_match_full_node_text_in_strict_mode() { - await ExpectedToFailAsync(async () => + await ExpectedToFailAsync("Expected span1", async () => { await Browser.GotoAsync(Content("""
helloworld
diff --git a/tests/E2E.XUnit.V3.Tests/E2E.XUnit.V3.Tests.csproj b/tests/E2E.XUnit.V3.Tests/E2E.XUnit.V3.Tests.csproj index 9d764e906..43d87e126 100644 --- a/tests/E2E.XUnit.V3.Tests/E2E.XUnit.V3.Tests.csproj +++ b/tests/E2E.XUnit.V3.Tests/E2E.XUnit.V3.Tests.csproj @@ -19,6 +19,7 @@ + From d947b3f7b13f918166dd09221af68b52398748df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 18:55:58 -0300 Subject: [PATCH 3/9] Port Playwright's fill, select-option, set-input-files and filechooser tests (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- COMPATIBILITY.md | 2 +- tests/E2E.Agent.Tests/PlaywrightRoutes.cs | 76 +++ tests/E2E.Agent.Tests/Testbed.cs | 1 + .../Filechooser/PageFilechooserTests.cs | 141 ++++++ tests/E2E.NUnit.Tests/Fill/PageFillTests.cs | 469 ++++++++++++++++++ tests/E2E.NUnit.Tests/Helpers/Helpers.cs | 6 + .../SelectOption/PageSelectOptionTests.cs | 330 ++++++++++++ .../SetInputFiles/PageSetInputFilesTests.cs | 344 +++++++++++++ .../playwright/assets/file to upload.txt | 1 + .../playwright/assets/file-to-upload-2.txt | 1 + .../playwright/assets/file-to-upload.txt | 1 + .../assets/input/fileupload-multi.html | 12 + .../playwright/assets/input/fileupload.html | 12 + .../playwright/assets/input/folderupload.html | 12 + .../playwright/assets/input/select.html | 70 +++ .../playwright/assets/input/textarea.html | 20 + .../Testbed/playwright/assets/pptr.png | Bin 0 -> 6138 bytes 17 files changed, 1497 insertions(+), 1 deletion(-) create mode 100644 tests/E2E.NUnit.Tests/Filechooser/PageFilechooserTests.cs create mode 100644 tests/E2E.NUnit.Tests/Fill/PageFillTests.cs create mode 100644 tests/E2E.NUnit.Tests/SelectOption/PageSelectOptionTests.cs create mode 100644 tests/E2E.NUnit.Tests/SetInputFiles/PageSetInputFilesTests.cs create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/file to upload.txt create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/file-to-upload-2.txt create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/file-to-upload.txt create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/fileupload-multi.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/fileupload.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/folderupload.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/select.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/textarea.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/pptr.png diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 1bdd8a6c4..78f4225bd 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -162,7 +162,7 @@ Differences: - Upstream's docs site pages that have no counterpart in the port: the page objects page (`docs/page-objects.mdx`, moved to `/page-object-model` in `d30114a`), `e2e feedback` and the `docs/reference/cli.mdx` text about its opt-out variables (`4c1e2e8`), and `examples/` with its registry (`b3ae3a4`, `38b802d`, `a29edcb`, `b54646f`). The migration guides (`docs/migrate/*.mdx`, `8537abc`) are ported: see [Migration guides](#migration-guides). The docs site has .NET-only guides for upstream's five example apps of `caf51eb` (tester-army/e2e#1497: i18n, file upload, location, biometrics, deep links), under [Examples](docs-site/src/content/docs/examples/index.mdx). They are not ports: that commit only adds registry entries that link to separate repositories, so there was no guide text. Each page writes C# tests for the upstream app. The self-healing deep dive (`6fa99ea`) is ported as the [Self-healing tests](README.md#self-healing-tests) section of the guide, since the port has no docs pages for the cache, the trace page, or executors to link to. Known gap: only `e2e explore` prints a run summary, since it is the one command that feeds a run to `ListReporter` (see [List reporter](#list-reporter)): the `Cache 4 replayed · 1 handed off · 1 missed` row is `Format.CacheText` over `Format.StepsCacheTally` (`E2E.Cli`, upstream's `cacheText` and `stepsCacheTally` of `report/format.ts`), which an exploration, with its cache off, never fills, and a test run does not print ([#799](https://github.com/hardkoded/e2e-dotnet/issues/799)) - Parallel workers and serial suites - `test.fail` and the `fail` test option (tester-army/e2e#1539, `732ea8a`): a test expected to fail, whose product failure passes and whose pass fails with `UNEXPECTED_PASS`. It lives in upstream's test registry, scheduler, retry, and reporters (`settleExpectedFailure` runs on a finished attempt), and the port has none of them. NUnit and xUnit v3 own the verdict and the retries, and neither has an expected-failure outcome, so a port would need a new public API of its own -- Playwright's page tests in the testbed suite (tester-army/e2e#1505, `bdf769b`) are ported in slices (hardkoded/e2e-dotnet#1060), as the `playwright` category of `tests/E2E.NUnit.Tests`, against the playground's `/content` route and Playwright's test assets (Apache-2.0, `Testbed/playwright/`, with Playwright's `LICENSE` and `NOTICE`). A test upstream marks `{ fail: 'reason' }` keeps its assertions inside the test-only `Helpers.ExpectedToFailAsync`, which passes while the body fails and fails once it passes. Ported so far: `check`, `wait-for-url`, `locator-list`, and `selectors-text` (one test is such a known difference, hardkoded/e2e-dotnet#1062). +- Playwright's page tests in the testbed suite (tester-army/e2e#1505, `bdf769b`) are ported in slices (hardkoded/e2e-dotnet#1060), as the `playwright` category of `tests/E2E.NUnit.Tests`, against the playground's `/content` route and Playwright's test assets (Apache-2.0, `Testbed/playwright/`, with Playwright's `LICENSE` and `NOTICE`). A test upstream marks `{ fail: 'reason' }` keeps its assertions inside the test-only `Helpers.ExpectedToFailAsync`, which passes while the body fails and fails once it passes. Ported so far: `check`, `wait-for-url`, `locator-list`, `selectors-text` (one test is such a known difference, hardkoded/e2e-dotnet#1062), `fill`, `select-option`, `set-input-files`, and `filechooser`. Upstream's `select-option` test marked `fail` (a bare string selects by label only) passes in the port, which matches a value or a label, so it has no marker. A missing file reports .NET's `Could not find file`, where upstream shows Node's `ENOENT`. - Serial groups (upstream tester-army/e2e#1056, #1470): serial runs, group retries, and skipping the rest of a group after a failure belong to the test runner, which is NUnit or xUnit here, so the port keeps no serial groups. The schema has `serialAttempt.cutRetry` and the serial verdict is read from it, but nothing in the port writes a serial attempt: see [Report document](#report-document) - The out-of-process engine protocol (upstream tester-army/e2e#1232, [#873](https://github.com/hardkoded/e2e-dotnet/issues/873)): the port has no runner and no worker pool, so there is no engine process to talk to. An engine is written in .NET against `IEngine` - Diff-only observations for a custom executor's own model turns. The built-in agent has them (#1022): `#id` lines on the opening screen and on `observe`, and a diff after each action (see [MCP server](#mcp-server) for the presenter). `ExecutorObservation.Text`, which an executor reads from `Observe`, keeps the full `[ref=…]` snapshot, cut at the observation byte budget (see [Agents](#agents)), and a node is addressed by its ref there (`new ExecutorTarget("e12")`), so a custom executor has no presenter of its own. Upstream gives every executor the `#id` view. diff --git a/tests/E2E.Agent.Tests/PlaywrightRoutes.cs b/tests/E2E.Agent.Tests/PlaywrightRoutes.cs index c27600fb8..a3630a979 100644 --- a/tests/E2E.Agent.Tests/PlaywrightRoutes.cs +++ b/tests/E2E.Agent.Tests/PlaywrightRoutes.cs @@ -2,8 +2,11 @@ // Modified by Dario Kondratiuk. // SPDX-License-Identifier: Apache-2.0 +using System.Globalization; using System.Net; using System.Text; +using System.Text.Json; +using System.Text.RegularExpressions; namespace E2E.Playground; @@ -42,6 +45,35 @@ public static async Task HandleAsync(HttpListenerContext context) return; } + if (path == "/respond") + { + var query = context.Request.QueryString; + response.StatusCode = int.Parse(query["status"] ?? "200", CultureInfo.InvariantCulture); + if (query["headers"] is { } headers) + { + foreach (var (name, value) in JsonSerializer.Deserialize>(headers)!) + { + if (name.Equals("content-type", StringComparison.OrdinalIgnoreCase)) + { + response.ContentType = value; + } + else + { + response.AddHeader(name, value); + } + } + } + + await WriteAsync(response, Encoding.UTF8.GetBytes(query["body"] ?? "")).ConfigureAwait(false); + return; + } + + if (path == "/upload") + { + await UploadAsync(context).ConfigureAwait(false); + return; + } + var file = Path.GetFullPath(Path.Combine(Root, Uri.UnescapeDataString(path).TrimStart('/'))); if (!file.StartsWith(Root + Path.DirectorySeparatorChar, StringComparison.Ordinal) || !File.Exists(file)) { @@ -56,6 +88,50 @@ public static async Task HandleAsync(HttpListenerContext context) await WriteAsync(response, await File.ReadAllBytesAsync(file).ConfigureAwait(false)).ConfigureAwait(false); } + /// Answers a multipart form with the files it carried as JSON, as upstream's /upload: name, filename, mimetype, size, and the bytes (base64) of a file up to 64 KB. + private static async Task UploadAsync(HttpListenerContext context) + { + using var received = new MemoryStream(); + await context.Request.InputStream.CopyToAsync(received).ConfigureAwait(false); + var data = received.GetBuffer().AsMemory(0, (int)received.Length); + var type = context.Request.ContentType ?? ""; + var marker = type.IndexOf("boundary=", StringComparison.Ordinal); + var boundary = Encoding.UTF8.GetBytes("--" + (marker < 0 ? "" : type[(marker + "boundary=".Length)..])); + var files = new List>(); + var start = data.Span.IndexOf(boundary); + while (start >= 0) + { + var afterStart = start + boundary.Length; + var relative = data.Span[afterStart..].IndexOf(boundary); + if (relative < 0) + { + break; + } + + var next = afterStart + relative; + var part = data[(afterStart + 2)..(next - 2)]; + var split = part.Span.IndexOf("\r\n\r\n"u8); + var head = Encoding.UTF8.GetString(part.Span[..split]); + var body = part[(split + 4)..]; + files.Add(new Dictionary + { + ["name"] = Capture(head, "name=\"([^\"]*)\""), + ["filename"] = Capture(head, "filename=\"([^\"]*)\""), + ["mimetype"] = Capture(head, "content-type: ([^\r\n]+)"), + ["size"] = body.Length, + ["base64"] = body.Length <= 65536 ? Convert.ToBase64String(body.Span) : null, + }); + start = next; + } + + context.Response.ContentType = "text/plain"; + context.Response.AddHeader("Access-Control-Allow-Origin", "*"); + await WriteAsync(context.Response, JsonSerializer.SerializeToUtf8Bytes(files)).ConfigureAwait(false); + } + + private static string? Capture(string text, string pattern) => + Regex.Match(text, pattern, RegexOptions.IgnoreCase) is { Success: true } match ? match.Groups[1].Value : null; + private static byte[] FromBase64Url(string value) { var padded = value.Replace('-', '+').Replace('_', '/'); diff --git a/tests/E2E.Agent.Tests/Testbed.cs b/tests/E2E.Agent.Tests/Testbed.cs index d2a2336cf..02118f198 100644 --- a/tests/E2E.Agent.Tests/Testbed.cs +++ b/tests/E2E.Agent.Tests/Testbed.cs @@ -929,6 +929,7 @@ private static string Start() url = "http://127.0.0.1:" + port.ToString(CultureInfo.InvariantCulture) + "/"; listener = new HttpListener(); listener.Prefixes.Add(url); + listener.Prefixes.Add(url.Replace("127.0.0.1", "localhost", StringComparison.Ordinal)); try { listener.Start(); diff --git a/tests/E2E.NUnit.Tests/Filechooser/PageFilechooserTests.cs b/tests/E2E.NUnit.Tests/Filechooser/PageFilechooserTests.cs new file mode 100644 index 000000000..14215dd72 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Filechooser/PageFilechooserTests.cs @@ -0,0 +1,141 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.Filechooser; + +/// +/// test.describe('page filechooser') of upstream's apps/testbed/tests/filechooser.e2e.ts (Playwright's +/// page-filechooser.spec.ts). A file chooser is answered by SetInputFilesAsync on the control whose click opens it, so the +/// page's own click() on the input is a button that does it. Not ported, as upstream: should emit event once, should emit event via +/// prepend, should emit event for iframe, should emit event on/off, should emit event addListener/removeListener, should work when file input +/// is attached to DOM, should not throw when filechooser belongs to iframe, should not throw when frame is detached immediately, should +/// respect timeout, should respect default timeout when there is no custom timeout, should prioritize exact timeout over default timeout, +/// should work with no timeout, should abort with signal, should return the same file chooser when there are many watchdogs simultaneously, +/// should work for single file pick, should work for "multiple", should work for "webkitdirectory", should trigger listener added before +/// navigation (no filechooser events and no FileChooser objects); should not trim big uploaded files (no file chooser; ported in +/// SetInputFiles/PageSetInputFilesTests). +/// +public sealed class PageFilechooserTests : PlaywrightTest +{ + /// A button whose click clicks the page's file input, as picker.click() does in Playwright's tests. + private const string Picker = ""; + + /// Resolves, in the page, with the first picked file's text once the input fires input. + private const string ReadPicked = """ + () => { + const picker = document.querySelector('input'); + window.picked = new Promise((x) => { picker.oninput = x; }).then(() => { + const reader = new FileReader(); + const promise = new Promise((fulfill) => { reader.onload = fulfill; }); + reader.readAsText(picker.files[0]); + return promise.then(() => reader.result); + }); + } + """; + + [Test] + public async Task Should_upload_multiple_large_files() + { + const int filesCount = 10; + await Browser.GotoAsync("/input/fileupload-multi.html"); + var dir = Directory.CreateTempSubdirectory("e2e-chooser-").FullName; + try + { + var uploadFile = Path.Combine(dir, "50MB_1.zip"); + var chunk = new byte[1024]; + Array.Fill(chunk, (byte)'A'); + await using (var stream = File.Create(uploadFile)) + { + for (var i = 0; i < 49 * 1024; i++) + { + await stream.WriteAsync(chunk); + } + } + + var uploadFiles = new List { uploadFile }; + for (var i = 2; i <= filesCount; i++) + { + var dstFile = Path.Combine(dir, $"50MB_{i}.zip"); + File.Copy(uploadFile, dstFile); + uploadFiles.Add(dstFile); + } + + await Browser.EvaluateAsync("() => { const button = document.createElement('button'); button.textContent = 'pick'; button.type = 'button'; button.onclick = () => document.querySelector('input[type=\"file\"]').click(); document.body.append(button); }"); + await Browser.Locator("button").SetInputFilesAsync(uploadFiles); + var filesLen = await Browser.EvaluateAsync("document.getElementsByTagName(\"input\")[0].files.length"); + Assert.That(filesLen, Is.EqualTo(filesCount)); + } + finally + { + Directory.Delete(dir, recursive: true); + } + } + + [Test] + public async Task Should_work_when_file_input_is_not_attached_to_DOM() + { + await Browser.GotoAsync(Content(""" + + """)); + await Browser.Locator("button").SetInputFilesAsync(Asset("file-to-upload.txt")); + Assert.That(await Browser.EvaluateAsync("() => window.picked"), Is.EqualTo("contents of the file")); + } + + [Test] + public async Task Should_accept_single_file() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("button").SetInputFilesAsync(Asset("file-to-upload.txt")); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('input').files.length"), Is.EqualTo(1)); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('input').files[0].name"), Is.EqualTo("file-to-upload.txt")); + } + + [Test] + public async Task Should_be_able_to_read_selected_file() + { + await Browser.GotoAsync(Content(Picker)); + await Browser.EvaluateAsync(ReadPicked); + await Browser.Locator("button").SetInputFilesAsync(Asset("file-to-upload.txt")); + Assert.That(await Browser.EvaluateAsync("() => window.picked"), Is.EqualTo("contents of the file")); + } + + // Upstream: { skip: '`setInputFiles([])` is refused, so there is no way to clear a file input (refused as INVALID_ARGUMENT, which `fail` does not cover)' }. + [Test] + [Ignore("`SetInputFilesAsync([])` is refused, so there is no way to clear a file input (refused as INVALID_ARGUMENT, which a known difference does not cover)")] + public async Task Should_be_able_to_reset_selected_files_with_empty_file_list() + { + await Browser.GotoAsync(Content(Picker)); + const string watchLength = "() => { const picker = document.querySelector('input'); window.picked = new Promise((x) => { picker.oninput = x; }).then(() => picker.files.length); }"; + await Browser.EvaluateAsync(watchLength); + await Browser.Locator("button").SetInputFilesAsync(Asset("file-to-upload.txt")); + Assert.That(await Browser.EvaluateAsync("() => window.picked"), Is.EqualTo(1)); + await Browser.EvaluateAsync(watchLength); + await Browser.Locator("button").SetInputFilesAsync([]); + Assert.That(await Browser.EvaluateAsync("() => window.picked"), Is.EqualTo(0)); + } + + [Test] + public async Task Should_emit_event_after_navigation() + { + await Browser.GotoAsync($"{PREFIX}/empty.html"); + await Browser.GotoAsync(Content(Picker)); + await Browser.Locator("button").SetInputFilesAsync(Asset("file-to-upload.txt")); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('input').files.length"), Is.EqualTo(1)); + await Browser.GotoAsync($"{CROSS}/empty.html"); + await Browser.GotoAsync($"{CROSS}{Content(Picker)}"); + await Browser.Locator("button").SetInputFilesAsync(Asset("file-to-upload.txt")); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('input').files.length"), Is.EqualTo(1)); + } +} diff --git a/tests/E2E.NUnit.Tests/Fill/PageFillTests.cs b/tests/E2E.NUnit.Tests/Fill/PageFillTests.cs new file mode 100644 index 000000000..595c1b7ab --- /dev/null +++ b/tests/E2E.NUnit.Tests/Fill/PageFillTests.cs @@ -0,0 +1,469 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using System.Text.RegularExpressions; +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.Fill; + +/// +/// test.describe('page fill') of upstream's apps/testbed/tests/fill.e2e.ts (Playwright's page-fill.spec.ts). +/// Not ported, as upstream: should throw if passed a non-string value (Fill is typed to strings). +/// +public sealed partial class PageFillTests : PlaywrightTest +{ + /// Five pairs of animation frames, Playwright's rafraf(page, 5), so a pending fill has had its chance. + private const string GiveItAChanceToFill = + "() => new Promise((resolve) => { let frames = 0; const step = () => (++frames === 10 ? setTimeout(resolve, 0) : requestAnimationFrame(step)); requestAnimationFrame(step); })"; + + private async Task ValueOfInputAsync() => + (await Browser.EvaluateAsync("() => document.querySelector('input').value"))!; + + [Test] + public async Task Should_fill_textarea() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("textarea").FillAsync("some value"); + Assert.That(await Browser.EvaluateAsync("result"), Is.EqualTo("some value")); + } + + [Test] + public async Task Should_fill_input() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("input").FillAsync("some value"); + Assert.That(await Browser.EvaluateAsync("result"), Is.EqualTo("some value")); + } + + [Test] + public async Task Should_throw_on_unsupported_inputs() + { + await Browser.GotoAsync("/input/textarea.html"); + foreach (var type in new[] { "button", "checkbox", "file", "image", "radio", "reset", "submit" }) + { + await Browser.EvaluateAsync("(type) => document.querySelector('input').setAttribute('type', type)", type); + var error = await Assert.CatchAsync(() => Browser.Locator("input").FillAsync("")); + Assert.That(error!.Message, Does.Contain($"Input of type \"{type}\" cannot be filled")); + } + } + + [Test] + public async Task Should_fill_different_input_types() + { + await Browser.GotoAsync("/input/textarea.html"); + foreach (var type in new[] { "password", "search", "tel", "text", "url", "invalid-type" }) + { + await Browser.EvaluateAsync("(type) => document.querySelector('input').setAttribute('type', type)", type); + await Browser.Locator("input").FillAsync("text " + type); + Assert.That(await Browser.EvaluateAsync("result"), Is.EqualTo("text " + type)); + } + } + + [Test] + public async Task Should_fill_range_input() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").FillAsync("42"); + Assert.That(await ValueOfInputAsync(), Is.EqualTo("42")); + } + + [Test] + public async Task Should_throw_on_incorrect_range_value() + { + await Browser.GotoAsync(Content("")); + foreach (var value in new[] { "foo", "200", "15.43" }) + { + var error = await Assert.CatchAsync(() => Browser.Locator("input").FillAsync(value)); + Assert.That(error!.Message, Does.Contain("Malformed value")); + } + } + + [Test] + public async Task Should_fill_color_input() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").FillAsync("#aaaaaa"); + Assert.That(await ValueOfInputAsync(), Is.EqualTo("#aaaaaa")); + } + + [Test] + public async Task Should_fill_color_input_case_insensitive() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").FillAsync("#AbCd00"); + Assert.That(await ValueOfInputAsync(), Is.EqualTo("#abcd00")); + } + + [Test] + public async Task Should_throw_on_incorrect_color_value() + { + await Browser.GotoAsync(Content("")); + var error = await Assert.CatchAsync(() => Browser.Locator("input").FillAsync("badvalue")); + Assert.That(error!.Message, Does.Contain("Malformed value")); + } + + [Test] + public async Task Should_fill_date_input_after_clicking() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").TapAsync(); + await Browser.Locator("input").FillAsync("2020-03-02"); + Assert.That(await ValueOfInputAsync(), Is.EqualTo("2020-03-02")); + } + + [TestCase("color", "#aaaaaa")] + [TestCase("date", "2020-03-02")] + [TestCase("time", "13:15")] + [TestCase("datetime-local", "2020-03-02T13:15:30")] + [TestCase("month", "2020-03")] + [TestCase("range", "42")] + [TestCase("week", "2020-W50")] + public async Task Input_event_composed_should_be_true_and_cross_shadow_dom_boundary(string type, string value) + { + await Browser.GotoAsync("/empty.html"); + await Browser.GotoAsync(Content($$""" + + """)); + await Browser.EvaluateAsync(""" + () => { + window.firedBodyEvents = []; + for (const event of ['input', 'change']) + document.body.addEventListener(event, (e) => window.firedBodyEvents.push(e.type + ':' + e.composed), false); + } + """); + await Browser.EvaluateAsync(""" + () => { + window.firedEvents = []; + const input = document.querySelector('div').shadowRoot.querySelector('input'); + for (const event of ['input', 'change']) + input.addEventListener(event, (e) => window.firedEvents.push(e.type + ':' + e.composed), false); + } + """); + await Browser.Locator("input").FillAsync(value); + Assert.That(await Browser.EvaluateAsync("firedEvents"), Is.EqualTo(new[] { "input:true", "change:false" })); + Assert.That(await Browser.EvaluateAsync("firedBodyEvents"), Is.EqualTo(new[] { "input:true" })); + } + + [Test] + public async Task Should_throw_on_incorrect_date() + { + await Browser.GotoAsync(Content("")); + var error = await Assert.CatchAsync(() => Browser.Locator("input").FillAsync("2020-13-05")); + Assert.That(error!.Message, Does.Contain("Malformed value")); + } + + [Test] + public async Task Should_fill_time_input() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").FillAsync("13:15"); + Assert.That(await ValueOfInputAsync(), Is.EqualTo("13:15")); + } + + [Test] + public async Task Should_fill_month_input() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").FillAsync("2020-07"); + Assert.That(await ValueOfInputAsync(), Is.EqualTo("2020-07")); + } + + [Test] + public async Task Should_throw_on_incorrect_month() + { + await Browser.GotoAsync(Content("")); + var error = await Assert.CatchAsync(() => Browser.Locator("input").FillAsync("2020-13")); + Assert.That(error!.Message, Does.Contain("Malformed value")); + } + + [Test] + public async Task Should_fill_week_input() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").FillAsync("2020-W50"); + Assert.That(await ValueOfInputAsync(), Is.EqualTo("2020-W50")); + } + + [Test] + public async Task Should_throw_on_incorrect_week() + { + await Browser.GotoAsync(Content("")); + var error = await Assert.CatchAsync(() => Browser.Locator("input").FillAsync("2020-123")); + Assert.That(error!.Message, Does.Contain("Malformed value")); + } + + [Test] + public async Task Should_throw_on_incorrect_time() + { + await Browser.GotoAsync(Content("")); + var error = await Assert.CatchAsync(() => Browser.Locator("input").FillAsync("25:05")); + Assert.That(error!.Message, Does.Contain("Malformed value")); + } + + [Test] + public async Task Should_fill_datetime_local_input() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").FillAsync("2020-03-02T05:15"); + Assert.That(await ValueOfInputAsync(), Is.EqualTo("2020-03-02T05:15")); + } + + [Test] + public async Task Should_throw_on_incorrect_datetime_local() + { + await Browser.GotoAsync(Content("")); + var error = await Assert.CatchAsync(() => Browser.Locator("input").FillAsync("abc")); + Assert.That(error!.Message, Does.Contain("Malformed value")); + } + + [Test] + public async Task Should_fill_contenteditable() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("div[contenteditable]").FillAsync("some value"); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('div[contenteditable]').textContent"), Is.EqualTo("some value")); + } + + [Test] + public async Task Should_fill_contenteditable_with_new_lines() + { + await Browser.GotoAsync("/empty.html"); + await Browser.GotoAsync(Content("
")); + await Browser.Locator("div[contenteditable]").FillAsync("John\nDoe"); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('div[contenteditable]').innerText"), Is.EqualTo("John\nDoe")); + } + + [Test] + public async Task Should_not_double_fill_in_contenteditable_with_beforeinput_handler_in_Firefox() + { + await Browser.GotoAsync(Content(""" +
+ + """)); + var locator = Browser.Locator("#editor"); + const string testValue = "Playwright"; + await locator.FillAsync(testValue); + await Expect.That(locator).ToHaveTextAsync(testValue); + } + + [Test] + public async Task Should_fill_elements_with_existing_value_and_selection() + { + await Browser.GotoAsync("/input/textarea.html"); + + await Browser.EvaluateAsync("() => { document.querySelector('input').value = 'value one'; }"); + await Browser.Locator("input").FillAsync("another value"); + Assert.That(await Browser.EvaluateAsync("result"), Is.EqualTo("another value")); + + await Browser.EvaluateAsync("() => { const input = document.querySelector('input'); input.selectionStart = 1; input.selectionEnd = 2; }"); + await Browser.Locator("input").FillAsync("maybe this one"); + Assert.That(await Browser.EvaluateAsync("result"), Is.EqualTo("maybe this one")); + + await Browser.EvaluateAsync(""" + () => { + const div = document.querySelector('div[contenteditable]'); + div.innerHTML = 'some text some more text and even more text'; + const range = document.createRange(); + range.selectNodeContents(div.querySelector('span')); + const selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); + } + """); + await Browser.Locator("div[contenteditable]").FillAsync("replace with this"); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('div[contenteditable]').textContent"), Is.EqualTo("replace with this")); + } + + [Test] + public async Task Should_throw_nice_error_without_injected_script_stack_when_element_is_not_an_input() + { + await Browser.GotoAsync(Content("")); + var error = await Assert.CatchAsync(() => Browser.Locator("select").FillAsync("")); + Assert.That(error!.Message, Does.Contain("Element is not an , + +
+
Plain div
+ + + + \ No newline at end of file diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/pptr.png b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/pptr.png new file mode 100644 index 0000000000000000000000000000000000000000..65d87c68e65902c058af18d2a595fc89f423f4ff GIT binary patch literal 6138 zcmZu#cQjmWw;y9L%IID6F3RYg=q(tXsDlyR=)DagT6krUFiIrRiC%*dq6>-MMT<^? zh#Z0{rl~`P72IO2SUP30ssIYdb*mXIH`pju3$pkdn)>_ z6DL5A)eO}DfQC%cTQ~u3&f%hKY6t*C@BsjEi2%TFoGNY)00@Qx00&M0fWiv^fB}i= zG*QBRAapj+(FFYc_bKTve~!}-BXw;80RU2(e+M2QAH#@K5(ViQY7u=Up~B-QgS)T2 z1pw&x^)%JY!S$ZHQO&^aI)0-lv;<>80 zWA#UG$S*B4?TsqlUBshCdEDvPHNcV*OdOyOSy@aH)WgWr#na4aKR#bVDS|H_LulpcHxOMdr_XTVAT!R8 zhP{h>9N8B}El0+vnW!71Xz}AHA^Qa~g_3$0 zM2{yfOO-^-2o%Oog%|oeW7_?Er$4z+&KEfYAyEqZ_(l9LNWkxt8Eyc1uUE%(5$VX=D%> z*~dY;KVcMRNjv^nyx<=5xGrjl-$4Bi>lp{HsFgCI_;%Qhl2+U> zm(l&Sydg~V>~ETryTDi&Svy11NHU(uCG`DjUlzw(A1_1Y;<1EK8SvaGsK0{10qEe~ z8K}cr%WxK%2*zf?V8D+%Kx5gnb6`^)IiJa7Q5_`%M9-gck6S?ads%yw98zrb?gy+e zAhPc%K@pL|fH(6f_Jxs>yrD#-#6>2EzX@o1MQT|1?Hc$ig56tHSfHB>yc*)`Wl~%D zoZH|#(VxtU`W~`z4+xG2DQoF!%7@MYX~tDPcpg)98Z!+wcJ-xQ>RDqh%vS8kBvDM zpJ&{|>UT@LIb|9tPH&A&Er}i9fMrfBkxF))g7jsX=m9NMn%Nj~?g*v=k(ZJCi+|6D z`<`ODPQ1qh%Fl4A$S~1vI)9V<&^NBmpnFyf8*lh%|V7Lv9 zEAZ0gSkfyWP@2G@!Ju^Gti)f7b_;mv<8}mFWA<5&HBKwh{7X}79H2Snp$6Zz%zs{z zn)VPXEnjR*WT=?Pm_>sb%6-XB2q<_A2(J=9m|8zC9T&eUMM+9n_Ayb;lHH>ne)ki* zWDZYwP85X~l^#881tpYVn}FP=u+*KVJcSuQKMC+85%a-Y+S&!5cMI+3MrVhjXAvz3om5A5i$g9^bN4R zyb(p3-qMi*8AOgG_KEb@ca03Ll4xr_Mg22H`evZ`$uG36%*>c_4c&M zo{&`g)%f!GzXOXk{*NgL9=o%*yCyXCkq^C%-_g`4-`$Wx-X|z0L~=>cmZirLC-A}7 zuKz~eUkhJOi^QlDVia{BDRWG9Bu}0Y*{7Uf@o?r|x)}qS)OQI&!0W!Mk%J&RAWr%W z(C !4@^Vx1sD`7N#d=xeNFoPC9oyU-cfsEl&6lomsESF+tG@eQK*Rh_E6^MP|L zo%KhZgeJ4+BV`4()-B z#Ckf_O^nXtPvaSQL8R@8XhW9+>9Po;D5BIdcIJ zb_gd{&^-S;#RkSlET{ExEEXc*B_^Oi36Cr!omp~V2NeNS%I1D}{VX^BIwctUJ2aU| zFZ*Sv!3j7i&k`(})8DEAJ@*Cw!1H4HKx>FyRQfgK*8V8tET})|>OnJ`eZ9B*Q^XB? z`w16JZ~yO-ldH^P+FdvM#!?XsG&SKlY=HirmQi($^)y&4rj3b|ro)m3Sg|weP zd~PH-3;SE`4^?nzgqJ({2uW09W5iqW*zs&cFp=_}u7~LXuP{GRo4(7Oc3wq4t0_s9 zfDbk1HTD?rrfGOz6UMzO?>xxRW{1>R%K5YPEQl`TkrOLhfZ16sDTdZ26L0#DZp>F2 z;dxHezJ-C;nZSNn-8nIGuCHUKWE8)y!nMt!CHR84%{~Xb!D-F|u6mcEqt$x_|B|rB zf_KHQpUr}8=QC-la`iV%-Kg${nLqm5-7C8yX|2`p`D=;SWiI~ZYl{$0?*6-FVbTGnGAf&_W7wTRDsr$m-+;xVxJK0?k+N4NA*T;MB8nG>oS<0q2gCBorvAyaxKELp(B zSEc84wbHG%PYwmpUgobAnr*Pf(Ea|DjDW2a!EFAr3hfR#d2lC>t7~7QA*#2Q{^+4b zSf_JOD5DWYrq&+wTmlo+3$lfNCsZEd? zQ-ng9vg->``!I+x&JvO1qvBYxML!$SH!#sHkhSco_}dDql~Pea6=zs zoJW`=fy-m&xmqG|bBsSZ9oZoM>KdC#OohY}hoZXVd*FO>+fzjgos0CdF6SoVm3R|fSV>xs37S|g*GEi=z zs?%b~Fk28}QTXh%;+X_FYDJ|xNvxloG81@}rh*C{D!L%~c_4AmB2lrg3CzOo5>F_z z+9wRD!|KCW#k}(jvZBrrH>%IGZUe%yV)spZImwcsrWpY;ec1w-n@|g1KcM#bXcwZ;5lYka^TJIF;KV1+R7U8{NY=S1$7-6R$p{;o{5m6;O(Y=95@Y{1O) zymYpbRC`BntLXWU5(s%5&bJ5!$0}=3%0uu=%f33PEb3a@`q8p#Pg7Wf0ir)anh3$t z@Q>QGUpFCH|j;?a!5nS@VjGq%KVAJ6joJ^Hu1uh zxTe656kUgcGo zVuEbUyeVWkrA^6FtCE_j9PB9~3xt1I_QozP&X-7ysH?U_HNbkkC)t&udgFYRLqodC z;+C76uB!8Xaa0xId+fC)0>x&Ebn0C7>>LbXEIFL(?u^eiRx+w)@}w0UTb}J!9XGu_ z_OI80wWJ9-5!aKqRBc$G5zUpzK>QtGx~9cf3D}tApqVNnk~W9tj^}QowW+DXXn}z4 z&${=RyP?qofvU_4Z4tR_fwY%1Unp$5M&Ve-!5 z2HS%C?uuG9rle7w2Tyi$f*x9w65@AJo4idtOxjG$Uv9YiV&&ei`9(xXZwsbE!g%Xa za-l}mQvK9+9q|bD1v(j^ZI4WrKFBReS3``4Al8p^?=%-D*JI$xuk~|$k~aHWl!GQF zd}oc(-B{Zc=J?K%-{UeGOixF}j;hLbI&z+sP#+|33)?OaZE`dQgS0fR3s^iEt6P*G z75cvan3F-m&r|h-&!od_zV*TWvjbzEEZ@jF&3{gY8%ykT+tfxhI;PIbSQHMTb%3EI zz-HwN=K%T9CoAoj+%`HAusMg612JCDZhP?P6U!;5Vc(?(R_5x`pIQ^r1kO8CM?*dL z+XH|RrCdu7X9&oFpYUIMK&uyMM};{DzU=L}&lf32I?KE~Y|Uy+NE8sklu>?YO&Kut z`l|VxSVBUAOmL@3>IH=-_^oWc|CjFPof8GJnI$D0LH0WODR4$G=adwrADU%ax|kcn zlBA|%5fh^#)_qIu7<0X2Geh#-Wvcx(D?20Og3l+6d}4C43nL*D6B8{xeW?dC0)fED z`J?ig>FO}bk+~Smy+lgZpHysYpD>Go>2Yy!im)AmeD#zcS6BQ{U4jM=50Bd)UmY8N ziKSK6)$JCBu7B-IX5*2T&cT_+oU`|S?dX^^ad2>WoXcuxS)Eg|!6CxI0bs^8Ey#<{ ziIiZFss75!3Ye6Xn}-KvKTmu{!J(vdPfSbn0f$%~(D4*{~oCUL#6(R?OKbIJb91l_;?NPW5xqEy(fg&J% zA?-B>A$Xpht?uT=C+RkhotQXwjCoJLI^^82vAa81;MX&9Fk79Hk^=v}`4OWSO5P7W zD3g7IwieFq+^3A(wR!Ytbhi5P3cl1UNtW>Ci)mH$yE~0q+$}~&nT>7V*>~k?rP2HE ze|f82oR^np=HL)Bp;A>tV4v-fSEmj!he@ zPAoLI*mMN&+P3+AoSn^?nKADS+W!zZsXSB<>5R&ay|O$`v8sc#>vU2GQ)zf!`e0h0f7>~ z^`3DYex5!B(~H_YUG(OYlzfi6e6EPCHnM(8D_i7IDkZA1QDS$pc=C0o%ILCRuVGY_ zQlVm~TYnM+qf+a}92gjA(;K6V%PNd~VA9T5Uen`Aw!w5J4IJW+pc^@nBmCN?xCC0-psr_1~xXf7Z3SR z2?_f%l{5xo4`#mSm30ay zTU-5y?|O~Y)qz_>nU6OIQoL6?=?tgA5XjDP+d3Z~Us7Ts$n6tmWOt&#rpXPG1kcLJ zv1nWO>%Gh6FOJIg-x_QPIez32zC(vY@AXmB(jMIiCk|7=I8V1?pso_vSt(%uyocv&&{2y z(4TMS@|7t#)Xy&}D%$IGn2(i{m!A#J#jy*RvpwQcXm)lML_|cxz>r+#p{c1k^;##> ztIQM9Us6_wvZJZ>&|-)rY&WBqSu(?MTkzs2{|!w_EI= zg9|w|k~k7KRyqRTpM4;$vFpfwLdvkYwWVQdN{s^@Egjw0lM^E(6517dI_TMg<67Lg zx4(Tm?;~P|Sz2m4J9AxMUx!6T(oj-jKNTucsY4?!+=J}P8ymB6H37%_!=s}gR##c8 zXP0(Oz0z{2X=yc2*Sf_ESl-2vKp+SlnG4%ACaV6uo+M*cpydReoSZNw#kaM|^78U3 z-5fQwcXWK;OcTq_%EBf=SkBJRw{VA5IvtyY!y(eZQP{JRfB7n|f=&@aHU96?y#w@h@QDj66I%lr%INnwlU|df|=k zt2LL)gIN$Ep+xMTD23nyO;=Z*SFc|ApuWJ^2Zn~mva_i@tPqH|!lI(N^l4f$7Ct_; zO3}ZY$H&LfxO{DFZ?|Sn;>;7a;ljtq--*X3a@E#OdXN07zUqgApcpq7muo~s=R;%T zyzubwjGs1UX57ZbDk9U<)41A&czsGjO1guCh^vQ3CE9fK;J`EdU`8+;N21}l%+p@p z-QFHiW_3vHd-qyD?598)`Ax!npY>Q zhii(8in0NUIBjWZ-Q7FGekd|DG&F2>+%52Rv<$kpSM|@IKf$Mk7z{4Kg4%s_b-|pR zoWZA0C`F#h%r_r*9#_)gqVRQRM+-L9QvIIaxai?KhwihVKYdU8TdS8?^?PIP_U7Le z_n%TzQ|s#LwlDhlTC_E}{%?Iy*i0=bll*&JR2Rx4(3nx2CiADR0_o(?DF} W{|p>bpZvrb0Q9tsH0#uzQ2zrM7gd%3 literal 0 HcmV?d00001 From 26ee998f4cb9a831852ca91f9f22d009879ffbc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 18:59:44 -0300 Subject: [PATCH 4/9] Harden the upload and respond routes and write large test files in 1MB chunks (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.Agent.Tests/PlaywrightRoutes.cs | 8 +++++++- .../E2E.NUnit.Tests/Filechooser/PageFilechooserTests.cs | 4 ++-- .../SetInputFiles/PageSetInputFilesTests.cs | 9 ++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/E2E.Agent.Tests/PlaywrightRoutes.cs b/tests/E2E.Agent.Tests/PlaywrightRoutes.cs index a3630a979..344f39e90 100644 --- a/tests/E2E.Agent.Tests/PlaywrightRoutes.cs +++ b/tests/E2E.Agent.Tests/PlaywrightRoutes.cs @@ -48,7 +48,7 @@ public static async Task HandleAsync(HttpListenerContext context) if (path == "/respond") { var query = context.Request.QueryString; - response.StatusCode = int.Parse(query["status"] ?? "200", CultureInfo.InvariantCulture); + response.StatusCode = int.TryParse(query["status"], CultureInfo.InvariantCulture, out var status) ? status : 200; if (query["headers"] is { } headers) { foreach (var (name, value) in JsonSerializer.Deserialize>(headers)!) @@ -111,6 +111,12 @@ private static async Task UploadAsync(HttpListenerContext context) var next = afterStart + relative; var part = data[(afterStart + 2)..(next - 2)]; var split = part.Span.IndexOf("\r\n\r\n"u8); + if (split < 0) + { + start = next; + continue; + } + var head = Encoding.UTF8.GetString(part.Span[..split]); var body = part[(split + 4)..]; files.Add(new Dictionary diff --git a/tests/E2E.NUnit.Tests/Filechooser/PageFilechooserTests.cs b/tests/E2E.NUnit.Tests/Filechooser/PageFilechooserTests.cs index 14215dd72..e0fdb4c87 100644 --- a/tests/E2E.NUnit.Tests/Filechooser/PageFilechooserTests.cs +++ b/tests/E2E.NUnit.Tests/Filechooser/PageFilechooserTests.cs @@ -45,11 +45,11 @@ public async Task Should_upload_multiple_large_files() try { var uploadFile = Path.Combine(dir, "50MB_1.zip"); - var chunk = new byte[1024]; + var chunk = new byte[1024 * 1024]; Array.Fill(chunk, (byte)'A'); await using (var stream = File.Create(uploadFile)) { - for (var i = 0; i < 49 * 1024; i++) + for (var i = 0; i < 49; i++) { await stream.WriteAsync(chunk); } diff --git a/tests/E2E.NUnit.Tests/SetInputFiles/PageSetInputFilesTests.cs b/tests/E2E.NUnit.Tests/SetInputFiles/PageSetInputFilesTests.cs index 976f6df74..473e3a834 100644 --- a/tests/E2E.NUnit.Tests/SetInputFiles/PageSetInputFilesTests.cs +++ b/tests/E2E.NUnit.Tests/SetInputFiles/PageSetInputFilesTests.cs @@ -45,7 +45,10 @@ public void RemoveOutputDirs() { foreach (var dir in _outputDirs) { - Directory.Delete(dir, recursive: true); + if (Directory.Exists(dir)) + { + Directory.Delete(dir, recursive: true); + } } _outputDirs.Clear(); @@ -62,10 +65,10 @@ private string OutputDir() /// Writes a 200MB file of As, Playwright's large upload. private static async Task WriteLargeFileAsync(string file) { - var chunk = new byte[4 * 1024]; + var chunk = new byte[1024 * 1024]; Array.Fill(chunk, (byte)'A'); await using var stream = File.Create(file); - for (var i = 0; i < 50 * 1024; i++) + for (var i = 0; i < 200; i++) { await stream.WriteAsync(chunk); } From 2ecb2b87bda2946971b395c42f3e31deacc65806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:09:52 -0300 Subject: [PATCH 5/9] Port Playwright's click, click-scroll and elementhandle-scroll-into-view tests (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- COMPATIBILITY.md | 2 +- tests/E2E.Agent.Tests/Testbed.cs | 1 + tests/E2E.NUnit.Tests/Click/PageClickTests.cs | 708 ++++++++++++++++++ .../ClickScroll/PageClickScrollTests.cs | 113 +++ .../ElementhandleScrollIntoViewTests.cs | 131 ++++ tests/E2E.NUnit.Tests/Helpers/Helpers.cs | 6 + .../playwright/assets/input/button.html | 32 + .../playwright/assets/input/checkbox.html | 42 ++ .../assets/input/rotatedButton.html | 21 + .../playwright/assets/input/scrollable.html | 23 + .../playwright/assets/offscreenbuttons.html | 55 ++ .../playwright/assets/wrappedlink.html | 32 + 12 files changed, 1165 insertions(+), 1 deletion(-) create mode 100644 tests/E2E.NUnit.Tests/Click/PageClickTests.cs create mode 100644 tests/E2E.NUnit.Tests/ClickScroll/PageClickScrollTests.cs create mode 100644 tests/E2E.NUnit.Tests/ElementhandleScrollIntoView/ElementhandleScrollIntoViewTests.cs create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/button.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/checkbox.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/rotatedButton.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/scrollable.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/offscreenbuttons.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/wrappedlink.html diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 1bdd8a6c4..67b788deb 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -162,7 +162,7 @@ Differences: - Upstream's docs site pages that have no counterpart in the port: the page objects page (`docs/page-objects.mdx`, moved to `/page-object-model` in `d30114a`), `e2e feedback` and the `docs/reference/cli.mdx` text about its opt-out variables (`4c1e2e8`), and `examples/` with its registry (`b3ae3a4`, `38b802d`, `a29edcb`, `b54646f`). The migration guides (`docs/migrate/*.mdx`, `8537abc`) are ported: see [Migration guides](#migration-guides). The docs site has .NET-only guides for upstream's five example apps of `caf51eb` (tester-army/e2e#1497: i18n, file upload, location, biometrics, deep links), under [Examples](docs-site/src/content/docs/examples/index.mdx). They are not ports: that commit only adds registry entries that link to separate repositories, so there was no guide text. Each page writes C# tests for the upstream app. The self-healing deep dive (`6fa99ea`) is ported as the [Self-healing tests](README.md#self-healing-tests) section of the guide, since the port has no docs pages for the cache, the trace page, or executors to link to. Known gap: only `e2e explore` prints a run summary, since it is the one command that feeds a run to `ListReporter` (see [List reporter](#list-reporter)): the `Cache 4 replayed · 1 handed off · 1 missed` row is `Format.CacheText` over `Format.StepsCacheTally` (`E2E.Cli`, upstream's `cacheText` and `stepsCacheTally` of `report/format.ts`), which an exploration, with its cache off, never fills, and a test run does not print ([#799](https://github.com/hardkoded/e2e-dotnet/issues/799)) - Parallel workers and serial suites - `test.fail` and the `fail` test option (tester-army/e2e#1539, `732ea8a`): a test expected to fail, whose product failure passes and whose pass fails with `UNEXPECTED_PASS`. It lives in upstream's test registry, scheduler, retry, and reporters (`settleExpectedFailure` runs on a finished attempt), and the port has none of them. NUnit and xUnit v3 own the verdict and the retries, and neither has an expected-failure outcome, so a port would need a new public API of its own -- Playwright's page tests in the testbed suite (tester-army/e2e#1505, `bdf769b`) are ported in slices (hardkoded/e2e-dotnet#1060), as the `playwright` category of `tests/E2E.NUnit.Tests`, against the playground's `/content` route and Playwright's test assets (Apache-2.0, `Testbed/playwright/`, with Playwright's `LICENSE` and `NOTICE`). A test upstream marks `{ fail: 'reason' }` keeps its assertions inside the test-only `Helpers.ExpectedToFailAsync`, which passes while the body fails and fails once it passes. Ported so far: `check`, `wait-for-url`, `locator-list`, and `selectors-text` (one test is such a known difference, hardkoded/e2e-dotnet#1062). +- Playwright's page tests in the testbed suite (tester-army/e2e#1505, `bdf769b`) are ported in slices (hardkoded/e2e-dotnet#1060), as the `playwright` category of `tests/E2E.NUnit.Tests`, against the playground's `/content` route and Playwright's test assets (Apache-2.0, `Testbed/playwright/`, with Playwright's `LICENSE` and `NOTICE`). A test upstream marks `{ fail: 'reason' }` keeps its assertions inside the test-only `Helpers.ExpectedToFailAsync`, which passes while the body fails and fails once it passes. Ported so far: `check`, `wait-for-url`, `locator-list`, `selectors-text` (one test is such a known difference, hardkoded/e2e-dotnet#1062), `click`, `click-scroll`, and `elementhandle-scroll-into-view` (three more known differences: hardkoded/e2e-dotnet#1079, #1080, #1081). - Serial groups (upstream tester-army/e2e#1056, #1470): serial runs, group retries, and skipping the rest of a group after a failure belong to the test runner, which is NUnit or xUnit here, so the port keeps no serial groups. The schema has `serialAttempt.cutRetry` and the serial verdict is read from it, but nothing in the port writes a serial attempt: see [Report document](#report-document) - The out-of-process engine protocol (upstream tester-army/e2e#1232, [#873](https://github.com/hardkoded/e2e-dotnet/issues/873)): the port has no runner and no worker pool, so there is no engine process to talk to. An engine is written in .NET against `IEngine` - Diff-only observations for a custom executor's own model turns. The built-in agent has them (#1022): `#id` lines on the opening screen and on `observe`, and a diff after each action (see [MCP server](#mcp-server) for the presenter). `ExecutorObservation.Text`, which an executor reads from `Observe`, keeps the full `[ref=…]` snapshot, cut at the observation byte budget (see [Agents](#agents)), and a node is addressed by its ref there (`new ExecutorTarget("e12")`), so a custom executor has no presenter of its own. Upstream gives every executor the `#id` view. diff --git a/tests/E2E.Agent.Tests/Testbed.cs b/tests/E2E.Agent.Tests/Testbed.cs index d2a2336cf..02118f198 100644 --- a/tests/E2E.Agent.Tests/Testbed.cs +++ b/tests/E2E.Agent.Tests/Testbed.cs @@ -929,6 +929,7 @@ private static string Start() url = "http://127.0.0.1:" + port.ToString(CultureInfo.InvariantCulture) + "/"; listener = new HttpListener(); listener.Prefixes.Add(url); + listener.Prefixes.Add(url.Replace("127.0.0.1", "localhost", StringComparison.Ordinal)); try { listener.Start(); diff --git a/tests/E2E.NUnit.Tests/Click/PageClickTests.cs b/tests/E2E.NUnit.Tests/Click/PageClickTests.cs new file mode 100644 index 000000000..7f340513a --- /dev/null +++ b/tests/E2E.NUnit.Tests/Click/PageClickTests.cs @@ -0,0 +1,708 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using E2E.Engine; +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.Click; + +/// +/// test.describe('page click') of upstream's apps/testbed/tests/click.e2e.ts (Playwright's page-click.spec.ts). +/// TapAsync stands for page.click. Not ported, as upstream: should click button inside frameset; should issue clicks in +/// parallel in page and popup; should select the text by triple clicking; should waitFor visible when already visible; should not wait with +/// force; should click the button with fixed position inside an iframe; should click the button with px border with offset; should click the +/// button with em border with offset; should click a very large button with offset; should click a button in scrolling container with +/// offset; should wait for becoming hit target with trial run; trial run should work with short timeout; trial run should not click; trial +/// run should not double click; should fail when obscured and not waiting for hit target; should wait for LABEL to be clickable when it has +/// pointer-events:none; should report nice error when element is detached and force-clicked; should fail when element detaches after +/// animation; should retry when element detaches after animation; should retry when element is animating from outside the viewport; should +/// fail when element is animating from outside the viewport with force; should dispatch microtasks in order; should not throw protocol error +/// when navigating during the click; should retry when navigating during the click; should not hang when frame is detached; should click in +/// an iframe with border 2; should not retain removed iframe after clicking inside it; should click a button that is overlaid by a +/// permission popup; should click in a transformed iframe with force; ensure events are dispatched in the individual tasks; should set +/// PointerEvent.pressure on pointerdown; should set PointerEvent.pressure on pointermove; should click with tweened mouse movement; should +/// abort via signal; should throw an Error when aborted in-flight with a string reason; should abort via already-aborted signal; should +/// throw an Error when aborted via an already-aborted signal with a string reason (no force, trial, position scrolling, +/// clickCount, steps, element handles, Frame objects, events, or abort signals; some upstream left undone). +/// +public sealed class PageClickTests : PlaywrightTest +{ + /// Two animation frames and a task, Playwright's rafraf, so a pending tap has had its chance. + private const string GiveItAChanceToClick = + "() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(resolve, 0))))"; + + private static readonly ActionOptions Ten = new() { Timeout = TimeSpan.FromSeconds(10) }; + + private async Task ResultAsync() => (await Browser.EvaluateAsync("result"))!; + + [Test] + public async Task Should_click_the_button() + { + await Browser.GotoAsync("/input/button.html"); + await Browser.Locator("button").TapAsync(); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + } + + [Test] + public async Task Should_click_svg() + { + await Browser.GotoAsync(Content(""" + + + + """)); + await Browser.Locator("circle").TapAsync(); + Assert.That(await Browser.EvaluateAsync("__CLICKED"), Is.EqualTo(42)); + } + + [Test] + public async Task Should_click_the_button_if_window_Node_is_removed() + { + // Known difference (hardkoded/e2e-dotnet#1079): the page script reads window.Node. + await ExpectedToFailAsync("Node is not defined", async () => + { + await Browser.GotoAsync("/input/button.html"); + await Browser.EvaluateAsync("() => { delete window.Node; }"); + await Browser.Locator("button").TapAsync(); + Equal("Clicked", await ResultAsync()); + }); + } + + [Test] + public async Task Should_click_on_a_span_with_an_inline_element_inside() + { + await Browser.GotoAsync(Content(""" + + + """)); + await Browser.Locator("span").TapAsync(); + Assert.That(await Browser.EvaluateAsync("CLICKED"), Is.EqualTo(42)); + } + + [TestCase("aligned", "")] + [TestCase("half-aligned", "margin-left: 20.5px; margin-top: 11.5px;")] + [TestCase("unaligned v1", "margin-left: 20.23px; margin-top: 11.65px;")] + [TestCase("unaligned v2", "margin-left: 20.68px; margin-top: 11.13px;")] + [TestCase("unaligned v3", "margin-left: 20.68px; margin-top: 11.52px;")] + [TestCase("unaligned v4", "margin-left: 20.15px; margin-top: 11.24px;")] + public async Task Should_click_the_1x1_div(string name, string style) + { + await Browser.GotoAsync(Content($"""
""")); + await Browser.Locator("div").TapAsync(); + Assert.That(await Browser.EvaluateAsync("window.__clicked"), Is.True, $"should click the {name} 1x1 div"); + } + + [Test] + public async Task Should_click_the_button_after_navigation() + { + await Browser.GotoAsync("/input/button.html"); + await Browser.Locator("button").TapAsync(); + await Browser.GotoAsync("/input/button.html"); + await Browser.Locator("button").TapAsync(); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + } + + [Test] + public async Task Should_click_the_button_after_a_cross_origin_navigation() + { + await Browser.GotoAsync("/input/button.html"); + await Browser.Locator("button").TapAsync(); + await Browser.GotoAsync($"{CROSS}/input/button.html"); + await Browser.Locator("button").TapAsync(); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + } + + [Test] + public async Task Should_click_when_one_of_inline_box_children_is_outside_of_viewport() + { + await Browser.GotoAsync(Content(""" + + woofdoggo + """)); + await Browser.Locator("span").TapAsync(); + Assert.That(await Browser.EvaluateAsync("CLICKED"), Is.EqualTo(42)); + } + + [Test] + public async Task Should_click_offscreen_buttons() + { + await Browser.GotoAsync("/offscreenbuttons.html"); + await Browser.EvaluateAsync("() => { window.messages = []; console.log = (text) => window.messages.push(text); }"); + for (var index = 0; index < 11; ++index) + { + await Browser.EvaluateAsync("() => window.scrollTo(0, 0)"); + await Browser.Locator($"#btn{index}").TapAsync(); + } + + Assert.That( + await Browser.EvaluateAsync("messages"), + Is.EqualTo(Enumerable.Range(0, 11).Select(index => $"button #{index} clicked").ToArray())); + } + + [Test] + public async Task Should_waitFor_display_none_to_be_gone() + { + await WaitForPropertyToBeGoneAsync("display", "none", "block"); + } + + [Test] + public async Task Should_waitFor_visibility_hidden_to_be_gone() + { + await WaitForPropertyToBeGoneAsync("visibility", "hidden", "visible"); + } + + private async Task WaitForPropertyToBeGoneAsync(string property, string hidden, string shown) + { + await Browser.GotoAsync("/input/button.html"); + await Browser.EvaluateAsync($"() => {{ document.querySelector('button').style.{property} = '{hidden}'; }}"); + var done = false; + var clicked = Task.Run(async () => + { + await Browser.Locator("button").TapAsync(Ten); + done = true; + }); + await Browser.EvaluateAsync(GiveItAChanceToClick); + Assert.That(await ResultAsync(), Is.EqualTo("Was not clicked")); + Assert.That(done, Is.False); + await Browser.EvaluateAsync($"() => {{ document.querySelector('button').style.{property} = '{shown}'; }}"); + await clicked; + Assert.That(done, Is.True); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + } + + [Test] + public async Task Should_waitFor_visible_when_parent_is_hidden() + { + await Browser.GotoAsync("/input/button.html"); + await Browser.EvaluateAsync("() => { document.querySelector('button').parentElement.style.display = 'none'; }"); + var done = false; + var clicked = Task.Run(async () => + { + await Browser.Locator("button").TapAsync(Ten); + done = true; + }); + await Browser.EvaluateAsync(GiveItAChanceToClick); + Assert.That(done, Is.False); + await Browser.EvaluateAsync("() => { document.querySelector('button').parentElement.style.display = 'block'; }"); + await clicked; + Assert.That(done, Is.True); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + } + + [Test] + public async Task Should_click_wrapped_links() + { + await Browser.GotoAsync("/wrappedlink.html"); + await Browser.Locator("a").TapAsync(); + Assert.That(await Browser.EvaluateAsync("__clicked"), Is.True); + } + + [Test] + public async Task Should_click_on_checkbox_input_and_toggle() + { + await Browser.GotoAsync("/input/checkbox.html"); + Assert.That(await Browser.EvaluateAsync("() => window.result.check"), Is.Null); + await Browser.Locator("input#agree").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.result.check"), Is.True); + Assert.That( + await Browser.EvaluateAsync("() => window.result.events"), + Is.EqualTo(new[] { "mouseover", "mouseenter", "mousemove", "mousedown", "mouseup", "click", "input", "change" })); + await Browser.Locator("input#agree").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.result.check"), Is.False); + } + + [Test] + public async Task Should_click_on_checkbox_label_and_toggle() + { + await Browser.GotoAsync("/input/checkbox.html"); + Assert.That(await Browser.EvaluateAsync("() => window.result.check"), Is.Null); + await Browser.Locator("label[for=\"agree\"]").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.result.check"), Is.True); + Assert.That(await Browser.EvaluateAsync("() => window.result.events"), Is.EqualTo(new[] { "click", "input", "change" })); + await Browser.Locator("label[for=\"agree\"]").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.result.check"), Is.False); + } + + [Test] + public async Task Should_scroll_and_click_the_button() + { + await Browser.GotoAsync("/input/scrollable.html"); + await Browser.Locator("#button-5").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('#button-5').textContent"), Is.EqualTo("clicked")); + await Browser.Locator("#button-80").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('#button-80').textContent"), Is.EqualTo("clicked")); + } + + [Test] + public async Task Should_scroll_and_click_the_button_with_smooth_scroll_behavior() + { + await Browser.GotoAsync("/input/scrollable.html"); + await Browser.EvaluateAsync("() => { const style = document.createElement('style'); style.textContent = 'html { scroll-behavior: smooth; }'; document.head.append(style); }"); + for (var index = 0; index < 5; index++) + { + await Browser.Locator("#button-80").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('#button-80').textContent"), Is.EqualTo("clicked")); + await Browser.Locator("#button-20").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('#button-20').textContent"), Is.EqualTo("clicked")); + } + } + + [Test] + public async Task Should_double_click_the_button() + { + await Browser.GotoAsync("/input/button.html"); + await Browser.EvaluateAsync("() => { window.double = false; document.querySelector('button').addEventListener('dblclick', () => { window.double = true; }); }"); + await Browser.Locator("button").DoubleTapAsync(); + Assert.That(await Browser.EvaluateAsync("double"), Is.True); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + } + + [Test] + public async Task Should_click_a_partially_obscured_button() + { + await Browser.GotoAsync("/input/button.html"); + await Browser.EvaluateAsync("() => { const button = document.querySelector('button'); button.textContent = 'Some really long text that will go offscreen'; button.style.position = 'absolute'; button.style.left = '368px'; }"); + await Browser.Locator("button").TapAsync(); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + } + + [Test] + public async Task Should_click_a_rotated_button() + { + await Browser.GotoAsync("/input/rotatedButton.html"); + await Browser.Locator("button").TapAsync(); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + } + + [Test] + public async Task Should_fire_contextmenu_event_on_right_click() + { + await Browser.GotoAsync("/input/scrollable.html"); + await Browser.Locator("#button-8").SecondaryTapAsync(); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('#button-8').textContent"), Is.EqualTo("context menu")); + } + + [Test] + public async Task Should_click_links_which_cause_navigation() + { + await Browser.GotoAsync(Content("empty.html")); + await Browser.Locator("a").TapAsync(); + await Browser.WaitForURLAsync("/empty.html"); + } + + [Test] + public async Task Should_click_the_button_inside_an_iframe() + { + await Browser.GotoAsync(Content("
spacer
")); + var frame = Browser.FrameLocator("iframe"); + await frame.Locator("button").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('iframe').contentWindow.result"), Is.EqualTo("Clicked")); + } + + [Test] + public async Task Should_click_the_button_behind_sticky_header() + { + await Browser.SetViewportAsync(500, 240); + await Browser.GotoAsync(Content(""" + +
+
    +
  1. hi1
  2. hi2
  3. hi3
  4. hi4
  5. hi5
  6. hi6
  7. hi7
  8. hi8
  9. +
  10. hi9
  11. +
  12. hi10
  13. hi11
  14. hi12
  15. hi13
  16. hi14
  17. +
+ """)); + await Browser.EvaluateAsync("() => document.querySelector('#li14').scrollIntoView()"); + await Browser.Locator("#target").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.__clicked"), Is.True); + } + + [Test] + public async Task Should_click_the_button_behind_position_absolute_header() + { + await Browser.SetViewportAsync(500, 240); + await Browser.GotoAsync(Content(""" + +
    +
  1. hi1
  2. hi2
  3. hi3
  4. hi4
  5. hi5
  6. hi6
  7. hi7
  8. hi8
  9. +
  10. hi9
  11. +
  12. hi10
  13. hi11
  14. hi12
  15. hi13
  16. hi14
  17. +
+
Overlay
+ """)); + await Browser.EvaluateAsync("() => { const target = document.querySelector('#target'); document.querySelector('ol').scrollTo({ top: target.offsetTop, behavior: 'instant' }); }"); + await Browser.Locator("#target").TapAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.__clicked"), Is.True); + } + + [Test] + public async Task Should_wait_for_stable_position() + { + await Browser.GotoAsync("/input/button.html"); + await Browser.EvaluateAsync(""" + () => { + const button = document.querySelector('button'); + button.style.transition = 'margin 500ms linear 0s'; + button.style.marginLeft = '200px'; + button.style.borderWidth = '0'; + button.style.width = '200px'; + button.style.height = '20px'; + button.style.display = 'block'; + document.body.style.margin = '0'; + } + """); + await Browser.EvaluateAsync(GiveItAChanceToClick); + await Browser.Locator("button").TapAsync(); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + Assert.That(await Browser.EvaluateAsync("pageX"), Is.EqualTo(300)); + Assert.That(await Browser.EvaluateAsync("pageY"), Is.EqualTo(10)); + } + + [Test] + public async Task Should_wait_for_becoming_hit_target() + { + await Browser.GotoAsync("/input/button.html"); + await Browser.EvaluateAsync(""" + () => { + const button = document.querySelector('button'); + button.style.borderWidth = '0'; + button.style.width = '200px'; + button.style.height = '20px'; + document.body.style.margin = '0'; + document.body.style.position = 'relative'; + const flyOver = document.createElement('div'); + flyOver.className = 'flyover'; + flyOver.style.position = 'absolute'; + flyOver.style.width = '400px'; + flyOver.style.height = '20px'; + flyOver.style.left = '-200px'; + flyOver.style.top = '0'; + flyOver.style.background = 'red'; + document.body.appendChild(flyOver); + } + """); + var clicked = false; + var tap = Task.Run(async () => + { + await Browser.Locator("button").TapAsync(Ten); + clicked = true; + }); + Assert.That(clicked, Is.False); + await Browser.EvaluateAsync("() => { document.querySelector('.flyover').style.left = '0'; }"); + await Browser.EvaluateAsync(GiveItAChanceToClick); + Assert.That(clicked, Is.False); + await Browser.EvaluateAsync("() => { document.querySelector('.flyover').style.left = '200px'; }"); + await tap; + Assert.That(clicked, Is.True); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + } + + [TestCase("button", "", "document.querySelector('button').removeAttribute('disabled')")] + [TestCase("input", "", "document.querySelector('input').removeAttribute('disabled')")] + public async Task Should_wait_for_element_to_be_enabled(string name, string html, string enable) + { + await Browser.GotoAsync(Content(html)); + var done = false; + var target = name == "button" ? Screen.GetByText("Click target") : Browser.Locator(name); + var tap = Task.Run(async () => + { + await target.TapAsync(Ten); + done = true; + }); + await Browser.EvaluateAsync(GiveItAChanceToClick); + Assert.That(await Browser.EvaluateAsync("() => window.__CLICKED"), Is.Null); + Assert.That(done, Is.False); + await Browser.EvaluateAsync($"() => {{ {enable}; }}"); + await tap; + Assert.That(await Browser.EvaluateAsync("__CLICKED"), Is.True, $"should wait for {name} to be enabled"); + } + + [Test] + public async Task Should_wait_for_select_to_be_enabled() + { + await Browser.GotoAsync(Content(""" + + + """)); + var done = false; + var tap = Task.Run(async () => + { + await Browser.Locator("select").TapAsync(Ten); + done = true; + }); + await Browser.EvaluateAsync(GiveItAChanceToClick); + Assert.That(await Browser.EvaluateAsync("() => window.__CLICKED"), Is.Null); + Assert.That(done, Is.False); + await Browser.EvaluateAsync("() => { document.querySelector('select').removeAttribute('disabled'); }"); + await tap; + Assert.That(await Browser.EvaluateAsync("__CLICKED"), Is.True); + } + + [Test] + public async Task Should_click_disabled_div() + { + await Browser.GotoAsync(Content("
Click target
")); + await Screen.GetByText("Click target").TapAsync(); + Assert.That(await Browser.EvaluateAsync("__CLICKED"), Is.True); + } + + [Test] + public async Task Should_wait_for_BUTTON_to_be_clickable_when_it_has_pointer_events_none() + { + await Browser.GotoAsync(Content("")); + var done = false; + var tap = Task.Run(async () => + { + await Screen.GetByText("Click target").TapAsync(Ten); + done = true; + }); + await Browser.EvaluateAsync(GiveItAChanceToClick); + Assert.That(await Browser.EvaluateAsync("() => window.__CLICKED"), Is.Null); + Assert.That(done, Is.False); + await Browser.EvaluateAsync("() => { document.querySelector('button').style.removeProperty('pointer-events'); }"); + await tap; + Assert.That(await Browser.EvaluateAsync("__CLICKED"), Is.True); + } + + [Test] + public async Task Should_update_modifiers_correctly() + { + await Browser.GotoAsync("/input/button.html"); + var button = Browser.Locator("button"); + await button.TapAsync(new ClickOptions { Modifiers = [KeyModifier.Shift] }); + Assert.That(await Browser.EvaluateAsync("shiftKey"), Is.True); + await button.TapAsync(); + Assert.That(await Browser.EvaluateAsync("shiftKey"), Is.False); + await Browser.Keyboard.DownAsync("Shift"); + await button.TapAsync(); + Assert.That(await Browser.EvaluateAsync("shiftKey"), Is.True); + await Browser.Keyboard.UpAsync("Shift"); + await button.TapAsync(); + Assert.That(await Browser.EvaluateAsync("shiftKey"), Is.False); + } + + [Test] + public async Task Should_click_an_offscreen_element_when_scroll_behavior_is_smooth() + { + await Browser.GotoAsync(Content(""" +
+ +
+ """)); + await Browser.Locator("button").TapAsync(); + Assert.That(await Browser.EvaluateAsync("window.clicked"), Is.True); + } + + [Test] + public async Task Should_click_the_button_when_window_innerWidth_is_corrupted() + { + await Browser.GotoAsync("/input/button.html"); + await Browser.EvaluateAsync("() => { Object.defineProperty(window, 'innerWidth', { value: 0 }); }"); + await Browser.Locator("button").TapAsync(); + Assert.That(await ResultAsync(), Is.EqualTo("Clicked")); + } + + [Test] + public async Task Should_click_zero_sized_input_by_label() + { + // Known difference (hardkoded/e2e-dotnet#1080): the label is not actionable. + await ExpectedToFailAsync("not visible", async () => + { + await Browser.GotoAsync(Content(""" + + """)); + await Screen.GetByText("Click me").TapAsync(new ActionOptions { Timeout = TimeSpan.FromSeconds(3) }); + Equal(true, await Browser.EvaluateAsync("window.__clicked")); + }); + } + + [Test] + public async Task Should_climb_dom_for_inner_label_with_pointer_events_none() + { + await Browser.GotoAsync(Content("")); + await Screen.GetByText("Click target").TapAsync(); + Assert.That(await Browser.EvaluateAsync("__CLICKED"), Is.True); + } + + [Test] + public async Task Should_climb_up_to_role_button() + { + await Browser.GotoAsync(Content("
Click target
")); + await Screen.GetByText("Click target").TapAsync(); + Assert.That(await Browser.EvaluateAsync("__CLICKED"), Is.True); + } + + [Test] + public async Task Should_climb_up_to_a_anchor() + { + await Browser.GotoAsync(Content("
Inner
")); + await Browser.Locator("#inner").TapAsync(); + Assert.That(await Browser.EvaluateAsync("__CLICKED"), Is.True); + } + + [Test] + public async Task Should_climb_up_to_a_role_link() + { + await Browser.GotoAsync(Content("
Inner
")); + await Browser.Locator("#inner").TapAsync(); + Assert.That(await Browser.EvaluateAsync("__CLICKED"), Is.True); + } + + [Test] + public async Task Should_click_in_an_iframe_with_border() + { + await Browser.GotoAsync(Content(""" + + + """)); + await Browser.FrameLocator("iframe").Locator("div").TapAsync(); + Assert.That(await Browser.EvaluateAsync("window._clicked"), Is.True); + } + + [Test] + public async Task Should_click_in_a_transformed_iframe() + { + await Browser.GotoAsync(Content(""" + + + """)); + await Browser.FrameLocator("iframe").Locator("div").TapAsync(); + Assert.That(await Browser.EvaluateAsync("window._clicked"), Is.True); + } + + [Test] + public async Task Should_click_in_a_nested_transformed_iframe() + { + await Browser.GotoAsync(Content(""" + + + """)); + await Browser.FrameLocator("iframe").FrameLocator("iframe").Locator("div").TapAsync(); + Assert.That(await Browser.EvaluateAsync("window._clicked"), Is.True); + } + + [Test] + public async Task Should_click_if_opened_select_covers_the_button() + { + await Browser.GotoAsync(Content(""" +
+ +
+
+ """)); + await Browser.Locator("select").TapAsync(); + await Browser.Locator("button").TapAsync(); + Assert.That(await Browser.EvaluateAsync("window.__CLICKED"), Is.EqualTo(42)); + } + + [Test] + public async Task Should_fire_contextmenu_event_on_right_click_in_correct_order() + { + await Browser.GotoAsync(Content("")); + await Browser.EvaluateAsync("() => { window.entries = []; const log = (event) => window.entries.push(event.type); for (const type of ['mousedown', 'mouseup', 'contextmenu']) document.addEventListener(type, log); }"); + await Screen.GetByRole("button", "Click me").SecondaryTapAsync(); + await Expect.Poll(() => Browser.EvaluateAsync("entries")).ToMatchAsync(Is.EqualTo(new[] { "mousedown", "contextmenu", "mouseup" })); + } + + [Test] + public async Task Should_click_after_a_right_click() + { + await Browser.GotoAsync(Content(""" + + + """)); + await Screen.GetByRole("button").SecondaryTapAsync(); + await Screen.GetByRole("button").TapAsync(); + await Expect.That(Screen.GetByRole("button")).ToHaveTextAsync("Clicked!"); + } + + [Test] + public async Task Should_click_into_shadow_root_with_slotted_div() + { + await Browser.GotoAsync(Content(""" + + +
Foo
+
+ """)); + await Screen.GetByRole("button", "Foo").TapAsync(); + Assert.That(await Browser.EvaluateAsync("window.__clicked"), Is.True); + } + + [Test] + public async Task Should_click_shadow_root_button() + { + await Browser.GotoAsync(Content(""" + + +
Foo
+
+ """)); + await Browser.Locator("my-button").TapAsync(); + Assert.That(await Browser.EvaluateAsync("window.__clicked"), Is.True); + } +} diff --git a/tests/E2E.NUnit.Tests/ClickScroll/PageClickScrollTests.cs b/tests/E2E.NUnit.Tests/ClickScroll/PageClickScrollTests.cs new file mode 100644 index 000000000..74f43d2ed --- /dev/null +++ b/tests/E2E.NUnit.Tests/ClickScroll/PageClickScrollTests.cs @@ -0,0 +1,113 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.ClickScroll; + +/// +/// test.describe('page click scroll') of upstream's apps/testbed/tests/click-scroll.e2e.ts (Playwright's +/// page-click-scroll.spec.ts). TapAsync stands for page.click, and a text= selector is a substring +/// GetByText. Not ported, as upstream: should not crash when force-clicking hidden input (no force); should not scroll the page +/// when scroll is "none", should click in-viewport element when scroll is "none", should not scroll nested container when scroll is "none", +/// should not scroll on hover when scroll is "none" (no scroll option); should scroll into view display:contents with position +/// (Playwright skips it on Chromium). +/// +public sealed class PageClickScrollTests : PlaywrightTest +{ + [Test] + public async Task Should_not_hit_scroll_bar() + { + await Browser.GotoAsync(Content(""" + +
+ + + + + + + +
+ """)); + await Screen.GetByText("Story", exact: false).TapAsync(new ActionOptions { Timeout = TimeSpan.FromSeconds(2) }); + } + + [Test] + public async Task Should_scroll_into_view_display_contents() + { + await Browser.GotoAsync(Content(""" +
filler
+
+ Example text, and button here: + +
+ """)); + await Screen.GetByText("click me", exact: false).TapAsync(new ActionOptions { Timeout = TimeSpan.FromSeconds(5) }); + Assert.That(await Browser.EvaluateAsync("window._clicked"), Is.True); + } + + [Test] + public async Task Should_scroll_into_view_display_contents_with_a_child() + { + await Browser.GotoAsync(Content(""" +
filler
+ Example text, and button here: + + """)); + await Screen.GetByText("click me", exact: false).TapAsync(new ActionOptions { Timeout = TimeSpan.FromSeconds(5) }); + Assert.That(await Browser.EvaluateAsync("window._clicked"), Is.True); + } + + [Test] + public async Task Should_scroll_into_view_span_element() + { + await Browser.GotoAsync(Content(""" +
+ foo + """)); + await Browser.Locator("#small").ScrollIntoViewAsync(); + Assert.That(await Browser.EvaluateAsync("() => window.scrollY"), Is.GreaterThan(9000)); + } + + [Test] + public async Task Should_scroll_into_view_element_in_iframe() + { + await Browser.GotoAsync("/empty.html"); + await Browser.GotoAsync(Content($""" +
+ + """)); + await Browser.FrameLocator("iframe").GetByRole("button").TapAsync(new ActionOptions { Timeout = TimeSpan.FromSeconds(5) }); + } + + [Test] + public async Task Should_scroll_instantly_on_retry_when_scroll_behavior_is_smooth() + { + await Browser.GotoAsync(Content(""" + + +
+ +
+ + """)); + await Browser.Locator("button").TapAsync(); + Assert.That(await Browser.EvaluateAsync("window.clicked"), Is.True); + var scrolls = await Browser.EvaluateAsync("() => window['scrolls']"); + Assert.That(scrolls!.Length, Is.LessThanOrEqualTo(2)); + } +} diff --git a/tests/E2E.NUnit.Tests/ElementhandleScrollIntoView/ElementhandleScrollIntoViewTests.cs b/tests/E2E.NUnit.Tests/ElementhandleScrollIntoView/ElementhandleScrollIntoViewTests.cs new file mode 100644 index 000000000..20a95d6d7 --- /dev/null +++ b/tests/E2E.NUnit.Tests/ElementhandleScrollIntoView/ElementhandleScrollIntoViewTests.cs @@ -0,0 +1,131 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.ElementhandleScrollIntoView; + +/// +/// test.describe('elementhandle scroll into view') of upstream's apps/testbed/tests/elementhandle-scroll-into-view.e2e.ts +/// (Playwright's elementhandle-scroll-into-view.spec.ts). An element handle's scrollIntoViewIfNeeded is +/// ScrollIntoViewAsync on a locator. Not ported, as upstream: should throw for detached element (a handle to a removed element; a +/// locator re-resolves). +/// +public sealed class ElementhandleScrollIntoViewTests : PlaywrightTest +{ + /// + /// Starts scrolling the page's one div into view, checks it is still waiting a second later, runs on the + /// div in the page, and checks the scroll then finishes: Playwright's testWaiting. + /// + private async Task TestWaitingAsync(string after) + { + var done = false; + var promise = Task.Run(async () => + { + await Browser.Locator("div").ScrollIntoViewAsync(); + done = true; + }); + await Task.Delay(1000); + Assert.That(done, Is.False); + await Browser.EvaluateAsync($"() => {{ const div = document.querySelector('div'); ({after})(div); }}"); + await promise; + Assert.That(done, Is.True); + } + + [Test] + public async Task Should_work_smoke() + { + await Browser.GotoAsync("/offscreenbuttons.html"); + const string overflow = "(id) => document.getElementById(id).getBoundingClientRect().right - window.innerWidth"; + for (var i = 0; i < 11; ++i) + { + var before = await Browser.EvaluateAsync(overflow, $"btn{i}"); + Assert.That(before, Is.EqualTo(10 * i)); + await Browser.Locator($"#btn{i}").ScrollIntoViewAsync(); + var after = await Browser.EvaluateAsync(overflow, $"btn{i}"); + Assert.That(after <= 0, Is.True); + await Browser.EvaluateAsync("() => window.scrollTo(0, 0)"); + } + } + + [Test] + public async Task Should_wait_for_display_none_to_become_visible() + { + await Browser.GotoAsync(Content("
Hello
")); + await TestWaitingAsync("div => div.style.display = 'block'"); + } + + [Test] + public async Task Should_scroll_display_contents_into_view() + { + await Browser.GotoAsync(Content(""" + +
+
+
+
Hello
+
+
+
+ """)); + await Browser.Locator("#target").ScrollIntoViewAsync(); + var scrollTop = await Browser.EvaluateAsync("() => document.querySelector('#container').scrollTop"); + Assert.That(Math.Abs(scrollTop - 350), Is.LessThan(1)); + } + + [Test] + public async Task Should_work_for_visibility_hidden_element() + { + // Known difference (hardkoded/e2e-dotnet#1081): ScrollIntoViewAsync refuses a hidden node. + await ExpectedToFailAsync("is hidden", async () => + { + await Browser.GotoAsync(Content("
Hello
")); + await Browser.Locator("div").ScrollIntoViewAsync(new ActionOptions { Timeout = TimeSpan.FromSeconds(3) }); + }); + } + + [Test] + public async Task Should_work_for_zero_sized_element() + { + await Browser.GotoAsync(Content("
Hello
")); + await Browser.Locator("div").ScrollIntoViewAsync(); + } + + [Test] + public async Task Should_wait_for_nested_display_none_to_become_visible() + { + await Browser.GotoAsync(Content("
Hello
")); + await TestWaitingAsync("div => div.parentElement.style.display = 'block'"); + } + + [Test] + public async Task Should_wait_for_element_to_stop_moving() + { + await Browser.GotoAsync(Content(""" + +
moving
+ """)); + await TestWaitingAsync("div => div.classList.remove('animated')"); + } + + [Test] + public async Task Should_timeout_waiting_for_visible() + { + await Browser.GotoAsync(Content("
Hello
")); + var error = await Assert.CatchAsync(() => Browser.Locator("div").ScrollIntoViewAsync(new ActionOptions { Timeout = TimeSpan.FromSeconds(3) })); + Assert.That(error, Is.InstanceOf()); + } +} diff --git a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs index da38a9b5c..3626c5ec8 100644 --- a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs +++ b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs @@ -15,6 +15,12 @@ internal static class Helpers /// The app's origin, Playwright's server.PREFIX in the tests ported from it. public static string PREFIX => E2E.Playground.Testbed.Url; + /// Another origin on the same app, Playwright's server.CROSS_PROCESS_PREFIX. + public static string CROSS => PREFIX.Replace("127.0.0.1", "localhost", StringComparison.Ordinal); + + /// The absolute path of one of Playwright's test assets. + public static string Asset(string name) => Path.Combine(AppContext.BaseDirectory, "Testbed", "playwright", "assets", name); + /// A path that serves as a page, for Playwright's page.setContent(html). public static string Content(string html) => "/content?html=" + Convert.ToBase64String(Encoding.UTF8.GetBytes(html)).TrimEnd('=').Replace('+', '-').Replace('/', '_'); diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/button.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/button.html new file mode 100644 index 000000000..bfce25ee0 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/button.html @@ -0,0 +1,32 @@ + + + + Button test + + + + + + + \ No newline at end of file diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/checkbox.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/checkbox.html new file mode 100644 index 000000000..ca56762e2 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/checkbox.html @@ -0,0 +1,42 @@ + + + + Selection Test + + + + + + + diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/rotatedButton.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/rotatedButton.html new file mode 100644 index 000000000..1bce66cf5 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/rotatedButton.html @@ -0,0 +1,21 @@ + + + + Rotated button test + + + + + + + + diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/scrollable.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/scrollable.html new file mode 100644 index 000000000..885d3739d --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/scrollable.html @@ -0,0 +1,23 @@ + + + + Scrollable test + + + + + + \ No newline at end of file diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/offscreenbuttons.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/offscreenbuttons.html new file mode 100644 index 000000000..b7f381dec --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/offscreenbuttons.html @@ -0,0 +1,55 @@ + +
+ + + + + + + + + + + +
+ diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/wrappedlink.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/wrappedlink.html new file mode 100644 index 000000000..429b6e915 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/wrappedlink.html @@ -0,0 +1,32 @@ + +
+ 123321 +
+ From b75960816dae9e521ff5a14b1c7cda5c0d7a4303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:13:49 -0300 Subject: [PATCH 6/9] Add the mouse helper script the input pages load (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- .../playwright/assets/input/mouse-helper.js | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/mouse-helper.js diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/mouse-helper.js b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/mouse-helper.js new file mode 100644 index 000000000..3c4d57033 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/mouse-helper.js @@ -0,0 +1,62 @@ +// This injects a box into the page that moves with the mouse; +// Useful for debugging +(function(){ + const box = document.createElement('div'); + box.classList.add('mouse-helper'); + const styleElement = document.createElement('style'); + styleElement.innerHTML = ` + .mouse-helper { + pointer-events: none; + position: absolute; + top: 0; + left: 0; + width: 20px; + height: 20px; + background: rgba(0,0,0,.4); + border: 1px solid white; + border-radius: 10px; + margin-left: -10px; + margin-top: -10px; + transition: background .2s, border-radius .2s, border-color .2s; + } + .mouse-helper.button-1 { + transition: none; + background: rgba(0,0,0,0.9); + } + .mouse-helper.button-2 { + transition: none; + border-color: rgba(0,0,255,0.9); + } + .mouse-helper.button-3 { + transition: none; + border-radius: 4px; + } + .mouse-helper.button-4 { + transition: none; + border-color: rgba(255,0,0,0.9); + } + .mouse-helper.button-5 { + transition: none; + border-color: rgba(0,255,0,0.9); + } + `; + document.head.appendChild(styleElement); + document.body.appendChild(box); + document.addEventListener('mousemove', event => { + box.style.left = event.pageX + 'px'; + box.style.top = event.pageY + 'px'; + updateButtons(event.buttons); + }, true); + document.addEventListener('mousedown', event => { + updateButtons(event.buttons); + box.classList.add('button-' + event.which); + }, true); + document.addEventListener('mouseup', event => { + updateButtons(event.buttons); + box.classList.remove('button-' + event.which); + }, true); + function updateButtons(buttons) { + for (let i = 0; i < 5; i++) + box.classList.toggle('button-' + i, buttons & (1 << i)); + } +})(); From 6dca0c8a6bce54e5e1a31a661c65a2a1cb7ca5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:17:06 -0300 Subject: [PATCH 7/9] Port Playwright's keyboard tests (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- COMPATIBILITY.md | 2 +- tests/E2E.Agent.Tests/Testbed.cs | 1 + tests/E2E.NUnit.Tests/Helpers/Helpers.cs | 6 + .../Keyboard/PageKeyboardTests.cs | 801 ++++++++++++++++++ .../playwright/assets/input/keyboard.html | 51 ++ .../playwright/assets/input/mouse-helper.js | 62 ++ .../playwright/assets/input/scrollable.html | 23 + .../playwright/assets/input/textarea.html | 20 + 8 files changed, 965 insertions(+), 1 deletion(-) create mode 100644 tests/E2E.NUnit.Tests/Keyboard/PageKeyboardTests.cs create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/keyboard.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/mouse-helper.js create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/scrollable.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/textarea.html diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 1bdd8a6c4..d9fea9f28 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -162,7 +162,7 @@ Differences: - Upstream's docs site pages that have no counterpart in the port: the page objects page (`docs/page-objects.mdx`, moved to `/page-object-model` in `d30114a`), `e2e feedback` and the `docs/reference/cli.mdx` text about its opt-out variables (`4c1e2e8`), and `examples/` with its registry (`b3ae3a4`, `38b802d`, `a29edcb`, `b54646f`). The migration guides (`docs/migrate/*.mdx`, `8537abc`) are ported: see [Migration guides](#migration-guides). The docs site has .NET-only guides for upstream's five example apps of `caf51eb` (tester-army/e2e#1497: i18n, file upload, location, biometrics, deep links), under [Examples](docs-site/src/content/docs/examples/index.mdx). They are not ports: that commit only adds registry entries that link to separate repositories, so there was no guide text. Each page writes C# tests for the upstream app. The self-healing deep dive (`6fa99ea`) is ported as the [Self-healing tests](README.md#self-healing-tests) section of the guide, since the port has no docs pages for the cache, the trace page, or executors to link to. Known gap: only `e2e explore` prints a run summary, since it is the one command that feeds a run to `ListReporter` (see [List reporter](#list-reporter)): the `Cache 4 replayed · 1 handed off · 1 missed` row is `Format.CacheText` over `Format.StepsCacheTally` (`E2E.Cli`, upstream's `cacheText` and `stepsCacheTally` of `report/format.ts`), which an exploration, with its cache off, never fills, and a test run does not print ([#799](https://github.com/hardkoded/e2e-dotnet/issues/799)) - Parallel workers and serial suites - `test.fail` and the `fail` test option (tester-army/e2e#1539, `732ea8a`): a test expected to fail, whose product failure passes and whose pass fails with `UNEXPECTED_PASS`. It lives in upstream's test registry, scheduler, retry, and reporters (`settleExpectedFailure` runs on a finished attempt), and the port has none of them. NUnit and xUnit v3 own the verdict and the retries, and neither has an expected-failure outcome, so a port would need a new public API of its own -- Playwright's page tests in the testbed suite (tester-army/e2e#1505, `bdf769b`) are ported in slices (hardkoded/e2e-dotnet#1060), as the `playwright` category of `tests/E2E.NUnit.Tests`, against the playground's `/content` route and Playwright's test assets (Apache-2.0, `Testbed/playwright/`, with Playwright's `LICENSE` and `NOTICE`). A test upstream marks `{ fail: 'reason' }` keeps its assertions inside the test-only `Helpers.ExpectedToFailAsync`, which passes while the body fails and fails once it passes. Ported so far: `check`, `wait-for-url`, `locator-list`, and `selectors-text` (one test is such a known difference, hardkoded/e2e-dotnet#1062). +- Playwright's page tests in the testbed suite (tester-army/e2e#1505, `bdf769b`) are ported in slices (hardkoded/e2e-dotnet#1060), as the `playwright` category of `tests/E2E.NUnit.Tests`, against the playground's `/content` route and Playwright's test assets (Apache-2.0, `Testbed/playwright/`, with Playwright's `LICENSE` and `NOTICE`). A test upstream marks `{ fail: 'reason' }` keeps its assertions inside the test-only `Helpers.ExpectedToFailAsync`, which passes while the body fails and fails once it passes. Ported so far: `check`, `wait-for-url`, `locator-list`, `selectors-text` (one test is such a known difference, hardkoded/e2e-dotnet#1062), and `keyboard`. - Serial groups (upstream tester-army/e2e#1056, #1470): serial runs, group retries, and skipping the rest of a group after a failure belong to the test runner, which is NUnit or xUnit here, so the port keeps no serial groups. The schema has `serialAttempt.cutRetry` and the serial verdict is read from it, but nothing in the port writes a serial attempt: see [Report document](#report-document) - The out-of-process engine protocol (upstream tester-army/e2e#1232, [#873](https://github.com/hardkoded/e2e-dotnet/issues/873)): the port has no runner and no worker pool, so there is no engine process to talk to. An engine is written in .NET against `IEngine` - Diff-only observations for a custom executor's own model turns. The built-in agent has them (#1022): `#id` lines on the opening screen and on `observe`, and a diff after each action (see [MCP server](#mcp-server) for the presenter). `ExecutorObservation.Text`, which an executor reads from `Observe`, keeps the full `[ref=…]` snapshot, cut at the observation byte budget (see [Agents](#agents)), and a node is addressed by its ref there (`new ExecutorTarget("e12")`), so a custom executor has no presenter of its own. Upstream gives every executor the `#id` view. diff --git a/tests/E2E.Agent.Tests/Testbed.cs b/tests/E2E.Agent.Tests/Testbed.cs index d2a2336cf..02118f198 100644 --- a/tests/E2E.Agent.Tests/Testbed.cs +++ b/tests/E2E.Agent.Tests/Testbed.cs @@ -929,6 +929,7 @@ private static string Start() url = "http://127.0.0.1:" + port.ToString(CultureInfo.InvariantCulture) + "/"; listener = new HttpListener(); listener.Prefixes.Add(url); + listener.Prefixes.Add(url.Replace("127.0.0.1", "localhost", StringComparison.Ordinal)); try { listener.Start(); diff --git a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs index da38a9b5c..3626c5ec8 100644 --- a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs +++ b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs @@ -15,6 +15,12 @@ internal static class Helpers /// The app's origin, Playwright's server.PREFIX in the tests ported from it. public static string PREFIX => E2E.Playground.Testbed.Url; + /// Another origin on the same app, Playwright's server.CROSS_PROCESS_PREFIX. + public static string CROSS => PREFIX.Replace("127.0.0.1", "localhost", StringComparison.Ordinal); + + /// The absolute path of one of Playwright's test assets. + public static string Asset(string name) => Path.Combine(AppContext.BaseDirectory, "Testbed", "playwright", "assets", name); + /// A path that serves as a page, for Playwright's page.setContent(html). public static string Content(string html) => "/content?html=" + Convert.ToBase64String(Encoding.UTF8.GetBytes(html)).TrimEnd('=').Replace('+', '-').Replace('/', '_'); diff --git a/tests/E2E.NUnit.Tests/Keyboard/PageKeyboardTests.cs b/tests/E2E.NUnit.Tests/Keyboard/PageKeyboardTests.cs new file mode 100644 index 000000000..d62c6323b --- /dev/null +++ b/tests/E2E.NUnit.Tests/Keyboard/PageKeyboardTests.cs @@ -0,0 +1,801 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.Keyboard; + +/// +/// test.describe('page keyboard') of upstream's apps/testbed/tests/keyboard.e2e.ts (Playwright's page-keyboard.spec.ts). +/// PressSequentiallyAsync stands for page.type(selector, text), and an element press of a key Locator.PressAsync does +/// not name (a code like Digit5) is a focus and a keyboard press. Not ported, as upstream: should send a character with insertText, +/// insertText should only emit input event (no keyboard.insertText); should expose keyIdentifier in webkit (WebKit only); should +/// dispatch insertText after context menu was opened (no keyboard.insertText, and mouse.down presses only the primary button); +/// should type after context menu was opened (mouse.down presses only the primary button). +/// +public sealed class PageKeyboardTests : PlaywrightTest +{ + /// Records the last keydown in window.lastEvent, Playwright's captureLastKeydown. + private const string CaptureLastKeydown = """ + () => { + const lastEvent = { repeat: false, location: -1, code: '', key: '', metaKey: false, keyIdentifier: 'unsupported' }; + window.lastEvent = lastEvent; + document.addEventListener('keydown', (e) => { + lastEvent.repeat = e.repeat; + lastEvent.location = e.location; + lastEvent.key = e.key; + lastEvent.code = e.code; + lastEvent.metaKey = e.metaKey; + lastEvent.keyIdentifier = 'keyIdentifier' in e && typeof e.keyIdentifier === 'string' && e.keyIdentifier; + }, true); + } + """; + + private static readonly bool IsMac = OperatingSystem.IsMacOS(); + + private async Task TextareaValueAsync() => + (await Browser.EvaluateAsync("() => document.querySelector('textarea').value"))!; + + private async Task ResultAsync() => (await Browser.EvaluateAsync("getResult()"))!; + + private static string Lines(params string[] lines) => string.Join('\n', lines); + + [Test] + public async Task Should_type_into_a_textarea() + { + await Browser.GotoAsync("/empty.html"); + await Browser.EvaluateAsync("() => { const textarea = document.createElement('textarea'); document.body.appendChild(textarea); textarea.focus(); }"); + const string text = "Hello world. I am the text that was typed!"; + await Browser.Keyboard.TypeAsync(text); + Assert.That(await TextareaValueAsync(), Is.EqualTo(text)); + } + + [Test] + public async Task Should_move_with_the_arrow_keys() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("textarea").PressSequentiallyAsync("Hello World!"); + Assert.That(await TextareaValueAsync(), Is.EqualTo("Hello World!")); + for (var i = 0; i < "World!".Length; i++) + { + await Browser.Keyboard.PressAsync("ArrowLeft"); + } + + await Browser.Keyboard.TypeAsync("inserted "); + Assert.That(await TextareaValueAsync(), Is.EqualTo("Hello inserted World!")); + await Browser.Keyboard.DownAsync("Shift"); + for (var i = 0; i < "inserted ".Length; i++) + { + await Browser.Keyboard.PressAsync("ArrowLeft"); + } + + await Browser.Keyboard.UpAsync("Shift"); + await Browser.Keyboard.PressAsync("Backspace"); + Assert.That(await TextareaValueAsync(), Is.EqualTo("Hello World!")); + } + + [Test] + public async Task Should_send_a_character_with_ElementHandle_press() + { + await Browser.GotoAsync("/input/textarea.html"); + var textarea = Browser.Locator("textarea"); + await textarea.PressAsync("a"); + Assert.That(await TextareaValueAsync(), Is.EqualTo("a")); + + await Browser.EvaluateAsync("() => window.addEventListener('keydown', (e) => e.preventDefault(), true)"); + + await textarea.PressAsync("b"); + Assert.That(await TextareaValueAsync(), Is.EqualTo("a")); + } + + [Test] + public async Task Should_not_type_text_with_Alt_modifier() + { + await Browser.GotoAsync(Content("
")); + foreach (var locator in new[] { Browser.Locator("input"), Browser.Locator("textarea"), Browser.Locator("div") }) + { + await locator.FocusAsync(); + await Browser.Keyboard.PressAsync("Alt+KeyA"); + await Browser.Keyboard.PressAsync("Alt+Digit1"); + await Browser.Keyboard.PressAsync("Alt+Shift+KeyA"); + await Browser.Keyboard.DownAsync("Alt"); + await Browser.Keyboard.PressAsync("b"); + await Browser.Keyboard.UpAsync("Alt"); + await locator.PressAsync("c"); + } + + await Expect.That(Browser.Locator("input")).ToHaveValueAsync("c"); + await Expect.That(Browser.Locator("textarea")).ToHaveValueAsync("c"); + await Expect.That(Browser.Locator("div")).ToHaveTextAsync("c"); + } + + [Test] + public async Task Should_emit_keydown_keypress_textInput_and_input_when_typing_a_character() + { + await Browser.GotoAsync(Content("")); + await Browser.EvaluateAsync(""" + () => { + window.events = []; + for (const type of ['keydown', 'keypress', 'textInput', 'input', 'keyup']) + document.querySelector('input').addEventListener(type, () => window.events.push(type)); + } + """); + await Browser.Locator("input").FocusAsync(); + await Browser.Keyboard.PressAsync("f"); + Assert.That(await Browser.EvaluateAsync("events"), Is.EqualTo(new[] { "keydown", "keypress", "textInput", "input", "keyup" })); + } + + [Test] + public async Task Should_dispatch_key_events_in_separate_tasks() + { + await Browser.GotoAsync(Content("")); + await Browser.EvaluateAsync(""" + () => { + window.log = []; + const input = document.querySelector('input'); + for (const type of ['keydown', 'keypress']) + input.addEventListener(type, () => { window.log.push(type); queueMicrotask(() => window.log.push('microtask-' + type)); }); + input.focus(); + } + """); + await Browser.Keyboard.PressAsync("a"); + Assert.That(await Browser.EvaluateAsync("log"), Is.EqualTo(new[] { "keydown", "microtask-keydown", "keypress", "microtask-keypress" })); + } + + [Test] + public async Task Should_report_shiftKey() + { + await Browser.GotoAsync("/input/keyboard.html"); + var keyboard = Browser.Keyboard; + foreach (var modifierKey in new[] { "Shift", "Alt", "Control" }) + { + await keyboard.DownAsync(modifierKey); + Assert.That(await ResultAsync(), Is.EqualTo("Keydown: " + modifierKey + " " + modifierKey + "Left LEFT [" + modifierKey + "]")); + await keyboard.DownAsync("!"); + if (modifierKey == "Shift") + { + Assert.That(await ResultAsync(), Is.EqualTo("Keydown: ! Digit1 STANDARD [" + modifierKey + "]\nKeypress: ! Digit1 STANDARD 33 [" + modifierKey + "]")); + } + else + { + Assert.That(await ResultAsync(), Is.EqualTo("Keydown: ! Digit1 STANDARD [" + modifierKey + "]")); + } + + await keyboard.UpAsync("!"); + Assert.That(await ResultAsync(), Is.EqualTo("Keyup: ! Digit1 STANDARD [" + modifierKey + "]")); + await keyboard.UpAsync(modifierKey); + Assert.That(await ResultAsync(), Is.EqualTo("Keyup: " + modifierKey + " " + modifierKey + "Left LEFT []")); + } + } + + [Test] + public async Task Should_report_multiple_modifiers() + { + await Browser.GotoAsync("/input/keyboard.html"); + var keyboard = Browser.Keyboard; + await keyboard.DownAsync("Control"); + Assert.That(await ResultAsync(), Is.EqualTo("Keydown: Control ControlLeft LEFT [Control]")); + await keyboard.DownAsync("Alt"); + Assert.That(await ResultAsync(), Is.EqualTo("Keydown: Alt AltLeft LEFT [Alt Control]")); + await keyboard.DownAsync(";"); + Assert.That(await ResultAsync(), Is.EqualTo("Keydown: ; Semicolon STANDARD [Alt Control]")); + await keyboard.UpAsync(";"); + Assert.That(await ResultAsync(), Is.EqualTo("Keyup: ; Semicolon STANDARD [Alt Control]")); + await keyboard.UpAsync("Control"); + Assert.That(await ResultAsync(), Is.EqualTo("Keyup: Control ControlLeft LEFT [Alt]")); + await keyboard.UpAsync("Alt"); + Assert.That(await ResultAsync(), Is.EqualTo("Keyup: Alt AltLeft LEFT []")); + } + + [Test] + public async Task Should_send_proper_codes_while_typing() + { + await Browser.GotoAsync("/input/keyboard.html"); + await Browser.Keyboard.TypeAsync("!"); + Assert.That( + await ResultAsync(), + Is.EqualTo(Lines("Keydown: ! Digit1 STANDARD []", "Keypress: ! Digit1 STANDARD 33 []", "Keyup: ! Digit1 STANDARD []"))); + await Browser.Keyboard.TypeAsync("^"); + Assert.That( + await ResultAsync(), + Is.EqualTo(Lines("Keydown: ^ Digit6 STANDARD []", "Keypress: ^ Digit6 STANDARD 94 []", "Keyup: ^ Digit6 STANDARD []"))); + } + + [Test] + public async Task Should_send_proper_codes_while_typing_with_shift() + { + await Browser.GotoAsync("/input/keyboard.html"); + var keyboard = Browser.Keyboard; + await keyboard.DownAsync("Shift"); + await Browser.Keyboard.TypeAsync("~"); + Assert.That( + await ResultAsync(), + Is.EqualTo(Lines( + "Keydown: Shift ShiftLeft LEFT [Shift]", + "Keydown: ~ Backquote STANDARD [Shift]", + "Keypress: ~ Backquote STANDARD 126 [Shift]", + "Keyup: ~ Backquote STANDARD [Shift]"))); + await keyboard.UpAsync("Shift"); + } + + [Test] + public async Task Should_not_type_canceled_events() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("textarea").FocusAsync(); + await Browser.EvaluateAsync(""" + () => { + window.addEventListener('keydown', (event) => { + event.stopPropagation(); + event.stopImmediatePropagation(); + if (event.key === 'l') + event.preventDefault(); + if (event.key === 'o') + event.preventDefault(); + }, false); + } + """); + await Browser.Keyboard.TypeAsync("Hello World!"); + Assert.That(await TextareaValueAsync(), Is.EqualTo("He Wrd!")); + } + + [Test] + public async Task Should_press_plus() + { + await Browser.GotoAsync("/input/keyboard.html"); + await Browser.Keyboard.PressAsync("+"); + Assert.That( + await ResultAsync(), + Is.EqualTo(Lines("Keydown: + Equal STANDARD []", "Keypress: + Equal STANDARD 43 []", "Keyup: + Equal STANDARD []"))); + } + + [Test] + public async Task Should_press_shift_plus() + { + await Browser.GotoAsync("/input/keyboard.html"); + await Browser.Keyboard.PressAsync("Shift++"); + Assert.That( + await ResultAsync(), + Is.EqualTo(Lines( + "Keydown: Shift ShiftLeft LEFT [Shift]", + "Keydown: + Equal STANDARD [Shift]", + "Keypress: + Equal STANDARD 43 [Shift]", + "Keyup: + Equal STANDARD [Shift]", + "Keyup: Shift ShiftLeft LEFT []"))); + } + + [Test] + public async Task Should_support_plus_separated_modifiers() + { + await Browser.GotoAsync("/input/keyboard.html"); + await Browser.Keyboard.PressAsync("Shift+~"); + Assert.That( + await ResultAsync(), + Is.EqualTo(Lines( + "Keydown: Shift ShiftLeft LEFT [Shift]", + "Keydown: ~ Backquote STANDARD [Shift]", + "Keypress: ~ Backquote STANDARD 126 [Shift]", + "Keyup: ~ Backquote STANDARD [Shift]", + "Keyup: Shift ShiftLeft LEFT []"))); + } + + [Test] + public async Task Should_support_multiple_plus_separated_modifiers() + { + await Browser.GotoAsync("/input/keyboard.html"); + await Browser.Keyboard.PressAsync("Control+Shift+~"); + Assert.That( + await ResultAsync(), + Is.EqualTo(Lines( + "Keydown: Control ControlLeft LEFT [Control]", + "Keydown: Shift ShiftLeft LEFT [Control Shift]", + "Keydown: ~ Backquote STANDARD [Control Shift]", + "Keyup: ~ Backquote STANDARD [Control Shift]", + "Keyup: Shift ShiftLeft LEFT [Control]", + "Keyup: Control ControlLeft LEFT []"))); + } + + [Test] + public async Task Should_shift_raw_codes() + { + await Browser.GotoAsync("/input/keyboard.html"); + await Browser.Keyboard.PressAsync("Shift+Digit3"); + Assert.That( + await ResultAsync(), + Is.EqualTo(Lines( + "Keydown: Shift ShiftLeft LEFT [Shift]", + "Keydown: # Digit3 STANDARD [Shift]", + "Keypress: # Digit3 STANDARD 35 [Shift]", + "Keyup: # Digit3 STANDARD [Shift]", + "Keyup: Shift ShiftLeft LEFT []"))); + } + + [Test] + public async Task Should_specify_repeat_property() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("textarea").FocusAsync(); + await Browser.EvaluateAsync(CaptureLastKeydown); + await Browser.Keyboard.DownAsync("a"); + Assert.That(await Browser.EvaluateAsync("lastEvent.repeat"), Is.False); + await Browser.Keyboard.PressAsync("a"); + Assert.That(await Browser.EvaluateAsync("lastEvent.repeat"), Is.True); + + await Browser.Keyboard.DownAsync("b"); + Assert.That(await Browser.EvaluateAsync("lastEvent.repeat"), Is.False); + await Browser.Keyboard.DownAsync("b"); + Assert.That(await Browser.EvaluateAsync("lastEvent.repeat"), Is.True); + + await Browser.Keyboard.UpAsync("a"); + await Browser.Keyboard.DownAsync("a"); + Assert.That(await Browser.EvaluateAsync("lastEvent.repeat"), Is.False); + } + + [Test] + public async Task Should_type_all_kinds_of_characters() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("textarea").FocusAsync(); + const string text = "This text goes onto two lines.\nThis character is 嗨."; + await Browser.Keyboard.TypeAsync(text); + Assert.That(await TextareaValueAsync(), Is.EqualTo(text)); + } + + /// Reads lastEvent's location, key, and code and checks them together, Playwright's three expect.soft calls. + private async Task ExpectLastKeydownAsync(int location, string key, string code) + { + var actualLocation = await Browser.EvaluateAsync("lastEvent.location"); + var actualKey = await Browser.EvaluateAsync("lastEvent.key"); + var actualCode = await Browser.EvaluateAsync("lastEvent.code"); + Assert.Multiple(() => + { + Assert.That(actualLocation, Is.EqualTo(location)); + Assert.That(actualKey, Is.EqualTo(key)); + Assert.That(actualCode, Is.EqualTo(code)); + }); + } + + [Test] + public async Task Should_specify_location() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.EvaluateAsync(CaptureLastKeydown); + var textarea = Browser.Locator("textarea"); + + await textarea.FocusAsync(); + await Browser.Keyboard.PressAsync("Digit5"); + await ExpectLastKeydownAsync(0, "5", "Digit5"); + + await textarea.FocusAsync(); + await Browser.Keyboard.PressAsync("ControlLeft"); + await ExpectLastKeydownAsync(1, "Control", "ControlLeft"); + + await textarea.FocusAsync(); + await Browser.Keyboard.PressAsync("ControlRight"); + await ExpectLastKeydownAsync(2, "Control", "ControlRight"); + + await textarea.FocusAsync(); + await Browser.Keyboard.PressAsync("NumpadSubtract"); + await ExpectLastKeydownAsync(3, "-", "NumpadSubtract"); + } + + [Test] + public async Task Should_specify_numpad_location_on_keyup() + { + await Browser.GotoAsync("/input/keyboard.html"); + await Browser.Keyboard.PressAsync("NumpadSubtract"); + Assert.That( + await ResultAsync(), + Is.EqualTo(Lines("Keydown: - NumpadSubtract NUMPAD []", "Keypress: - NumpadSubtract NUMPAD 45 []", "Keyup: - NumpadSubtract NUMPAD []"))); + } + + [Test] + public async Task Should_press_NumpadDecimal_as_Delete() + { + await Browser.GotoAsync(Content("")); + await Browser.EvaluateAsync(CaptureLastKeydown); + var textarea = Browser.Locator("textarea"); + + await textarea.FocusAsync(); + await Browser.Keyboard.PressAsync("NumpadDecimal"); + Assert.That(await Browser.EvaluateAsync("lastEvent.key"), Is.EqualTo("Delete")); + Assert.That(await Browser.EvaluateAsync("lastEvent.code"), Is.EqualTo("NumpadDecimal")); + Assert.That(await Browser.EvaluateAsync("lastEvent.location"), Is.EqualTo(3)); + await Expect.That(textarea).ToHaveValueAsync(""); + } + + [Test] + public async Task Should_type_numpad_digits_with_Shift() + { + await Browser.GotoAsync(Content("")); + var textarea = Browser.Locator("textarea"); + await textarea.FocusAsync(); + await Browser.Keyboard.PressAsync("Shift+Numpad1"); + await Browser.Keyboard.PressAsync("Shift+NumpadDecimal"); + await Browser.Keyboard.PressAsync("Shift+Numpad9"); + await Expect.That(textarea).ToHaveValueAsync("1.9"); + } + + [Test] + public async Task Should_press_Enter() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("textarea").FocusAsync(); + await Browser.EvaluateAsync(CaptureLastKeydown); + foreach (var (key, expectedKey, expectedCode) in new[] + { + ("Enter", "Enter", "Enter"), + ("NumpadEnter", "Enter", "NumpadEnter"), + ("\n", "Enter", "Enter"), + ("\r", "Enter", "Enter"), + }) + { + await Browser.Keyboard.PressAsync(key); + Assert.That(await Browser.EvaluateAsync("lastEvent.key"), Is.EqualTo(expectedKey)); + Assert.That(await Browser.EvaluateAsync("lastEvent.code"), Is.EqualTo(expectedCode)); + Assert.That(await TextareaValueAsync(), Is.EqualTo("\n")); + await Browser.EvaluateAsync("() => { document.querySelector('textarea').value = ''; }"); + } + } + + [Test] + public async Task Should_press_audio_and_media_control_keys() + { + await Browser.GotoAsync(Content("")); + await Browser.Locator("input").FocusAsync(); + await Browser.EvaluateAsync(CaptureLastKeydown); + foreach (var mediaKey in new[] { "AudioVolumeMute", "AudioVolumeDown", "AudioVolumeUp", "MediaTrackNext", "MediaTrackPrevious", "MediaPlayPause" }) + { + await Browser.Keyboard.PressAsync(mediaKey); + await ExpectLastKeydownAsync(0, mediaKey, mediaKey); + } + } + + [Test] + public async Task Should_throw_on_unknown_keys() + { + await Browser.GotoAsync("/empty.html"); + foreach (var key in new[] { "NotARealKey", "ё", "😊" }) + { + var error = await Assert.CatchAsync(() => Browser.Keyboard.PressAsync(key)); + Assert.That(error!.Message, Does.Contain($"Unknown key: \"{key}\"")); + } + } + + [Test] + public async Task Should_type_emoji() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("textarea").PressSequentiallyAsync("👹 Tokyo street Japan 🇯🇵"); + Assert.That(await TextareaValueAsync(), Is.EqualTo("👹 Tokyo street Japan 🇯🇵")); + } + + [Test] + public async Task Should_type_emoji_into_an_iframe() + { + await Browser.GotoAsync("/empty.html"); + await Browser.EvaluateAsync(""" + () => new Promise((resolve) => { + const frame = document.createElement('iframe'); + frame.id = 'emoji-test'; + frame.src = '/input/textarea.html'; + frame.onload = resolve; + document.body.appendChild(frame); + }) + """); + await Browser.FrameLocator("#emoji-test").Locator("textarea").PressSequentiallyAsync("👹 Tokyo street Japan 🇯🇵"); + Assert.That( + await Browser.EvaluateAsync("() => document.querySelector('#emoji-test').contentDocument.querySelector('textarea').value"), + Is.EqualTo("👹 Tokyo street Japan 🇯🇵")); + } + + [Test] + public async Task Should_handle_selectAll() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("textarea").PressSequentiallyAsync("some text"); + await Browser.Keyboard.DownAsync("ControlOrMeta"); + await Browser.Keyboard.PressAsync("a"); + await Browser.Keyboard.UpAsync("ControlOrMeta"); + await Browser.Keyboard.PressAsync("Backspace"); + Assert.That(await TextareaValueAsync(), Is.EqualTo("")); + } + + [Test] + public async Task Pressing_Meta_should_not_result_in_any_text_insertion_on_any_platform() + { + await Browser.GotoAsync(Content("")); + var input = Browser.Locator("input"); + await Expect.That(input).ToHaveValueAsync("hello world"); + await input.FocusAsync(); + await Browser.Keyboard.PressAsync("Meta"); + await Expect.That(input).ToHaveValueAsync("hello world"); + } + + [Test] + public async Task Should_be_able_to_prevent_selectAll() + { + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("textarea").PressSequentiallyAsync("some text"); + await Browser.EvaluateAsync(""" + () => { + document.querySelector('textarea').addEventListener('keydown', (event) => { + if (event.key === 'a' && (event.metaKey || event.ctrlKey)) + event.preventDefault(); + }, false); + } + """); + await Browser.Keyboard.DownAsync("ControlOrMeta"); + await Browser.Keyboard.PressAsync("a"); + await Browser.Keyboard.UpAsync("ControlOrMeta"); + await Browser.Keyboard.PressAsync("Backspace"); + Assert.That(await TextareaValueAsync(), Is.EqualTo("some tex")); + } + + [Test] + public async Task Should_support_MacOS_shortcuts() + { + Assume.That(IsMac, Is.True, "macOS only"); + await Browser.GotoAsync("/input/textarea.html"); + await Browser.Locator("textarea").PressSequentiallyAsync("some text"); + await Browser.Keyboard.PressAsync("Shift+Control+Alt+KeyB"); + await Browser.Keyboard.PressAsync("Backspace"); + Assert.That(await TextareaValueAsync(), Is.EqualTo("some ")); + } + + [Test] + public async Task Should_press_the_meta_key() + { + await Browser.GotoAsync("/empty.html"); + await Browser.EvaluateAsync(CaptureLastKeydown); + await Browser.Keyboard.PressAsync("Meta"); + var last = (await Browser.EvaluateAsync("lastEvent"))!; + Assert.That(last.Key, Is.EqualTo("Meta")); + Assert.That(last.Code, Is.EqualTo("MetaLeft")); + Assert.That(last.MetaKey, Is.True); + } + + [Test] + public async Task Should_work_with_keyboard_events_with_empty_html() + { + await Browser.GotoAsync("/empty.html"); + await Browser.EvaluateAsync(CaptureLastKeydown); + await Browser.Keyboard.PressAsync("a"); + Assert.That(await Browser.EvaluateAsync("lastEvent.key"), Is.EqualTo("a")); + } + + [Test] + public async Task Should_work_after_a_cross_origin_navigation() + { + await Browser.GotoAsync("/empty.html"); + await Browser.GotoAsync($"{CROSS}/empty.html"); + await Browser.EvaluateAsync(CaptureLastKeydown); + await Browser.Keyboard.PressAsync("a"); + Assert.That(await Browser.EvaluateAsync("lastEvent.key"), Is.EqualTo("a")); + } + + [Test] + public async Task Should_scroll_with_PageDown() + { + await Browser.GotoAsync("/input/scrollable.html"); + await Browser.Locator("body").TapAsync(); + await Browser.Keyboard.PressAsync("PageDown"); + await Expect.Poll(() => Browser.EvaluateAsync("scrollY > 0")).ToBeAsync(true); + } + + [Test] + public async Task Should_move_around_the_selection_in_a_contenteditable() + { + await Browser.GotoAsync(Content("
")); + await Browser.Locator("div").FocusAsync(); + var modifier = IsMac ? "Alt" : "Control"; + await Browser.Keyboard.TypeAsync("Hello World"); + await Browser.Keyboard.DownAsync(modifier); + await Browser.Keyboard.DownAsync("Shift"); + await Browser.Keyboard.PressAsync("ArrowLeft"); + await Browser.Keyboard.UpAsync("Shift"); + await Browser.Keyboard.UpAsync(modifier); + Assert.That(await Browser.EvaluateAsync("() => window.getSelection().toString()"), Is.EqualTo("World")); + } + + [Test] + public async Task Should_move_to_the_start_of_the_document() + { + Assume.That(IsMac, Is.True, "macOS only"); + await Browser.GotoAsync(Content("
")); + await Browser.Locator("div").FocusAsync(); + await Browser.Keyboard.TypeAsync("1\n2\n3\n"); + await Browser.Keyboard.PressAsync("Shift+Meta+ArrowUp"); + Assert.That(await Browser.EvaluateAsync("() => window.getSelection().toString()"), Is.EqualTo("1\n2\n3\n")); + } + + [Test] + public async Task Should_dispatch_a_click_event_on_a_button_when_Space_gets_pressed() + { + await Browser.GotoAsync(Content("")); + await Browser.EvaluateAsync("() => { window.actual = { clicked: false }; document.querySelector('button').addEventListener('click', () => (window.actual.clicked = true)); }"); + await Browser.Locator("button").FocusAsync(); + await Browser.Keyboard.PressAsync("Space"); + Assert.That(await Browser.EvaluateAsync("actual.clicked"), Is.True); + } + + [Test] + public async Task Should_dispatch_a_click_event_on_a_button_when_Enter_gets_pressed() + { + await Browser.GotoAsync(Content("")); + await Browser.EvaluateAsync("() => { window.actual = { clicked: false }; document.querySelector('button').addEventListener('click', () => (window.actual.clicked = true)); }"); + await Browser.Locator("button").FocusAsync(); + await Browser.Keyboard.PressAsync("Enter"); + Assert.That(await Browser.EvaluateAsync("actual.clicked"), Is.True); + } + + [Test] + public async Task Should_support_simple_copy_pasting() + { + await Browser.GotoAsync(Content("
123
")); + await Browser.Locator("div").FocusAsync(); + await Browser.Keyboard.PressAsync("ControlOrMeta+KeyA"); + await Browser.Keyboard.PressAsync("ControlOrMeta+KeyC"); + await Browser.Keyboard.PressAsync("ControlOrMeta+KeyV"); + await Browser.Keyboard.PressAsync("ControlOrMeta+KeyV"); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('div').textContent"), Is.EqualTo("123123")); + } + + [Test] + public async Task Should_support_simple_cut_pasting() + { + await Browser.GotoAsync(Content("
123
")); + await Browser.Locator("div").FocusAsync(); + await Browser.Keyboard.PressAsync("ControlOrMeta+KeyA"); + await Browser.Keyboard.PressAsync("ControlOrMeta+KeyX"); + await Browser.Keyboard.PressAsync("ControlOrMeta+KeyV"); + await Browser.Keyboard.PressAsync("ControlOrMeta+KeyV"); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('div').textContent"), Is.EqualTo("123123")); + } + + [Test] + public async Task Should_support_undo_redo() + { + await Browser.GotoAsync(Content("
")); + var div = Browser.Locator("div"); + await Expect.That(div).ToHaveTextAsync(""); + await div.PressSequentiallyAsync("123"); + await Expect.That(div).ToHaveTextAsync("123"); + await Browser.Keyboard.PressAsync("ControlOrMeta+KeyZ"); + await Expect.That(div).ToHaveTextAsync(""); + await Browser.Keyboard.PressAsync("Shift+ControlOrMeta+KeyZ"); + await Expect.That(div).ToHaveTextAsync("123"); + } + + /// A page with a shadow-element whose shadow root holds , for the typing-in-shadow-dom tests. + private static string ShadowElementPage(string editors) => $$""" + + + + + + + """; + + [Test] + public async Task Should_type_repeatedly_in_contenteditable_in_shadow_dom() + { + await Browser.GotoAsync(Content(ShadowElementPage(""" +
+
+
+
+
+ """))); + + var editor = Browser.Locator("shadow-element > .editor").First(); + await editor.PressSequentiallyAsync("This is the first box."); + + var sectionEditor = Browser.Locator("section .editor"); + await sectionEditor.PressSequentiallyAsync("This is the second box."); + + Assert.That(await editor.TextContentAsync(), Is.EqualTo("This is the first box.")); + Assert.That(await sectionEditor.TextContentAsync(), Is.EqualTo("This is the second box.")); + } + + [Test] + public async Task Should_type_repeatedly_in_contenteditable_in_shadow_dom_with_nested_elements() + { + await Browser.GotoAsync(Content(ShadowElementPage(""" +

hello

+
+
+

world

+
+ """))); + + var editor = Browser.Locator("shadow-element > .editor").First(); + await editor.PressSequentiallyAsync("This is the first box: "); + + var sectionEditor = Browser.Locator("section .editor"); + await sectionEditor.PressSequentiallyAsync("This is the second box: "); + + Assert.That(await editor.TextContentAsync(), Is.EqualTo("This is the first box: hello")); + Assert.That(await sectionEditor.TextContentAsync(), Is.EqualTo("This is the second box: world")); + } + + [Test] + public async Task Should_type_repeatedly_in_input_in_shadow_dom() + { + await Browser.GotoAsync(Content(ShadowElementPage(""" + +
+
+ +
+ """))); + + var editor = Browser.Locator("shadow-element > .editor").First(); + await editor.PressSequentiallyAsync("This is the first box."); + + var sectionEditor = Browser.Locator("section .editor"); + await sectionEditor.PressSequentiallyAsync("This is the second box."); + + Assert.That(await editor.InputValueAsync(), Is.EqualTo("This is the first box.")); + Assert.That(await sectionEditor.InputValueAsync(), Is.EqualTo("This is the second box.")); + } + + [Test] + public async Task Type_to_non_focusable_element_should_maintain_old_focus() + { + await Browser.GotoAsync(Content(""" +
focusable div
+
non-editable, non-focusable
+ """)); + + await Browser.Locator("#focusable").FocusAsync(); + Assert.That(await Browser.EvaluateAsync("() => document.activeElement?.id"), Is.EqualTo("focusable")); + await Browser.Locator("#non-focusable-and-non-editable").PressSequentiallyAsync("foo"); + Assert.That(await Browser.EvaluateAsync("() => document.activeElement?.id"), Is.EqualTo("focusable")); + } + + [Test] + public async Task Should_have_correct_Keydown_Keyup_order_when_pressing_Escape_key() + { + await Browser.GotoAsync("/input/keyboard.html"); + await Browser.Keyboard.PressAsync("Escape"); + Assert.That(await ResultAsync(), Is.EqualTo(Lines("Keydown: Escape Escape STANDARD []", "Keyup: Escape Escape STANDARD []"))); + } + + [Test] + public async Task Should_close_dialog_on_Escape_key_press_in_contenteditable() + { + await Browser.GotoAsync(Content(""" + +
Edit Me
+
+ """)); + var widget = Browser.Locator("dialog [contenteditable]"); + await Browser.EvaluateAsync("() => document.querySelector('dialog').showModal()"); + await Expect.Poll(() => Browser.EvaluateAsync("() => document.querySelector('dialog').open")).ToBeAsync(true); + await Expect.That(widget).ToBeVisibleAsync(); + + await widget.PressAsync("Escape"); + await Expect.Poll(() => Browser.EvaluateAsync("() => document.querySelector('dialog').open")).ToBeAsync(false); + await Expect.That(widget).Not.ToBeVisibleAsync(); + } + + private sealed record LastKeydown(string Key, string Code, bool MetaKey); +} diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/keyboard.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/keyboard.html new file mode 100644 index 000000000..049ed439b --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/keyboard.html @@ -0,0 +1,51 @@ + + + + Keyboard test + + + + + + \ No newline at end of file diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/mouse-helper.js b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/mouse-helper.js new file mode 100644 index 000000000..3c4d57033 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/mouse-helper.js @@ -0,0 +1,62 @@ +// This injects a box into the page that moves with the mouse; +// Useful for debugging +(function(){ + const box = document.createElement('div'); + box.classList.add('mouse-helper'); + const styleElement = document.createElement('style'); + styleElement.innerHTML = ` + .mouse-helper { + pointer-events: none; + position: absolute; + top: 0; + left: 0; + width: 20px; + height: 20px; + background: rgba(0,0,0,.4); + border: 1px solid white; + border-radius: 10px; + margin-left: -10px; + margin-top: -10px; + transition: background .2s, border-radius .2s, border-color .2s; + } + .mouse-helper.button-1 { + transition: none; + background: rgba(0,0,0,0.9); + } + .mouse-helper.button-2 { + transition: none; + border-color: rgba(0,0,255,0.9); + } + .mouse-helper.button-3 { + transition: none; + border-radius: 4px; + } + .mouse-helper.button-4 { + transition: none; + border-color: rgba(255,0,0,0.9); + } + .mouse-helper.button-5 { + transition: none; + border-color: rgba(0,255,0,0.9); + } + `; + document.head.appendChild(styleElement); + document.body.appendChild(box); + document.addEventListener('mousemove', event => { + box.style.left = event.pageX + 'px'; + box.style.top = event.pageY + 'px'; + updateButtons(event.buttons); + }, true); + document.addEventListener('mousedown', event => { + updateButtons(event.buttons); + box.classList.add('button-' + event.which); + }, true); + document.addEventListener('mouseup', event => { + updateButtons(event.buttons); + box.classList.remove('button-' + event.which); + }, true); + function updateButtons(buttons) { + for (let i = 0; i < 5; i++) + box.classList.toggle('button-' + i, buttons & (1 << i)); + } +})(); diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/scrollable.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/scrollable.html new file mode 100644 index 000000000..885d3739d --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/scrollable.html @@ -0,0 +1,23 @@ + + + + Scrollable test + + + + + + \ No newline at end of file diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/textarea.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/textarea.html new file mode 100644 index 000000000..11da79882 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/input/textarea.html @@ -0,0 +1,20 @@ + + + + Textarea test + + + + +
+
Plain div
+ + + + \ No newline at end of file From 8519fbd03ed9855066318a0e0132581a6c55744e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:19:36 -0300 Subject: [PATCH 8/9] Drop the unused Asset helper (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.NUnit.Tests/Helpers/Helpers.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs index 3626c5ec8..6a77154bc 100644 --- a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs +++ b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs @@ -18,9 +18,6 @@ internal static class Helpers /// Another origin on the same app, Playwright's server.CROSS_PROCESS_PREFIX. public static string CROSS => PREFIX.Replace("127.0.0.1", "localhost", StringComparison.Ordinal); - /// The absolute path of one of Playwright's test assets. - public static string Asset(string name) => Path.Combine(AppContext.BaseDirectory, "Testbed", "playwright", "assets", name); - /// A path that serves as a page, for Playwright's page.setContent(html). public static string Content(string html) => "/content?html=" + Convert.ToBase64String(Encoding.UTF8.GetBytes(html)).TrimEnd('=').Replace('+', '-').Replace('/', '_'); From 8fe7f84d2b2d8bc3fe0cb858354e847bbd26db19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:34:15 -0300 Subject: [PATCH 9/9] Remove the known-difference marker of the selectors-text test: #1062 is fixed on main (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- COMPATIBILITY.md | 2 +- .../SelectorsText/SelectorsTextTests.cs | 40 +++++++++---------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 78f4225bd..d5038a4d4 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -162,7 +162,7 @@ Differences: - Upstream's docs site pages that have no counterpart in the port: the page objects page (`docs/page-objects.mdx`, moved to `/page-object-model` in `d30114a`), `e2e feedback` and the `docs/reference/cli.mdx` text about its opt-out variables (`4c1e2e8`), and `examples/` with its registry (`b3ae3a4`, `38b802d`, `a29edcb`, `b54646f`). The migration guides (`docs/migrate/*.mdx`, `8537abc`) are ported: see [Migration guides](#migration-guides). The docs site has .NET-only guides for upstream's five example apps of `caf51eb` (tester-army/e2e#1497: i18n, file upload, location, biometrics, deep links), under [Examples](docs-site/src/content/docs/examples/index.mdx). They are not ports: that commit only adds registry entries that link to separate repositories, so there was no guide text. Each page writes C# tests for the upstream app. The self-healing deep dive (`6fa99ea`) is ported as the [Self-healing tests](README.md#self-healing-tests) section of the guide, since the port has no docs pages for the cache, the trace page, or executors to link to. Known gap: only `e2e explore` prints a run summary, since it is the one command that feeds a run to `ListReporter` (see [List reporter](#list-reporter)): the `Cache 4 replayed · 1 handed off · 1 missed` row is `Format.CacheText` over `Format.StepsCacheTally` (`E2E.Cli`, upstream's `cacheText` and `stepsCacheTally` of `report/format.ts`), which an exploration, with its cache off, never fills, and a test run does not print ([#799](https://github.com/hardkoded/e2e-dotnet/issues/799)) - Parallel workers and serial suites - `test.fail` and the `fail` test option (tester-army/e2e#1539, `732ea8a`): a test expected to fail, whose product failure passes and whose pass fails with `UNEXPECTED_PASS`. It lives in upstream's test registry, scheduler, retry, and reporters (`settleExpectedFailure` runs on a finished attempt), and the port has none of them. NUnit and xUnit v3 own the verdict and the retries, and neither has an expected-failure outcome, so a port would need a new public API of its own -- Playwright's page tests in the testbed suite (tester-army/e2e#1505, `bdf769b`) are ported in slices (hardkoded/e2e-dotnet#1060), as the `playwright` category of `tests/E2E.NUnit.Tests`, against the playground's `/content` route and Playwright's test assets (Apache-2.0, `Testbed/playwright/`, with Playwright's `LICENSE` and `NOTICE`). A test upstream marks `{ fail: 'reason' }` keeps its assertions inside the test-only `Helpers.ExpectedToFailAsync`, which passes while the body fails and fails once it passes. Ported so far: `check`, `wait-for-url`, `locator-list`, `selectors-text` (one test is such a known difference, hardkoded/e2e-dotnet#1062), `fill`, `select-option`, `set-input-files`, and `filechooser`. Upstream's `select-option` test marked `fail` (a bare string selects by label only) passes in the port, which matches a value or a label, so it has no marker. A missing file reports .NET's `Could not find file`, where upstream shows Node's `ENOENT`. +- Playwright's page tests in the testbed suite (tester-army/e2e#1505, `bdf769b`) are ported in slices (hardkoded/e2e-dotnet#1060), as the `playwright` category of `tests/E2E.NUnit.Tests`, against the playground's `/content` route and Playwright's test assets (Apache-2.0, `Testbed/playwright/`, with Playwright's `LICENSE` and `NOTICE`). A test upstream marks `{ fail: 'reason' }` keeps its assertions inside the test-only `Helpers.ExpectedToFailAsync`, which passes while the body fails and fails once it passes. Ported so far: `check`, `wait-for-url`, `locator-list`, `selectors-text`, `fill`, `select-option`, `set-input-files`, and `filechooser`. Upstream's `select-option` test marked `fail` (a bare string selects by label only) passes in the port, which matches a value or a label, so it has no marker. A missing file reports .NET's `Could not find file`, where upstream shows Node's `ENOENT`. - Serial groups (upstream tester-army/e2e#1056, #1470): serial runs, group retries, and skipping the rest of a group after a failure belong to the test runner, which is NUnit or xUnit here, so the port keeps no serial groups. The schema has `serialAttempt.cutRetry` and the serial verdict is read from it, but nothing in the port writes a serial attempt: see [Report document](#report-document) - The out-of-process engine protocol (upstream tester-army/e2e#1232, [#873](https://github.com/hardkoded/e2e-dotnet/issues/873)): the port has no runner and no worker pool, so there is no engine process to talk to. An engine is written in .NET against `IEngine` - Diff-only observations for a custom executor's own model turns. The built-in agent has them (#1022): `#id` lines on the opening screen and on `observe`, and a diff after each action (see [MCP server](#mcp-server) for the presenter). `ExecutorObservation.Text`, which an executor reads from `Observe`, keeps the full `[ref=…]` snapshot, cut at the observation byte budget (see [Agents](#agents)), and a node is addressed by its ref there (`new ExecutorTarget("e12")`), so a custom executor has no presenter of its own. Upstream gives every executor the `#id` view. diff --git a/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs b/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs index c14218e4a..8fbc083f2 100644 --- a/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs +++ b/tests/E2E.NUnit.Tests/SelectorsText/SelectorsTextTests.cs @@ -26,32 +26,28 @@ await Browser.GotoAsync(Content(""" Assert.That(await Screen.GetByText("hello world").GetAttributeAsync("id"), Is.EqualTo("me")); } - // Known difference, hardkoded/e2e-dotnet#1062: the first getByText('hello') match has no `id`. [Test] public async Task HasText_and_internal_text_should_match_full_node_text_in_strict_mode() { - await ExpectedToFailAsync("Expected span1", async () => - { - await Browser.GotoAsync(Content(""" -
helloworld
-
hello
- """)); - await Expect.That(Screen.GetByText("helloworld")).ToHaveAttributeAsync("id", "div1"); - await Expect.That(Screen.GetByText("hello")).ToHaveAttributeAsync("id", "div2"); - await Expect.That(Browser.Locator("div").Filter(hasText: HelloWorld())).ToHaveAttributeAsync("id", "div1"); - await Expect.That(Browser.Locator("div").Filter(hasText: Hello())).ToHaveAttributeAsync("id", "div2"); + await Browser.GotoAsync(Content(""" +
helloworld
+
hello
+ """)); + await Expect.That(Screen.GetByText("helloworld")).ToHaveAttributeAsync("id", "div1"); + await Expect.That(Screen.GetByText("hello")).ToHaveAttributeAsync("id", "div2"); + await Expect.That(Browser.Locator("div").Filter(hasText: HelloWorld())).ToHaveAttributeAsync("id", "div1"); + await Expect.That(Browser.Locator("div").Filter(hasText: Hello())).ToHaveAttributeAsync("id", "div2"); - await Browser.GotoAsync(Content(""" -
helloworld
-
hello
- """)); - await Expect.That(Screen.GetByText("helloworld")).ToHaveAttributeAsync("id", "div1"); - Equal("span1", await Screen.GetByText("hello").Nth(0).GetAttributeAsync("id")); - Equal("span2", await Screen.GetByText("hello").Nth(1).GetAttributeAsync("id")); - await Expect.That(Screen.GetByText("hello")).ToHaveCountAsync(2); - await Expect.That(Browser.Locator("div").Filter(hasText: HelloWorld())).ToHaveAttributeAsync("id", "div1"); - await Expect.That(Browser.Locator("div").Filter(hasText: Hello())).ToHaveAttributeAsync("id", "div2"); - }); + await Browser.GotoAsync(Content(""" +
helloworld
+
hello
+ """)); + await Expect.That(Screen.GetByText("helloworld")).ToHaveAttributeAsync("id", "div1"); + Assert.That(await Screen.GetByText("hello").Nth(0).GetAttributeAsync("id"), Is.EqualTo("span1")); + Assert.That(await Screen.GetByText("hello").Nth(1).GetAttributeAsync("id"), Is.EqualTo("span2")); + await Expect.That(Screen.GetByText("hello")).ToHaveCountAsync(2); + await Expect.That(Browser.Locator("div").Filter(hasText: HelloWorld())).ToHaveAttributeAsync("id", "div1"); + await Expect.That(Browser.Locator("div").Filter(hasText: Hello())).ToHaveAttributeAsync("id", "div2"); } [GeneratedRegex(@"^helloworld$")]