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 3fe8034dc7463e17eee5e0548c05500ec0444a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 18:58:51 -0300 Subject: [PATCH 3/9] Port Playwright's locator-frame, selectors-frame, frame-goto and frame-hierarchy tests (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.Agent.Tests/PlaywrightRoutes.cs | 10 +- tests/E2E.Agent.Tests/Testbed.cs | 18 +- .../FrameGoto/FrameGotoTests.cs | 42 +++ .../FrameHierarchy/FrameHierarchyTests.cs | 54 ++++ tests/E2E.NUnit.Tests/Helpers/Helpers.cs | 5 +- .../LocatorFrame/LocatorFrameTests.cs | 290 ++++++++++++++++++ .../SelectorsFrame/SelectorsFrameTests.cs | 176 +++++++++++ .../assets/frames/child-redirect.html | 1 + .../playwright/assets/frames/frame.html | 19 ++ .../assets/frames/nested-frames.html | 30 ++ .../playwright/assets/frames/one-frame.html | 1 + .../assets/frames/redirect-my-parent.html | 3 + .../playwright/assets/frames/script.js | 1 + .../playwright/assets/frames/style.css | 3 + .../playwright/assets/frames/two-frames.html | 16 + .../Testbed/playwright/assets/shadow.html | 17 + 16 files changed, 683 insertions(+), 3 deletions(-) create mode 100644 tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs create mode 100644 tests/E2E.NUnit.Tests/FrameHierarchy/FrameHierarchyTests.cs create mode 100644 tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs create mode 100644 tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/child-redirect.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/frame.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/nested-frames.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/one-frame.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/redirect-my-parent.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/script.js create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/style.css create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/two-frames.html create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/shadow.html diff --git a/tests/E2E.Agent.Tests/PlaywrightRoutes.cs b/tests/E2E.Agent.Tests/PlaywrightRoutes.cs index c27600fb8..649920b44 100644 --- a/tests/E2E.Agent.Tests/PlaywrightRoutes.cs +++ b/tests/E2E.Agent.Tests/PlaywrightRoutes.cs @@ -11,7 +11,7 @@ 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. +/// The playground serves them for any path it has no page for. This port has /content, /never and the assets so far. /// internal static class PlaywrightRoutes { @@ -42,6 +42,14 @@ public static async Task HandleAsync(HttpListenerContext context) return; } + if (path == "/never") + { + // Holds the response and never answers, as upstream's /never; ends after upstream's longest delay so the task does not outlive the run. + await Task.Delay(TimeSpan.FromSeconds(30)).ConfigureAwait(false); + response.Abort(); + return; + } + var file = Path.GetFullPath(Path.Combine(Root, Uri.UnescapeDataString(path).TrimStart('/'))); if (!file.StartsWith(Root + Path.DirectorySeparatorChar, StringComparison.Ordinal) || !File.Exists(file)) { diff --git a/tests/E2E.Agent.Tests/Testbed.cs b/tests/E2E.Agent.Tests/Testbed.cs index d2a2336cf..9f66f7719 100644 --- a/tests/E2E.Agent.Tests/Testbed.cs +++ b/tests/E2E.Agent.Tests/Testbed.cs @@ -1014,7 +1014,23 @@ await WriteHtmlAsync(response, "Dashboard", """ } else { - await PlaywrightRoutes.HandleAsync(context).ConfigureAwait(false); + // Its own task: a route that holds its response (upstream's /never) must not stall the other requests. + _ = Task.Run(async () => + { + try + { + await PlaywrightRoutes.HandleAsync(context).ConfigureAwait(false); + } + catch (Exception ex) when (ex is HttpListenerException or InvalidOperationException or IOException) + { + // The client went away. + } + finally + { + response.Close(); + } + }); + continue; } response.Close(); diff --git a/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs b/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs new file mode 100644 index 000000000..bdfe10672 --- /dev/null +++ b/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs @@ -0,0 +1,42 @@ +// 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.FrameGoto; + +/// +/// test.describe('frame goto') of upstream's apps/testbed/tests/frame-goto.e2e.ts (Playwright's +/// frame-goto.spec.ts). The stalled /frames/script.js is a route that sends the request to /never. Not ported, +/// as upstream: should navigate subframes, should reject when frame detaches, should return matching responses (no +/// frame.goto and no Frame objects). +/// +public sealed class FrameGotoTests : PlaywrightTest +{ + // Known difference, hardkoded/e2e-dotnet#1068: the timeout message has no `timed out in browser.goto` label. + [Test] + public async Task Should_continue_after_client_redirect() + { + await ExpectedToFailAsync("exceeded", async () => + { + await Browser.RouteAsync("**/frames/script.js", route => route.ContinueAsync(new RouteContinueOverrides { Url = $"{PREFIX}/never" })); + var url = $"{PREFIX}/frames/child-redirect.html"; + Exception? error = null; + try + { + await Browser.GotoAsync(url, new GotoOptions { Timeout = TimeSpan.FromSeconds(5), WaitUntil = GotoWaitUntil.NetworkIdle }); + } + catch (Exception ex) when (ex is not OperationCanceledException) + { + error = ex; + } + + if (error is null || !error.Message.Contains("timed out in browser.goto", StringComparison.Ordinal)) + { + throw new InvalidOperationException("Expected a message with 'timed out in browser.goto', but was: " + (error?.Message ?? "no error")); + } + }); + } +} diff --git a/tests/E2E.NUnit.Tests/FrameHierarchy/FrameHierarchyTests.cs b/tests/E2E.NUnit.Tests/FrameHierarchy/FrameHierarchyTests.cs new file mode 100644 index 000000000..47bff7099 --- /dev/null +++ b/tests/E2E.NUnit.Tests/FrameHierarchy/FrameHierarchyTests.cs @@ -0,0 +1,54 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.FrameHierarchy; + +/// +/// test.describe('frame hierarchy') of upstream's apps/testbed/tests/frame-hierarchy.e2e.ts (Playwright's +/// frame-hierarchy.spec.ts). A frame the original finds in page.frames() is reached through FrameLocator. Not +/// ported, as upstream: should send events when frames are manipulated dynamically, should persist mainFrame on cross-process +/// navigation, should not send attach/detach events for main frame, should detach child frames on navigation, should support +/// framesets, should report frame.name(), should report frame.parent(), should report different frame instance when frame +/// re-attaches, should refuse to display x-frame-options:deny iframe, should return frame.page() (frame events, Frame objects, +/// console events). +/// +public sealed class FrameHierarchyTests : PlaywrightTest +{ + [Test] + public async Task Should_handle_nested_frames() + { + await Browser.GotoAsync("/frames/nested-frames.html"); + await Expect.That(Browser.FrameLocator("[name=aframe]").Locator("div")).ToHaveTextAsync("Hi, I'm frame"); + await Expect.That(Browser.FrameLocator("[name=\"2frames\"]").FrameLocator("[name=dos]").Locator("div")).ToHaveTextAsync("Hi, I'm frame"); + await Expect.That(Browser.FrameLocator("[name=\"2frames\"]").FrameLocator("[name=uno]").Locator("div")).ToHaveTextAsync("Hi, I'm frame"); + await Expect.That(Browser.FrameLocator("[name=\"2frames\"]").Locator("iframe")).ToHaveCountAsync(2); + await Expect.That(Browser.Locator("iframe")).ToHaveCountAsync(2); + } + + [Test] + public async Task Should_send_framenavigated_when_navigating_on_anchor_URLs() + { + await Browser.GotoAsync("/empty.html"); + await Browser.GotoAsync("/empty.html#foo"); + Assert.That(await Browser.UrlAsync(), Is.EqualTo($"{PREFIX}/empty.html#foo")); + } + + [Test] + public async Task Should_report_frame_from_inside_shadow_DOM() + { + await Browser.GotoAsync("/shadow.html"); + await Browser.EvaluateAsync(""" + async (url) => { + const frame = document.createElement('iframe'); + frame.src = url; + document.body.shadowRoot.appendChild(frame); + await new Promise((x) => (frame.onload = x)); + } + """, $"{PREFIX}/empty.html"); + await Expect.That(Browser.Locator("iframe")).ToHaveCountAsync(1); + await Expect.That(Browser.FrameLocator("iframe").Locator("body")).ToHaveCountAsync(1); + } +} diff --git a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs index da38a9b5c..85eec1b88 100644 --- a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs +++ b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs @@ -8,13 +8,16 @@ 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). +/// content, PREFIX and CROSS. 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; + /// Another origin on the same app, Playwright's server.CROSS_PROCESS_PREFIX (localhost on the app's port). + public static string CROSS => new UriBuilder(PREFIX) { Host = "localhost" }.Uri.GetLeftPart(UriPartial.Authority); + /// 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/LocatorFrame/LocatorFrameTests.cs b/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs new file mode 100644 index 000000000..3983e72cf --- /dev/null +++ b/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs @@ -0,0 +1,290 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.LocatorFrame; + +/// +/// test.describe('locator frame') of upstream's apps/testbed/tests/locator-frame.e2e.ts (Playwright's +/// locator-frame.spec.ts). Not ported, as upstream: should wait for frame (no locator.frameLocator), should non work +/// for non-frame (Playwright's error text), locator.frameLocator should work for iframe, locator.frameLocator should throw on +/// ambiguity, locator.frameLocator should not throw on first/last/nth, should work with COEP/COOP/CORP isolated iframe, +/// locator.contentFrame should work, frameLocator.owner should work. The getBy coverage test keeps the role, text, test id, label and +/// placeholder queries (no getByAltText or getByTitle). +/// +public sealed class LocatorFrameTests : PlaywrightTest +{ + + private static readonly string Nested = Content(""); + + private static readonly string Iframe = Content($""" + +
+ + +
+ 1 + 2 + + + """); + + private static readonly string Routed = Content($""""""); + + [Test] + public async Task Should_work_for_iframe() + { + await Browser.GotoAsync(Routed); + var button = Browser.FrameLocator("iframe").Locator("button"); + await button.WaitForAsync(); + Assert.That(await button.TextContentAsync(), Is.EqualTo("Hello iframe")); + await Expect.That(button).ToHaveTextAsync("Hello iframe"); + await button.TapAsync(); + } + + [Test] + public async Task Should_work_for_nested_iframe() + { + await Browser.GotoAsync(Routed); + var button = Browser.FrameLocator("iframe").FrameLocator("iframe").Locator("button"); + await button.WaitForAsync(); + Assert.That(await button.TextContentAsync(), Is.EqualTo("Hello nested iframe")); + await Expect.That(button).ToHaveTextAsync("Hello nested iframe"); + await button.TapAsync(); + } + + [Test] + public async Task Should_work_for_Dollar_and_DollarDollar() + { + await Browser.GotoAsync(Routed); + var locator = Browser.FrameLocator("iframe").Locator("button"); + await Expect.That(locator).ToHaveTextAsync("Hello iframe"); + var spans = Browser.FrameLocator("iframe").Locator("span"); + await Expect.That(spans).ToHaveCountAsync(2); + } + + [Test] + public async Task Should_wait_for_frame_2() + { + await Browser.GotoAsync("about:blank"); + var navigated = After(300, () => Browser.GotoAsync(Routed)); + await Browser.FrameLocator("iframe").Locator("button").TapAsync(); + await navigated; + } + + [Test] + public async Task Should_wait_for_frame_to_go() + { + await Browser.GotoAsync(Routed); + var removed = After(300, () => Browser.EvaluateAsync("() => { document.querySelector('iframe').remove(); }")); + await Expect.That(Browser.FrameLocator("iframe").Locator("button")).ToBeHiddenAsync(); + await removed; + } + + [Test] + public async Task Should_not_wait_for_frame() + { + await Browser.GotoAsync("/empty.html"); + await Expect.That(Browser.FrameLocator("iframe").Locator("span")).ToBeHiddenAsync(); + } + + [Test] + public async Task Should_not_wait_for_frame_2() + { + await Browser.GotoAsync("/empty.html"); + await Expect.That(Browser.FrameLocator("iframe").Locator("span")).ToBeVisibleAsync(false); + } + + [Test] + public async Task Should_not_wait_for_frame_3() + { + await Browser.GotoAsync("/empty.html"); + await Expect.That(Browser.FrameLocator("iframe").Locator("span")).ToHaveCountAsync(0); + } + + [Test] + public async Task Should_click_in_lazy_iframe() + { + var lazy = Content(""); + await Browser.GotoAsync("/empty.html"); + var attached = After(500, async () => + { + await Browser.EvaluateAsync("() => { document.body.appendChild(document.createElement('iframe')); }"); + await Task.Delay(500); + await Browser.EvaluateAsync("(src) => { document.querySelector('iframe').src = src; }", lazy); + }); + var button = Browser.FrameLocator("iframe").Locator("button"); + var tap = button.TapAsync(); + var text = button.TextContentAsync(); + var hasText = Expect.That(button).ToHaveTextAsync("Hello iframe"); + await Task.WhenAll(tap, text, hasText, attached); + Assert.That(await text, Is.EqualTo("Hello iframe")); + } + + [Test] + public async Task WaitFor_should_survive_frame_reattach() + { + await Browser.GotoAsync(Routed); + var button = Browser.FrameLocator("iframe").Locator("button").Filter(hasText: "Hello nested iframe"); + var promise = button.WaitForAsync(); + await Browser.EvaluateAsync("() => { document.querySelector('iframe').remove(); }"); + await Browser.EvaluateAsync("(src) => { const iframe = document.createElement('iframe'); iframe.src = src; document.body.appendChild(iframe); }", Nested); + await promise; + } + + [Test] + public async Task Click_should_survive_frame_reattach() + { + await Browser.GotoAsync(Routed); + var button = Browser.FrameLocator("iframe").Locator("button").Filter(hasText: "Hello nested iframe"); + var promise = button.TapAsync(); + await Browser.EvaluateAsync("() => { document.querySelector('iframe').remove(); }"); + await Browser.EvaluateAsync("(src) => { const iframe = document.createElement('iframe'); iframe.src = src; document.body.appendChild(iframe); }", Nested); + await promise; + } + + [Test] + public async Task Click_should_survive_iframe_navigation() + { + await Browser.GotoAsync(Routed); + var button = Browser.FrameLocator("iframe").Locator("button").Filter(hasText: "Hello nested iframe"); + var promise = button.TapAsync(); + var navigated = Browser.EvaluateAsync("(src) => { document.querySelector('iframe').src = src; }", Nested); + await promise; + await navigated; + } + + // Known difference, hardkoded/e2e-dotnet#1066: a frame-scoped getByRole also matches the nested frame's button. + [Test] + public async Task GetBy_coverage_role_text_test_id_label_placeholder() + { + await ExpectedToFailAsync("observed matched 2 nodes", async () => + { + await Browser.GotoAsync(Routed); + var button1 = Browser.FrameLocator("iframe").GetByRole("button"); + var button2 = Browser.FrameLocator("iframe").GetByText("Hello", exact: false); + var button3 = Browser.FrameLocator("iframe").GetByTestId("buttonId"); + await Expect.That(button1).ToHaveTextAsync("Hello iframe"); + await Expect.That(button2).ToHaveTextAsync("Hello iframe"); + await Expect.That(button3).ToHaveTextAsync("Hello iframe"); + var input1 = Browser.FrameLocator("iframe").GetByLabel("Name"); + await Expect.That(input1).ToHaveValueAsync(""); + var input2 = Browser.FrameLocator("iframe").GetByPlaceholder("Placeholder"); + await Expect.That(input2).ToHaveValueAsync(""); + }); + } + + [Test] + public async Task Wait_for_hidden_should_succeed_when_frame_is_not_in_dom() + { + await Browser.GotoAsync("about:blank"); + var button = Browser.FrameLocator("iframe1").Locator("button"); + Assert.That(await button.IsHiddenAsync(), Is.True); + await button.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Hidden, Timeout = TimeSpan.FromSeconds(1) }); + await button.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Detached, Timeout = TimeSpan.FromSeconds(1) }); + var error = await Assert.CatchAsync(() => button.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Attached, Timeout = TimeSpan.FromSeconds(1) })); + Assert.That(error, Is.Not.Null); + } + + // Known difference, hardkoded/e2e-dotnet#1067: an element inside a `visibility: hidden` iframe is not found, instead of hidden. + [Test] + public async Task Should_treat_elements_inside_hidden_iframe_as_hidden() + { + await ExpectedToFailAsync("observed no node", async () => + { + await Browser.GotoAsync(Content(""" + +
+ + +
+ + """)); + + foreach (var button in new[] + { + Browser.FrameLocator("[name=hidden]").Locator("button"), + Browser.FrameLocator("[name=hidden-parent]").Locator("button"), + Browser.FrameLocator("[name=outer]").FrameLocator("[name=inner]").Locator("button"), + }) + { + await Expect.That(button).ToBeAttachedAsync(); + Equal(false, await button.IsVisibleAsync()); + Equal(true, await button.IsHiddenAsync()); + await Expect.That(button).ToBeHiddenAsync(); + await Expect.That(button).ToBeVisibleAsync(false); + await button.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Hidden }); + } + + var visible = Browser.FrameLocator("[name=visible-override]").Locator("button"); + Equal(true, await visible.IsVisibleAsync()); + await Expect.That(visible).ToBeVisibleAsync(); + await visible.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Visible }); + }); + } + + [Test] + public async Task Should_wait_for_hidden_iframe_to_become_visible() + { + // Upstream marks this test `fail`; it passes in the port. + await Browser.GotoAsync(Content("""""")); + var button = Browser.FrameLocator("[name=frame]").Locator("button"); + await Expect.That(button).ToBeHiddenAsync(); + + var error = await Record(() => button.TapAsync(new ActionOptions { Timeout = TimeSpan.FromSeconds(1) })); + Assert.That(error, Is.Not.Null); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('iframe').contentWindow.__clicked === true"), Is.False); + + var clickPromise = button.TapAsync(); + var visiblePromise = Expect.That(button).ToBeVisibleAsync(); + await Browser.EvaluateAsync("() => { document.querySelector('iframe').style.visibility = 'visible'; }"); + await Task.WhenAll(clickPromise, visiblePromise); + Assert.That(await Browser.EvaluateAsync("() => document.querySelector('iframe').contentWindow.__clicked"), Is.True); + + await Browser.EvaluateAsync("() => { document.querySelector('iframe').style.visibility = 'hidden'; }"); + await Expect.That(button).ToBeHiddenAsync(); + Assert.That(await button.IsVisibleAsync(), Is.False); + } + + // Known difference, hardkoded/e2e-dotnet#1067: see above. + [Test] + public async Task Should_treat_elements_inside_hidden_cross_origin_iframe_as_hidden() + { + await ExpectedToFailAsync("is not in the observation", async () => + { + await Browser.GotoAsync("/empty.html"); + await Browser.GotoAsync(Content($"""""")); + var div = Browser.FrameLocator("iframe").Locator("div"); + await Expect.That(div).ToHaveTextAsync("Hi, I'm frame"); + Equal(false, await div.IsVisibleAsync()); + await Expect.That(div).ToBeHiddenAsync(); + + await Browser.EvaluateAsync("() => { document.querySelector('iframe').style.visibility = 'visible'; }"); + await Expect.That(div).ToBeVisibleAsync(); + Equal(true, await div.IsVisibleAsync()); + }); + } + + /// Upstream's delay(ms).then(next). + private static async Task After(int milliseconds, Func next) + { + await Task.Delay(milliseconds); + await next(); + } + + /// The error threw, or null when it did not. + private static async Task Record(Func act) + { + try + { + await act(); + return null; + } + catch (Exception ex) when (ex is not OperationCanceledException) + { + return ex; + } + } +} diff --git a/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs b/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs new file mode 100644 index 000000000..0ff141c09 --- /dev/null +++ b/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs @@ -0,0 +1,176 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using static E2E.NUnit.Tests.Helpers; + +namespace E2E.NUnit.Tests.SelectorsFrame; + +/// +/// test.describe('selectors frame') of upstream's apps/testbed/tests/selectors-frame.e2e.ts (Playwright's +/// selectors-frame.spec.ts). iframe >> internal:control=enter-frame >> x is +/// FrameLocator("iframe").Locator(x). Not ported, as upstream: the (handle) tests (element handles), $eval should throw for +/// missing frame (no $eval), should not allow dangling/leading enter-frame, should not allow capturing before enter-frame, +/// should capture after the enter-frame (Playwright selector syntax), should non work for non-frame, and the nine any-frame +/// tests (no counterpart). +/// +public sealed class SelectorsFrameTests : PlaywrightTest +{ + private static readonly string Iframe2 = Content(""); + + private static readonly string Iframe = Content($""" + +
+ + +
+ 1 + 2 + + """); + + private static readonly string Routed = Content($""""""); + + [Test] + public async Task Should_work_for_iframe() + { + await Browser.GotoAsync(Routed); + var button = Browser.FrameLocator("iframe").Locator("button"); + await button.WaitForAsync(); + Assert.That(await button.TextContentAsync(), Is.EqualTo("Hello iframe")); + await Expect.That(button).ToHaveTextAsync("Hello iframe"); + await button.TapAsync(); + } + + [Test] + public async Task Should_work_for_nested_iframe() + { + await Browser.GotoAsync(Routed); + var button = Browser.FrameLocator("iframe").FrameLocator("iframe").Locator("button"); + await button.WaitForAsync(); + Assert.That(await button.TextContentAsync(), Is.EqualTo("Hello nested iframe")); + await Expect.That(button).ToHaveTextAsync("Hello nested iframe"); + await button.TapAsync(); + } + + [Test] + public async Task Should_work_for_Dollar_and_DollarDollar() + { + await Browser.GotoAsync(Routed); + var element = Browser.FrameLocator("iframe").Locator("button"); + await element.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Attached }); + Assert.That(await element.TextContentAsync(), Is.EqualTo("Hello iframe")); + await Browser.FrameLocator("iframe").Locator("span").Nth(1).WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Attached }); + Assert.That(await Browser.FrameLocator("iframe").Locator("span").CountAsync(), Is.EqualTo(2)); + } + + [Test] + public async Task Dollar_should_not_wait_for_frame() + { + await Browser.GotoAsync("/empty.html"); + Assert.That(await Browser.FrameLocator("iframe").Locator("canvas").CountAsync(), Is.EqualTo(0)); + } + + [Test] + public async Task DollarDollar_should_not_wait_for_frame() + { + await Browser.GotoAsync("/empty.html"); + Assert.That(await Browser.FrameLocator("iframe").Locator("canvas").AllAsync(), Has.Count.EqualTo(0)); + } + + [Test] + public async Task DollarDollarEval_should_not_throw_for_missing_frame() + { + await Browser.GotoAsync("/empty.html"); + Assert.That(await Browser.FrameLocator("iframe").Locator("canvas").AllTextContentsAsync(), Has.Count.EqualTo(0)); + } + + // Known difference, hardkoded/e2e-dotnet#1066: a frame-scoped getByRole also matches the nested frame's button. + [Test] + public async Task Should_work_for_DollarEval() + { + await ExpectedToFailAsync("observed count 2", async () => + { + await Browser.GotoAsync(Routed); + await Expect.That(Browser.FrameLocator("iframe").GetByRole("button")).ToHaveCountAsync(1); + await Expect.That(Browser.FrameLocator("iframe").Locator("button")).ToHaveCountAsync(1); + }); + } + + [Test] + public async Task Should_work_for_DollarDollarEval() + { + await Browser.GotoAsync(Routed); + await Expect.That(Browser.FrameLocator("iframe").Locator("span")).ToHaveCountAsync(2); + Assert.That(await Browser.FrameLocator("iframe").Locator("span").AllTextContentsAsync(), Is.EqualTo(new[] { "1", "2" })); + } + + [Test] + public async Task Should_click_in_lazy_iframe() + { + var lazy = Content(""); + await Browser.GotoAsync("/empty.html"); + var attached = After(500, async () => + { + await Browser.EvaluateAsync("() => { document.body.appendChild(document.createElement('iframe')); }"); + await Task.Delay(500); + await Browser.EvaluateAsync("(src) => { document.querySelector('iframe').src = src; }", lazy); + }); + var button = Browser.FrameLocator("iframe").Locator("button"); + var tap = button.TapAsync(); + var text = button.TextContentAsync(); + var hasText = Expect.That(button).ToHaveTextAsync("Hello iframe"); + await Task.WhenAll(tap, text, hasText, attached); + Assert.That(await text, Is.EqualTo("Hello iframe")); + } + + [Test] + public async Task WaitFor_should_survive_frame_reattach() + { + await Browser.GotoAsync(Routed); + var button = Browser.FrameLocator("iframe").Locator("button").Filter(hasText: "Hello nested iframe"); + var promise = button.WaitForAsync(); + await Browser.EvaluateAsync("() => { document.querySelector('iframe').remove(); }"); + await Browser.EvaluateAsync("(src) => { const iframe = document.createElement('iframe'); iframe.src = src; document.body.appendChild(iframe); }", Iframe2); + await promise; + } + + [Test] + public async Task Click_should_survive_frame_reattach() + { + await Browser.GotoAsync(Routed); + var button = Browser.FrameLocator("iframe").Locator("button").Filter(hasText: "Hello nested iframe"); + var promise = button.TapAsync(); + await Browser.EvaluateAsync("() => { document.querySelector('iframe').remove(); }"); + await Browser.EvaluateAsync("(src) => { const iframe = document.createElement('iframe'); iframe.src = src; document.body.appendChild(iframe); }", Iframe2); + await promise; + } + + [Test] + public async Task Click_should_survive_iframe_navigation() + { + await Browser.GotoAsync(Routed); + var button = Browser.FrameLocator("iframe").Locator("button").Filter(hasText: "Hello nested iframe"); + var promise = button.TapAsync(); + var navigated = Browser.EvaluateAsync("(src) => { document.querySelector('iframe').src = src; }", Iframe2); + await promise; + await navigated; + } + + [Test] + public async Task Click_should_survive_navigation() + { + await Browser.GotoAsync(Iframe); + var promise = Browser.Locator("button").Filter(hasText: "Hello nested iframe").TapAsync(); + await Task.Delay(100); + await Browser.GotoAsync(Iframe2); + await promise; + } + + /// Upstream's delay(ms).then(next). + private static async Task After(int milliseconds, Func next) + { + await Task.Delay(milliseconds); + await next(); + } +} diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/child-redirect.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/child-redirect.html new file mode 100644 index 000000000..d4806e7f6 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/child-redirect.html @@ -0,0 +1 @@ + diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/frame.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/frame.html new file mode 100644 index 000000000..3d3b94343 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/frame.html @@ -0,0 +1,19 @@ + + + + + +
Hi, I'm frame
diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/nested-frames.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/nested-frames.html new file mode 100644 index 000000000..d858d3285 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/nested-frames.html @@ -0,0 +1,30 @@ + + + + diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/one-frame.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/one-frame.html new file mode 100644 index 000000000..e941d795a --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/one-frame.html @@ -0,0 +1 @@ + diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/redirect-my-parent.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/redirect-my-parent.html new file mode 100644 index 000000000..3beb0aac1 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/redirect-my-parent.html @@ -0,0 +1,3 @@ + diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/script.js b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/script.js new file mode 100644 index 000000000..be22256d1 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/script.js @@ -0,0 +1 @@ +console.log('Cheers!'); diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/style.css b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/style.css new file mode 100644 index 000000000..5b5436e87 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/style.css @@ -0,0 +1,3 @@ +div { + color: blue; +} diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/two-frames.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/two-frames.html new file mode 100644 index 000000000..00324f084 --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/frames/two-frames.html @@ -0,0 +1,16 @@ + + + diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/shadow.html b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/shadow.html new file mode 100644 index 000000000..d1fd331eb --- /dev/null +++ b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/shadow.html @@ -0,0 +1,17 @@ + From 9feb6b842eff8e020c7a9326e2f44b684dcef041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:02:09 -0300 Subject: [PATCH 4/9] Serve the testbed on localhost too and mark the two partial frame-hierarchy ports (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.Agent.Tests/Testbed.cs | 4 +++- tests/E2E.NUnit.Tests/FrameHierarchy/FrameHierarchyTests.cs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/E2E.Agent.Tests/Testbed.cs b/tests/E2E.Agent.Tests/Testbed.cs index 9f66f7719..bcdb6bae3 100644 --- a/tests/E2E.Agent.Tests/Testbed.cs +++ b/tests/E2E.Agent.Tests/Testbed.cs @@ -929,6 +929,8 @@ private static string Start() url = "http://127.0.0.1:" + port.ToString(CultureInfo.InvariantCulture) + "/"; listener = new HttpListener(); listener.Prefixes.Add(url); + // The second origin of the cross-origin cases (upstream's CROSS), the same app under another host name. + listener.Prefixes.Add("http://localhost:" + port.ToString(CultureInfo.InvariantCulture) + "/"); try { listener.Start(); @@ -1021,7 +1023,7 @@ await WriteHtmlAsync(response, "Dashboard", """ { await PlaywrightRoutes.HandleAsync(context).ConfigureAwait(false); } - catch (Exception ex) when (ex is HttpListenerException or InvalidOperationException or IOException) + catch (Exception ex) when (ex is HttpListenerException or InvalidOperationException or IOException or ObjectDisposedException) { // The client went away. } diff --git a/tests/E2E.NUnit.Tests/FrameHierarchy/FrameHierarchyTests.cs b/tests/E2E.NUnit.Tests/FrameHierarchy/FrameHierarchyTests.cs index 47bff7099..572c479e7 100644 --- a/tests/E2E.NUnit.Tests/FrameHierarchy/FrameHierarchyTests.cs +++ b/tests/E2E.NUnit.Tests/FrameHierarchy/FrameHierarchyTests.cs @@ -29,7 +29,7 @@ public async Task Should_handle_nested_frames() } [Test] - public async Task Should_send_framenavigated_when_navigating_on_anchor_URLs() + public async Task Partial_Should_send_framenavigated_when_navigating_on_anchor_URLs() { await Browser.GotoAsync("/empty.html"); await Browser.GotoAsync("/empty.html#foo"); @@ -37,7 +37,7 @@ public async Task Should_send_framenavigated_when_navigating_on_anchor_URLs() } [Test] - public async Task Should_report_frame_from_inside_shadow_DOM() + public async Task Partial_Should_report_frame_from_inside_shadow_DOM() { await Browser.GotoAsync("/shadow.html"); await Browser.EvaluateAsync(""" From c2233b20c434b731766d28307f1109348b9ee0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:17:36 -0300 Subject: [PATCH 5/9] Share the After and Record helpers and guard the held-response close (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.Agent.Tests/Testbed.cs | 9 +++++++- tests/E2E.NUnit.Tests/Helpers/Helpers.cs | 21 +++++++++++++++++++ .../LocatorFrame/LocatorFrameTests.cs | 21 ------------------- .../SelectorsFrame/SelectorsFrameTests.cs | 7 ------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/E2E.Agent.Tests/Testbed.cs b/tests/E2E.Agent.Tests/Testbed.cs index bcdb6bae3..1d9ada81d 100644 --- a/tests/E2E.Agent.Tests/Testbed.cs +++ b/tests/E2E.Agent.Tests/Testbed.cs @@ -1029,7 +1029,14 @@ await WriteHtmlAsync(response, "Dashboard", """ } finally { - response.Close(); + try + { + response.Close(); + } + catch (Exception ex) when (ex is HttpListenerException or InvalidOperationException or IOException or ObjectDisposedException) + { + // The response was aborted. + } } }); continue; diff --git a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs index 85eec1b88..654fe3b9e 100644 --- a/tests/E2E.NUnit.Tests/Helpers/Helpers.cs +++ b/tests/E2E.NUnit.Tests/Helpers/Helpers.cs @@ -15,6 +15,27 @@ 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; + /// Upstream's delay(milliseconds).then(next). + public static async Task After(int milliseconds, Func next) + { + await Task.Delay(milliseconds).ConfigureAwait(false); + await next().ConfigureAwait(false); + } + + /// The error threw, or null when it did not (upstream's failure). + public static async Task Record(Func act) + { + try + { + await act().ConfigureAwait(false); + return null; + } + catch (Exception ex) when (ex is not OperationCanceledException) + { + return ex; + } + } + /// Another origin on the same app, Playwright's server.CROSS_PROCESS_PREFIX (localhost on the app's port). public static string CROSS => new UriBuilder(PREFIX) { Host = "localhost" }.Uri.GetLeftPart(UriPartial.Authority); diff --git a/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs b/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs index 3983e72cf..f8dd176ff 100644 --- a/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs +++ b/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs @@ -266,25 +266,4 @@ await ExpectedToFailAsync("is not in the observation", async () => Equal(true, await div.IsVisibleAsync()); }); } - - /// Upstream's delay(ms).then(next). - private static async Task After(int milliseconds, Func next) - { - await Task.Delay(milliseconds); - await next(); - } - - /// The error threw, or null when it did not. - private static async Task Record(Func act) - { - try - { - await act(); - return null; - } - catch (Exception ex) when (ex is not OperationCanceledException) - { - return ex; - } - } } diff --git a/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs b/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs index 0ff141c09..818cd6281 100644 --- a/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs +++ b/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs @@ -166,11 +166,4 @@ public async Task Click_should_survive_navigation() await Browser.GotoAsync(Iframe2); await promise; } - - /// Upstream's delay(ms).then(next). - private static async Task After(int milliseconds, Func next) - { - await Task.Delay(milliseconds); - await next(); - } } From b5dfd6dfee5ea7a3ed0e19360b7dc48a0626505d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:23:44 -0300 Subject: [PATCH 6/9] Tighten the frame test assertions, skip CROSS when localhost cannot bind and release held requests at exit (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.Agent.Tests/PlaywrightRoutes.cs | 23 +++++++++++++++++-- tests/E2E.Agent.Tests/Testbed.cs | 20 ++++++++++++++-- .../FrameGoto/FrameGotoTests.cs | 2 +- .../LocatorFrame/LocatorFrameTests.cs | 9 +++++++- .../SelectorsFrame/SelectorsFrameTests.cs | 3 ++- 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/tests/E2E.Agent.Tests/PlaywrightRoutes.cs b/tests/E2E.Agent.Tests/PlaywrightRoutes.cs index 649920b44..a5393af39 100644 --- a/tests/E2E.Agent.Tests/PlaywrightRoutes.cs +++ b/tests/E2E.Agent.Tests/PlaywrightRoutes.cs @@ -17,6 +17,9 @@ internal static class PlaywrightRoutes { private static readonly string Root = Path.Combine(AppContext.BaseDirectory, "Testbed", "playwright", "assets"); + /// Cancelled when the process exits, which releases the requests a route holds. + private static readonly CancellationTokenSource Shutdown = CreateShutdown(); + private static readonly Dictionary Types = new(StringComparer.Ordinal) { [".html"] = "text/html", @@ -44,8 +47,17 @@ public static async Task HandleAsync(HttpListenerContext context) if (path == "/never") { - // Holds the response and never answers, as upstream's /never; ends after upstream's longest delay so the task does not outlive the run. - await Task.Delay(TimeSpan.FromSeconds(30)).ConfigureAwait(false); + // Holds the response and never answers, as upstream's /never. It ends when the run ends (the testbed never stops before that) + // or after upstream's longest delay, so a held request cannot outlive the run. + try + { + await Task.Delay(TimeSpan.FromSeconds(30), Shutdown.Token).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + // The run is ending. + } + response.Abort(); return; } @@ -64,6 +76,13 @@ public static async Task HandleAsync(HttpListenerContext context) await WriteAsync(response, await File.ReadAllBytesAsync(file).ConfigureAwait(false)).ConfigureAwait(false); } + private static CancellationTokenSource CreateShutdown() + { + var source = new CancellationTokenSource(); + AppDomain.CurrentDomain.ProcessExit += (_, _) => source.Cancel(); + return source; + } + 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 1d9ada81d..7cf7413f1 100644 --- a/tests/E2E.Agent.Tests/Testbed.cs +++ b/tests/E2E.Agent.Tests/Testbed.cs @@ -915,6 +915,9 @@ function submitForm() { /// The base URL of the running playground, started on first use. public static string Url => Server.Value; + /// Whether the app also answers on localhost, the second origin of the cross-origin cases. Read after . + public static bool CrossOriginAvailable { get; private set; } + private static string Start() { // HttpListener cannot bind port 0: take a free port, and try again when another test takes it first. @@ -934,6 +937,21 @@ private static string Start() try { listener.Start(); + CrossOriginAvailable = true; + break; + } + catch (HttpListenerException) + { + listener.Close(); + } + + // A host that cannot bind localhost (no mapping, no URL ACL) still serves the app; the cross-origin tests skip themselves. + listener = new HttpListener(); + listener.Prefixes.Add(url); + try + { + listener.Start(); + CrossOriginAvailable = false; break; } catch (HttpListenerException) @@ -943,8 +961,6 @@ private static string Start() { throw; } - - continue; } } diff --git a/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs b/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs index bdfe10672..d5105eb18 100644 --- a/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs +++ b/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs @@ -19,7 +19,7 @@ public sealed class FrameGotoTests : PlaywrightTest [Test] public async Task Should_continue_after_client_redirect() { - await ExpectedToFailAsync("exceeded", async () => + await ExpectedToFailAsync("child-redirect.html: Timeout", async () => { await Browser.RouteAsync("**/frames/script.js", route => route.ContinueAsync(new RouteContinueOverrides { Url = $"{PREFIX}/never" })); var url = $"{PREFIX}/frames/child-redirect.html"; diff --git a/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs b/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs index f8dd176ff..f465f6c04 100644 --- a/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs +++ b/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs @@ -185,7 +185,8 @@ public async Task Wait_for_hidden_should_succeed_when_frame_is_not_in_dom() await button.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Hidden, Timeout = TimeSpan.FromSeconds(1) }); await button.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Detached, Timeout = TimeSpan.FromSeconds(1) }); var error = await Assert.CatchAsync(() => button.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Attached, Timeout = TimeSpan.FromSeconds(1) })); - Assert.That(error, Is.Not.Null); + // Upstream only expects the error to be defined; the port's message names the missing frame. + Assert.That(error!.Message, Does.Contain("no frame matches iframe1")); } // Known difference, hardkoded/e2e-dotnet#1067: an element inside a `visibility: hidden` iframe is not found, instead of hidden. @@ -252,6 +253,12 @@ public async Task Should_wait_for_hidden_iframe_to_become_visible() [Test] public async Task Should_treat_elements_inside_hidden_cross_origin_iframe_as_hidden() { + _ = PREFIX; + if (!E2E.Playground.Testbed.CrossOriginAvailable) + { + Assert.Ignore("The testbed could not bind localhost, the second origin of this test (CROSS)."); + } + await ExpectedToFailAsync("is not in the observation", async () => { await Browser.GotoAsync("/empty.html"); diff --git a/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs b/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs index 818cd6281..6e468c92f 100644 --- a/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs +++ b/tests/E2E.NUnit.Tests/SelectorsFrame/SelectorsFrameTests.cs @@ -162,7 +162,8 @@ public async Task Click_should_survive_navigation() { await Browser.GotoAsync(Iframe); var promise = Browser.Locator("button").Filter(hasText: "Hello nested iframe").TapAsync(); - await Task.Delay(100); + // Upstream waits 100 ms; the page being loaded and the tap polling for a button it does not have yet is the condition. + await Expect.That(Screen.GetByRole("button", "Hello iframe")).ToBeVisibleAsync(); await Browser.GotoAsync(Iframe2); await promise; } From 2d96aa1df100bda6e858bd8a18ff41d60f2e6202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:27:40 -0300 Subject: [PATCH 7/9] Bind localhost after the app, use Record in the goto test and answer route bugs with 500 (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.Agent.Tests/Testbed.cs | 49 ++++++++++++------- .../FrameGoto/FrameGotoTests.cs | 10 +--- .../LocatorFrame/LocatorFrameTests.cs | 1 - 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/tests/E2E.Agent.Tests/Testbed.cs b/tests/E2E.Agent.Tests/Testbed.cs index 7cf7413f1..5275c44a9 100644 --- a/tests/E2E.Agent.Tests/Testbed.cs +++ b/tests/E2E.Agent.Tests/Testbed.cs @@ -915,14 +915,17 @@ function submitForm() { /// The base URL of the running playground, started on first use. public static string Url => Server.Value; - /// Whether the app also answers on localhost, the second origin of the cross-origin cases. Read after . - public static bool CrossOriginAvailable { get; private set; } + /// Whether the app also answers on localhost, the second origin of the cross-origin cases. Starts the app when it is not running yet. + public static bool CrossOriginAvailable => Url.Length > 0 && s_crossOrigin; + + private static bool s_crossOrigin; private static string Start() { // HttpListener cannot bind port 0: take a free port, and try again when another test takes it first. string url; HttpListener listener; + bool crossOrigin; for (var attempt = 0; ; attempt++) { var probe = new System.Net.Sockets.TcpListener(IPAddress.Loopback, 0); @@ -932,38 +935,38 @@ private static string Start() url = "http://127.0.0.1:" + port.ToString(CultureInfo.InvariantCulture) + "/"; listener = new HttpListener(); listener.Prefixes.Add(url); - // The second origin of the cross-origin cases (upstream's CROSS), the same app under another host name. - listener.Prefixes.Add("http://localhost:" + port.ToString(CultureInfo.InvariantCulture) + "/"); try { listener.Start(); - CrossOriginAvailable = true; - break; } catch (HttpListenerException) { listener.Close(); + if (attempt >= 5) + { + throw; + } + + continue; } - // A host that cannot bind localhost (no mapping, no URL ACL) still serves the app; the cross-origin tests skip themselves. - listener = new HttpListener(); - listener.Prefixes.Add(url); + // The second origin of the cross-origin cases (upstream's CROSS), the same app under another host name. A host that cannot + // bind it (no mapping, no URL ACL) still serves the app; only the cross-origin tests skip themselves. try { - listener.Start(); - CrossOriginAvailable = false; - break; + listener.Prefixes.Add("http://localhost:" + port.ToString(CultureInfo.InvariantCulture) + "/"); + crossOrigin = true; } catch (HttpListenerException) { - listener.Close(); - if (attempt >= 5) - { - throw; - } + crossOrigin = false; } + + break; } + s_crossOrigin = crossOrigin; + _ = Task.Run(() => ListenAsync(listener)); return url.TrimEnd('/'); } @@ -1043,6 +1046,18 @@ await WriteHtmlAsync(response, "Dashboard", """ { // The client went away. } + catch (Exception ex) when (ex is not OperationCanceledException) + { + // A route bug is a 500 the test can see, not an empty 200. + try + { + response.StatusCode = 500; + } + catch (Exception inner) when (inner is InvalidOperationException or ObjectDisposedException or System.Net.ProtocolViolationException) + { + // The response was already sent. + } + } finally { try diff --git a/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs b/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs index d5105eb18..bf3d7df0f 100644 --- a/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs +++ b/tests/E2E.NUnit.Tests/FrameGoto/FrameGotoTests.cs @@ -23,15 +23,7 @@ await ExpectedToFailAsync("child-redirect.html: Timeout", async () => { await Browser.RouteAsync("**/frames/script.js", route => route.ContinueAsync(new RouteContinueOverrides { Url = $"{PREFIX}/never" })); var url = $"{PREFIX}/frames/child-redirect.html"; - Exception? error = null; - try - { - await Browser.GotoAsync(url, new GotoOptions { Timeout = TimeSpan.FromSeconds(5), WaitUntil = GotoWaitUntil.NetworkIdle }); - } - catch (Exception ex) when (ex is not OperationCanceledException) - { - error = ex; - } + var error = await Record(() => Browser.GotoAsync(url, new GotoOptions { Timeout = TimeSpan.FromSeconds(5), WaitUntil = GotoWaitUntil.NetworkIdle })); if (error is null || !error.Message.Contains("timed out in browser.goto", StringComparison.Ordinal)) { diff --git a/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs b/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs index f465f6c04..85ddec31e 100644 --- a/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs +++ b/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs @@ -253,7 +253,6 @@ public async Task Should_wait_for_hidden_iframe_to_become_visible() [Test] public async Task Should_treat_elements_inside_hidden_cross_origin_iframe_as_hidden() { - _ = PREFIX; if (!E2E.Playground.Testbed.CrossOriginAvailable) { Assert.Ignore("The testbed could not bind localhost, the second origin of this test (CROSS)."); From fa3b74c980af997b3f60ae17a77474314c52a304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:34:03 -0300 Subject: [PATCH 8/9] Run the hidden-iframe tests as normal tests now that they pass (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- .../LocatorFrame/LocatorFrameTests.cs | 79 ++++++++----------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs b/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs index 85ddec31e..aeaed09b9 100644 --- a/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs +++ b/tests/E2E.NUnit.Tests/LocatorFrame/LocatorFrameTests.cs @@ -189,47 +189,42 @@ public async Task Wait_for_hidden_should_succeed_when_frame_is_not_in_dom() Assert.That(error!.Message, Does.Contain("no frame matches iframe1")); } - // Known difference, hardkoded/e2e-dotnet#1067: an element inside a `visibility: hidden` iframe is not found, instead of hidden. [Test] public async Task Should_treat_elements_inside_hidden_iframe_as_hidden() { - await ExpectedToFailAsync("observed no node", async () => - { - await Browser.GotoAsync(Content(""" - -
- - -
- - """)); + await Browser.GotoAsync(Content(""" + +
+ + +
+ + """)); - foreach (var button in new[] - { - Browser.FrameLocator("[name=hidden]").Locator("button"), - Browser.FrameLocator("[name=hidden-parent]").Locator("button"), - Browser.FrameLocator("[name=outer]").FrameLocator("[name=inner]").Locator("button"), - }) - { - await Expect.That(button).ToBeAttachedAsync(); - Equal(false, await button.IsVisibleAsync()); - Equal(true, await button.IsHiddenAsync()); - await Expect.That(button).ToBeHiddenAsync(); - await Expect.That(button).ToBeVisibleAsync(false); - await button.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Hidden }); - } + foreach (var button in new[] + { + Browser.FrameLocator("[name=hidden]").Locator("button"), + Browser.FrameLocator("[name=hidden-parent]").Locator("button"), + Browser.FrameLocator("[name=outer]").FrameLocator("[name=inner]").Locator("button"), + }) + { + await Expect.That(button).ToBeAttachedAsync(); + Assert.That(await button.IsVisibleAsync(), Is.False); + Assert.That(await button.IsHiddenAsync(), Is.True); + await Expect.That(button).ToBeHiddenAsync(); + await Expect.That(button).ToBeVisibleAsync(false); + await button.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Hidden }); + } - var visible = Browser.FrameLocator("[name=visible-override]").Locator("button"); - Equal(true, await visible.IsVisibleAsync()); - await Expect.That(visible).ToBeVisibleAsync(); - await visible.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Visible }); - }); + var visible = Browser.FrameLocator("[name=visible-override]").Locator("button"); + Assert.That(await visible.IsVisibleAsync(), Is.True); + await Expect.That(visible).ToBeVisibleAsync(); + await visible.WaitForAsync(new LocatorWaitForOptions { State = WaitForState.Visible }); } [Test] public async Task Should_wait_for_hidden_iframe_to_become_visible() { - // Upstream marks this test `fail`; it passes in the port. await Browser.GotoAsync(Content("""""")); var button = Browser.FrameLocator("[name=frame]").Locator("button"); await Expect.That(button).ToBeHiddenAsync(); @@ -249,7 +244,6 @@ public async Task Should_wait_for_hidden_iframe_to_become_visible() Assert.That(await button.IsVisibleAsync(), Is.False); } - // Known difference, hardkoded/e2e-dotnet#1067: see above. [Test] public async Task Should_treat_elements_inside_hidden_cross_origin_iframe_as_hidden() { @@ -258,18 +252,15 @@ public async Task Should_treat_elements_inside_hidden_cross_origin_iframe_as_hid Assert.Ignore("The testbed could not bind localhost, the second origin of this test (CROSS)."); } - await ExpectedToFailAsync("is not in the observation", async () => - { - await Browser.GotoAsync("/empty.html"); - await Browser.GotoAsync(Content($"""""")); - var div = Browser.FrameLocator("iframe").Locator("div"); - await Expect.That(div).ToHaveTextAsync("Hi, I'm frame"); - Equal(false, await div.IsVisibleAsync()); - await Expect.That(div).ToBeHiddenAsync(); + await Browser.GotoAsync("/empty.html"); + await Browser.GotoAsync(Content($"""""")); + var div = Browser.FrameLocator("iframe").Locator("div"); + await Expect.That(div).ToHaveTextAsync("Hi, I'm frame"); + Assert.That(await div.IsVisibleAsync(), Is.False); + await Expect.That(div).ToBeHiddenAsync(); - await Browser.EvaluateAsync("() => { document.querySelector('iframe').style.visibility = 'visible'; }"); - await Expect.That(div).ToBeVisibleAsync(); - Equal(true, await div.IsVisibleAsync()); - }); + await Browser.EvaluateAsync("() => { document.querySelector('iframe').style.visibility = 'visible'; }"); + await Expect.That(div).ToBeVisibleAsync(); + Assert.That(await div.IsVisibleAsync(), Is.True); } } From 6262b09839035b615a1b7835b1ab23054e7ac59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 19:36:00 -0300 Subject: [PATCH 9/9] Treat any failure to bind the localhost prefix as no cross origin (Refs #1060) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.Agent.Tests/Testbed.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/E2E.Agent.Tests/Testbed.cs b/tests/E2E.Agent.Tests/Testbed.cs index 5275c44a9..8bc4be4e7 100644 --- a/tests/E2E.Agent.Tests/Testbed.cs +++ b/tests/E2E.Agent.Tests/Testbed.cs @@ -957,7 +957,7 @@ private static string Start() listener.Prefixes.Add("http://localhost:" + port.ToString(CultureInfo.InvariantCulture) + "/"); crossOrigin = true; } - catch (HttpListenerException) + catch (Exception ex) when (ex is HttpListenerException or System.Net.Sockets.SocketException or ArgumentException) { crossOrigin = false; }