From c043fc0643f1a82feba76ea25a6201140e152d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Thu, 5 Nov 2026 10:56:25 -0300 Subject: [PATCH 1/3] Port timeout 0 as no step deadline (tester-army/e2e#1554) A call's Timeout of TimeSpan.Zero now sets no deadline of its own, as timeout: 0 does upstream. A negative timeout is INVALID_ARGUMENT everywhere. Also ports the page wait-for-response tests and drops three by-design Playwright gaps from the testbed tests. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- COMPATIBILITY.md | 3 +- .../src/content/docs/api/E2E/ActionOptions.md | 2 +- docs-site/src/content/docs/api/E2E/Browser.md | 8 +-- .../src/content/docs/api/E2E/GotoOptions.md | 2 +- .../docs/api/E2E/LocatorWaitForOptions.md | 2 +- .../src/content/docs/api/E2E/PollOptions.md | 3 +- .../content/docs/api/E2E/ScreenshotOptions.md | 2 +- .../src/content/docs/features/assertions.md | 2 +- .../src/content/docs/migrate/playwright.mdx | 2 +- skills/e2e-dotnet/SKILL.md | 6 ++ src/E2E/Expect/BrowserExpect.cs | 9 +-- src/E2E/Expect/Expect.cs | 7 +- src/E2E/Expect/Poll.cs | 30 ++++++++- src/E2E/Expect/ScreenshotAssertion.cs | 2 +- src/E2E/Expect/ScreenshotCall.cs | 5 +- src/E2E/Expect/ScreenshotOptions.cs | 2 +- src/E2E/Internal/Time.cs | 52 ++++++++++++++- src/E2E/Locator/LocatorEngine.cs | 23 +++---- src/E2E/Locator/Screen.cs | 14 ++-- src/E2E/Run/Browser.cs | 41 +++++------- src/E2E/Run/E2ESession.cs | 1 + src/E2E/Run/GotoOptions.cs | 2 +- tests/E2E.NUnit.Tests/Click/PageClickTests.cs | 6 +- .../LocatorConvenienceTests.cs | 15 +---- tests/E2E.NUnit.Tests/Route/PageRouteTests.cs | 37 +--------- .../SelectOption/PageSelectOptionTests.cs | 14 +--- .../Testbed/playwright/assets/digits/1.png | Bin 0 -> 346 bytes .../Testbed/playwright/assets/digits/2.png | Bin 0 -> 413 bytes .../Testbed/playwright/assets/digits/3.png | Bin 0 -> 434 bytes .../PageWaitForResponseTests.cs | 63 ++++++++++++++++++ tests/E2E.Tests/ExpectPoll/ExpectPollTests.cs | 11 +++ .../ExpectPoll/InsideAnAttemptTests.cs | 14 ++++ .../LocatorEngineStepDeadlineTests.cs | 47 +++++++++++++ .../Routes/BrowserRouteDecisionsTests.cs | 19 ++++++ .../ToHaveScreenshotTests.cs | 6 +- tests/E2E.Tests/Time/CheckStepTimeoutTests.cs | 51 ++++++++++++++ 36 files changed, 359 insertions(+), 144 deletions(-) create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/1.png create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/2.png create mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/3.png create mode 100644 tests/E2E.NUnit.Tests/WaitForResponse/PageWaitForResponseTests.cs create mode 100644 tests/E2E.Tests/LocatorEngine/LocatorEngineStepDeadlineTests.cs create mode 100644 tests/E2E.Tests/Time/CheckStepTimeoutTests.cs diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index dcf1a11fb..b9ae92903 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -45,7 +45,8 @@ Names are C# versions of the JavaScript API: `agent.act` is `ActAsync`, `screen. - `toHaveScreenshot` as `Expect.That(Screen).ToHaveScreenshotAsync(name, options)` and the same on a locator, with `Not` and `Expect.Soft(locator)`; see [Visual comparison](#visual-comparison) - `expect.soft` for every locator expectation, as `Expect.Soft(locator)`, including `.Not` and the per-matcher `timeout`. An `ASSERTION_FAILED` is kept and the body runs on; any other error still throws. `E2ETest` records each one on the NUnit result, as inside `Assert.EnterMultipleScope`, so the test fails when the body ends and lists every failure. `E2E.XUnit.V3.E2ETest` keeps them on the session and fails the test when it is disposed. As upstream, a failed soft assertion outranks a skip: `Assert.Ignore` or `Assert.Inconclusive` after one fails the test in NUnit, and the message keeps the skip reason beside the failures. In xUnit v3, `Assert.Skip` after one fails the test the same way. Other hosts set `E2ESessionOptions.OnSoftFailure` or call `E2ESession.CloseSoftFailures` - `expect(browser)` as `Expect.That(Browser)`: `ToHaveURLAsync` (a string or a `Regex`, with `ignoreCase` and `timeout`), `ToHaveTitleAsync` (a `TextMatch`, with `timeout`), and `ToHaveClassAsync(locator, TextMatch)`, `.Not`, and `Expect.Soft(Browser)`. Like the locator matchers, a passing one verifies the previous `act`, and `.Not` passes after 1000 ms of the opposite. A read that outlasts the matcher's deadline ends it, so a page that stops answering fails at the assertion timeout -- `expect.poll` as `Expect.Poll(read, options)`, with `Timeout`, `Interval`, and `Message`. A read that throws is retried. The matchers are `ToBeAsync`, `ToSatisfyAsync`, and `.Not`; `E2E.NUnit` adds `ToMatchAsync` for any NUnit constraint, such as `Is.GreaterThan(3)`. The default timeout is 5 seconds, not the configured assertion timeout, because the poll does not see the running test, and it does not stop at the test deadline unless a cancellation token is passed +- `expect.poll` as `Expect.Poll(read, options)`, with `Timeout`, `Interval`, and `Message`. A read that throws is retried. The matchers are `ToBeAsync`, `ToSatisfyAsync`, and `.Not`; `E2E.NUnit` adds `ToMatchAsync` for any NUnit constraint, such as `Is.GreaterThan(3)`. The default timeout is 5 seconds, not the configured assertion timeout, because the poll does not see the running test, and it does not stop at the test deadline unless a cancellation token is passed (a `Timeout` of zero waits for that token) +- A call's `Timeout` of `TimeSpan.Zero` sets no deadline of its own, as `timeout: 0` does upstream (`feat(e2e): timeout 0 means no step deadline`, `d2953bb`, tester-army/e2e#1554). Locator actions, `WaitForAsync`, locator and browser matchers, `ToHaveScreenshotAsync`, `Screen.TreeAsync` and `DebugAsync`, `Browser.GotoAsync`, `WaitForResponseAsync`, `WaitForDownloadAsync`, and `WaitForDownloadsAsync` wait until the test deadline instead of failing at once. A negative `TimeSpan` is `TestException` `INVALID_ARGUMENT` on every one of them (it was `ArgumentOutOfRangeException` on some); an infinite `TimeSpan` is negative, so it is refused too. `Time.CheckStepTimeout`, `StepDeadline`, and `StepBudget` (`Internal/Time.cs`, .NET-only; upstream's `checkStepTimeout` and `stepTimeout`) hold the rule. Upstream hands an engine author `stepTimeout` and builds the operation from it; the port hands an engine a `TimeSpan` budget, so `StepBudget` gives it what is left of the test deadline (at most a day, and a day when nothing bounds the test). `Expect.Poll` has no attempt: with `Timeout = TimeSpan.Zero` it polls until the cancellation token ends, and with a token that cannot end it throws `ConfigurationException` `INVALID_CONFIG` (upstream: outside a test). Not ported: the contributed-fixture `FixtureOperation.timeout` rule and `withTimeout` taking an infinite budget, because the port has neither. - `agent.act`, `agent.assert`, `agent.waitFor`, `agent.extract`. `ActOptions` has `Params`, `Timeout`, `MaxSteps`, `MaxModelCalls`, and `Agent`; `AssertOptions` has `Params`, `Timeout`, and `Agent`; `WaitForOptions` has `Params`, `Timeout`, `Interval`, `MaxModelCalls`, and `Agent`; `ExtractOptions` has `Timeout` and `Agent`. See [Agents](#agents) - Act tools `observe`, `scroll`, `scroll_to`, and `back`. They are offered when the engine declares `EngineCapabilities.Scroll` or `EngineCapabilities.History`. `scroll_to` with a target scrolls it into view. With text, it pages the viewport, or the target list, until a node reading the text is listed, then scrolls it into view. It stops when the screen stops moving - Replay cache for a verified `act`: role, name, test id, and path. Modes are `self-finalized`, `agent-concluded`, and `missed` diff --git a/docs-site/src/content/docs/api/E2E/ActionOptions.md b/docs-site/src/content/docs/api/E2E/ActionOptions.md index c9464cdb4..0f1c03ae3 100644 --- a/docs-site/src/content/docs/api/E2E/ActionOptions.md +++ b/docs-site/src/content/docs/api/E2E/ActionOptions.md @@ -40,6 +40,6 @@ public TimeSpan? Timeout { get; init; } ``` -How long to wait for exactly one enabled match. Defaults to the configured action timeout. +How long to wait for exactly one enabled match. Defaults to the configured action timeout. Zero sets no deadline of its own: the test timeout bounds it. A negative value is `INVALID_ARGUMENT`. **Value:** [TimeSpan?](https://learn.microsoft.com/dotnet/api/system.timespan) diff --git a/docs-site/src/content/docs/api/E2E/Browser.md b/docs-site/src/content/docs/api/E2E/Browser.md index 147cdb8ac..9adb7fa5d 100644 --- a/docs-site/src/content/docs/api/E2E/Browser.md +++ b/docs-site/src/content/docs/api/E2E/Browser.md @@ -664,7 +664,7 @@ public Task WaitForDownloadAsync(Func trigger, TimeSpan? Runs <code class="paramref">trigger</code> and waits for the download it starts, within <code class="paramref">timeout</code> (the action timeout by -default). The file is kept under the attempt's `downloads` artifact folder, as an artifact of this step. A text download +default; zero waits for the test timeout). The file is kept under the attempt's `downloads` artifact folder, as an artifact of this step. A text download (`text/*` or `application/json`) is rewritten in place through the session's secrets when it holds any, and the report labels it `complete`; any other download stays as the app served it, `incomplete`. A trigger that throws fails the call with its own error, and one that starts no download fails with `ACTION_FAILED`, naming the wait and @@ -692,7 +692,7 @@ public Task> WaitForDownloadsAsync(Func tri Runs <code class="paramref">trigger</code> once and waits for the first <code class="paramref">count</code> downloads it starts, within -<code class="paramref">timeout</code> (the action timeout by default), and returns them in start order. Each file is kept under the attempt's +<code class="paramref">timeout</code> (the action timeout by default; zero waits for the test timeout), and returns them in start order. Each file is kept under the attempt's `downloads` artifact folder as its own artifact of this step, and a text download is rewritten through the session's secrets as `WaitForDownloadAsync` does. One timeout bounds the start, completion and save of every file. When fewer start in time the call fails with `ACTION_FAILED` naming both counts; extra downloads are @@ -724,7 +724,7 @@ public Task WaitForResponseAsync(string pattern, TimeSpan? timeout Waits for a response whose complete URL matches the glob <code class="paramref">pattern</code>: `*` matches within one path segment, `**` crosses `/`, `?` matches one character, and `\` escapes the next one. The timeout bounds -the match only, and defaults to the action timeout. +the match only, and defaults to the action timeout; zero waits for the test timeout. **Parameters** @@ -746,7 +746,7 @@ public Task WaitForResponseAsync(Regex pattern, TimeSpan? timeout = ``` -Waits for a response whose URL matches <code class="paramref">pattern</code>. The timeout bounds the match only, and defaults to the action timeout. +Waits for a response whose URL matches <code class="paramref">pattern</code>. The timeout bounds the match only, and defaults to the action timeout; zero waits for the test timeout. **Parameters** diff --git a/docs-site/src/content/docs/api/E2E/GotoOptions.md b/docs-site/src/content/docs/api/E2E/GotoOptions.md index ed18c15d8..39f110a7a 100644 --- a/docs-site/src/content/docs/api/E2E/GotoOptions.md +++ b/docs-site/src/content/docs/api/E2E/GotoOptions.md @@ -40,7 +40,7 @@ public TimeSpan? Timeout { get; init; } ``` -The navigation budget. Defaults to the action timeout. +The navigation budget. Defaults to the action timeout. Zero sets no deadline of its own: the test timeout bounds it. A negative value is `INVALID_ARGUMENT`. **Value:** [TimeSpan?](https://learn.microsoft.com/dotnet/api/system.timespan) diff --git a/docs-site/src/content/docs/api/E2E/LocatorWaitForOptions.md b/docs-site/src/content/docs/api/E2E/LocatorWaitForOptions.md index 1c9071fee..7ec8c882e 100644 --- a/docs-site/src/content/docs/api/E2E/LocatorWaitForOptions.md +++ b/docs-site/src/content/docs/api/E2E/LocatorWaitForOptions.md @@ -51,6 +51,6 @@ public TimeSpan? Timeout { get; init; } ``` -How long to wait. Defaults to the configured action timeout. +How long to wait. Defaults to the configured action timeout. Zero sets no deadline of its own: the test timeout bounds it. A negative value is `INVALID_ARGUMENT`. **Value:** [TimeSpan?](https://learn.microsoft.com/dotnet/api/system.timespan) diff --git a/docs-site/src/content/docs/api/E2E/PollOptions.md b/docs-site/src/content/docs/api/E2E/PollOptions.md index d6c4c620c..4c7d3b253 100644 --- a/docs-site/src/content/docs/api/E2E/PollOptions.md +++ b/docs-site/src/content/docs/api/E2E/PollOptions.md @@ -68,6 +68,7 @@ public TimeSpan? Timeout { get; init; } ``` -Deadline for the matcher to hold. The default is 5 seconds. +Deadline for the matcher to hold. The default is 5 seconds. Zero sets no deadline: the poll runs until the cancellation token it is +given ends, so it needs a token that can end (`INVALID_CONFIG` otherwise). **Value:** [TimeSpan?](https://learn.microsoft.com/dotnet/api/system.timespan) diff --git a/docs-site/src/content/docs/api/E2E/ScreenshotOptions.md b/docs-site/src/content/docs/api/E2E/ScreenshotOptions.md index 7192dbdab..59023f39e 100644 --- a/docs-site/src/content/docs/api/E2E/ScreenshotOptions.md +++ b/docs-site/src/content/docs/api/E2E/ScreenshotOptions.md @@ -113,6 +113,6 @@ public TimeSpan? Timeout { get; init; } ``` -Assertion budget. Defaults to the assertion timeout. +Assertion budget. Defaults to the assertion timeout. Zero sets no deadline of its own: the test timeout bounds it. A negative value is `INVALID_ARGUMENT`. **Value:** [TimeSpan?](https://learn.microsoft.com/dotnet/api/system.timespan) diff --git a/docs-site/src/content/docs/features/assertions.md b/docs-site/src/content/docs/features/assertions.md index 164338ce2..71232028a 100644 --- a/docs-site/src/content/docs/features/assertions.md +++ b/docs-site/src/content/docs/features/assertions.md @@ -9,7 +9,7 @@ sidebar: - `Expect.Soft(locator)` and `Expect.Soft(screen)` record each failure and let the test go on. On NUnit the failures land on the test result, as inside `Assert.EnterMultipleScope`, and the test fails when it ends with every failure listed. On xUnit v3 they stay on the session, and the test fails when it is disposed, with every failure in one message. - `Expect.Soft(Browser)` keeps the failures of `ToHaveURLAsync`, `ToHaveTitleAsync`, and `ToHaveClassAsync` the same way. -- `Expect.Poll(read)` retries a value. `ToBeAsync` and `ToSatisfyAsync(predicate)` work on both adapters. `E2E.NUnit` also adds `ToMatchAsync` with any NUnit constraint: `await Expect.Poll(() => ReadCountAsync()).ToMatchAsync(Is.GreaterThan(3));`. A read that throws, or a matcher that refuses the value's type, is one failing sample, not the end of the poll. +- `Expect.Poll(read)` retries a value. `ToBeAsync` and `ToSatisfyAsync(predicate)` work on both adapters. `E2E.NUnit` also adds `ToMatchAsync` with any NUnit constraint: `await Expect.Poll(() => ReadCountAsync()).ToMatchAsync(Is.GreaterThan(3));`. A read that throws, or a matcher that refuses the value's type, is one failing sample, not the end of the poll. A `Timeout` of `TimeSpan.Zero` sets no deadline: the poll runs until the cancellation token you pass ends. ## Evidence screenshots diff --git a/docs-site/src/content/docs/migrate/playwright.mdx b/docs-site/src/content/docs/migrate/playwright.mdx index 3c03c9f47..13fb3c622 100644 --- a/docs-site/src/content/docs/migrate/playwright.mdx +++ b/docs-site/src/content/docs/migrate/playwright.mdx @@ -252,7 +252,7 @@ The agent does the checkout steps and adapts when the form changes. A test can a | `Page.UnrouteAsync()` | `Browser.UnrouteAsync(pattern)` | web only | | `Page.UnrouteAllAsync()` | `Browser.UnrouteAllAsync()`; configured site headers stay | web only | | `Page.WaitForResponseAsync(pattern)`, `RunAndWaitForResponseAsync` | `Browser.WaitForResponseAsync(pattern)`: a string or `Regex`, no predicate; `Url`, `Status`, `Headers`, `BodyAsync()`, `JsonAsync()`, `TextAsync()`. A string is the glob of `Browser.RouteAsync`, tested against the whole URL, query included: Playwright's `"/api/orders"` is the full URL or `"**/api/orders"`, and `"\\?"` is a literal `?`. Start it before the step that sends the request, and await it after | web only | -| a `Timeout` of `0` for no timeout | a positive `TimeSpan`. `TimeSpan.Zero` on `Browser.GotoAsync`, `WaitForDownloadAsync`, or `WaitForDownloadsAsync` throws `ArgumentOutOfRangeException`. A locator action takes `Timeout.InfiniteTimeSpan` for no timeout | missing | +| a `Timeout` of `0` for no timeout | the same: `TimeSpan.Zero` sets no deadline of its own on a locator action, `WaitForAsync`, a matcher, `ToHaveScreenshotAsync`, `Browser.GotoAsync`, `WaitForResponseAsync`, `WaitForDownloadAsync`, and `WaitForDownloadsAsync`; the test timeout still bounds it. A negative `TimeSpan` throws `TestException` with `INVALID_ARGUMENT`. `Expect.Poll` with `Timeout = TimeSpan.Zero` polls until the cancellation token you pass ends, and without one it throws `ConfigurationException` with `INVALID_CONFIG` | same | | `response.Ok`, `response.Request` | `Status` | missing | | `Page.WaitForRequestAsync()`, `request.PostDataJSON()` | none yet for `WaitForRequestAsync`; `route.Request.PostData` is a string | missing | | `RouteFromHARAsync()`, `RouteWebSocketAsync()` | not yet | missing | diff --git a/skills/e2e-dotnet/SKILL.md b/skills/e2e-dotnet/SKILL.md index e5e49bf19..fa07ac4ba 100644 --- a/skills/e2e-dotnet/SKILL.md +++ b/skills/e2e-dotnet/SKILL.md @@ -226,6 +226,12 @@ lines you changed: step, so keep it longer than the slowest screen takes to load. A call's own timeout still wins. An `Expect` already gives up after 5 s by default (`assertionTimeout`). +- A call's `Timeout` of `TimeSpan.Zero` sets no deadline of its own: the call + waits until the test timeout instead of failing at once. It works on locator + actions, `WaitForAsync`, `Expect` matchers, `ToHaveScreenshotAsync`, + `Browser.GotoAsync`, `WaitForResponseAsync`, and `WaitForDownloadAsync`. A + negative `TimeSpan` fails with `INVALID_ARGUMENT`. `Expect.Poll` with a zero + `Timeout` polls until the cancellation token you pass ends. - Keep the replay cache on. A failed run keeps the recording of every goal whose check passed, and the next run replays those with no model call. New, changed, and failed goals run live, and so does a replay the trace page diff --git a/src/E2E/Expect/BrowserExpect.cs b/src/E2E/Expect/BrowserExpect.cs index fb4758efa..818b912f8 100644 --- a/src/E2E/Expect/BrowserExpect.cs +++ b/src/E2E/Expect/BrowserExpect.cs @@ -161,14 +161,9 @@ private Task PollAsync(string matcher, string describeExpected, TimeSpan? timeou private async Task PollCoreAsync(string matcher, string describeExpected, TimeSpan? timeout, Func> read, CancellationToken cancellationToken) { - if (timeout is { } given) - { - ArgumentOutOfRangeException.ThrowIfLessThan(given, TimeSpan.Zero, nameof(timeout)); - } - var token = _browser.Token(cancellationToken); var clock = TimeProvider.System; - var deadline = new Deadline(timeout ?? _browser.AssertionTimeout, clock); + var deadline = Time.StepDeadline(timeout, "expect." + (_negated ? "not." : "") + matcher, _browser.AssertionTimeout, _browser.BudgetDeadline, clock); string? observed = null; try { @@ -182,7 +177,7 @@ await Time.PollConditionAsync(new PollConditionOptions { var left = deadline.Remaining(clock.GetUtcNow()); using var bounded = CancellationTokenSource.CreateLinkedTokenSource(token); - bounded.CancelAfter(left > Time.PollInterval ? left : Time.PollInterval); + bounded.CancelAfter(left > Time.Unbounded ? Time.Unbounded : left > Time.PollInterval ? left : Time.PollInterval); try { var sample = await read(bounded.Token).ConfigureAwait(false); diff --git a/src/E2E/Expect/Expect.cs b/src/E2E/Expect/Expect.cs index 6169938ba..fa5e99a38 100644 --- a/src/E2E/Expect/Expect.cs +++ b/src/E2E/Expect/Expect.cs @@ -405,11 +405,6 @@ private async Task PollCoreAsync( MissingFrame missingFrame, CancellationToken cancellationToken) { - if (timeout is { } budget) - { - ArgumentOutOfRangeException.ThrowIfLessThan(budget, TimeSpan.Zero, nameof(timeout)); - } - var token = _locator.Screen.Token(cancellationToken); var clock = _locator.Screen.Clock; Verdict last = default; @@ -417,7 +412,7 @@ private async Task PollCoreAsync( var samples = new SampleHistory("expect", _locator.Screen.Redact); try { - var deadline = new Deadline(timeout ?? _locator.Screen.AssertionTimeout, clock); + var deadline = _locator.Screen.Engine.AssertionDeadlineFor(timeout, "expect." + (_negated ? "not." : "") + matcher); await samples.RecordAsync(_locator.Screen.Steps, token, () => Time.PollReadsAsync(new PollReadsOptions { Deadline = deadline, diff --git a/src/E2E/Expect/Poll.cs b/src/E2E/Expect/Poll.cs index 3e25f89e7..bdb3b7373 100644 --- a/src/E2E/Expect/Poll.cs +++ b/src/E2E/Expect/Poll.cs @@ -3,13 +3,17 @@ // SPDX-License-Identifier: Apache-2.0 using System.Globalization; +using E2E.Internal; namespace E2E; /// How re-reads a value. public sealed class PollOptions { - /// Deadline for the matcher to hold. The default is 5 seconds. + /// + /// Deadline for the matcher to hold. The default is 5 seconds. Zero sets no deadline: the poll runs until the cancellation token it is + /// given ends, so it needs a token that can end (INVALID_CONFIG otherwise). + /// public TimeSpan? Timeout { get; init; } /// Pause between reads. The default is 100 milliseconds. @@ -74,7 +78,7 @@ private async Task PollAsync(string matcher, Func check, Func check, Func Time.Unbounded ? Time.Unbounded : remaining, clock, cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) { @@ -142,6 +146,26 @@ private async Task PollAsync(string matcher, Func check, Func + /// The poll's own deadline. A Timeout of zero sets none, as upstream's timeout: 0 waits for the phase's, and the port's + /// phase is the caller's : it needs one that can end, or nothing would bound the poll + /// (upstream's INVALID_CONFIG outside a test). + /// + private static DateTimeOffset PollDeadline(TimeSpan timeout, DateTimeOffset started, CancellationToken cancellationToken) + { + if (timeout != TimeSpan.Zero) + { + return started + timeout; + } + + if (!cancellationToken.CanBeCanceled) + { + throw new ConfigurationException("INVALID_CONFIG", "expect.poll timeout 0 waits for the test deadline, so it needs a cancellation token that ends with the test; pass a positive timeout or the test's token"); + } + + return Time.Never; + } + private static Task PauseAsync(DateTimeOffset deadline, TimeSpan interval, TimeProvider clock, CancellationToken cancellationToken) { var remaining = deadline - clock.GetUtcNow(); diff --git a/src/E2E/Expect/ScreenshotAssertion.cs b/src/E2E/Expect/ScreenshotAssertion.cs index 66d6e0121..edc716662 100644 --- a/src/E2E/Expect/ScreenshotAssertion.cs +++ b/src/E2E/Expect/ScreenshotAssertion.cs @@ -54,7 +54,7 @@ private static async Task ExpectScreenshotCoreAsync(Screen screen, Locator? subj var file = Path.Combine(directory, call.Stem + store.Suffix + ".png"); var shown = Shown(store, file); var token = screen.Token(cancellationToken); - var deadline = new Deadline(call.Timeout ?? screen.AssertionTimeout, screen.Clock); + var deadline = screen.Engine.AssertionDeadlineFor(call.Timeout, api + " option"); var reads = screen.Reads(deadline); var capturer = new Capturer(screen, store, api, subject, call, reads); diff --git a/src/E2E/Expect/ScreenshotCall.cs b/src/E2E/Expect/ScreenshotCall.cs index 39b1ecf74..c54747d21 100644 --- a/src/E2E/Expect/ScreenshotCall.cs +++ b/src/E2E/Expect/ScreenshotCall.cs @@ -37,10 +37,7 @@ private static ScreenshotCall ParseScreenshotCall(string api, ScreenshotContext throw new TestException("INVALID_ARGUMENT", api + " option maxDiffPixels must be a whole number of pixels, 0 or more"); } - if (options?.Timeout is { } timeout && timeout <= TimeSpan.Zero) - { - throw new TestException("INVALID_ARGUMENT", api + " option timeout must be a positive number of milliseconds"); - } + Time.CheckStepTimeout(options?.Timeout, api + " option"); var stem = name is null ? UnnamedStem(store) : NamedStem(api, name); var tolerance = new ImageTolerance( diff --git a/src/E2E/Expect/ScreenshotOptions.cs b/src/E2E/Expect/ScreenshotOptions.cs index f35f70c5a..91b666b7e 100644 --- a/src/E2E/Expect/ScreenshotOptions.cs +++ b/src/E2E/Expect/ScreenshotOptions.cs @@ -22,6 +22,6 @@ public sealed class ScreenshotOptions /// Color of the boxes, written #rrggbb. Default #ff00ff. public string? MaskColor { get; init; } - /// Assertion budget. Defaults to the assertion timeout. + /// Assertion budget. Defaults to the assertion timeout. Zero sets no deadline of its own: the test timeout bounds it. A negative value is INVALID_ARGUMENT. public TimeSpan? Timeout { get; init; } } diff --git a/src/E2E/Internal/Time.cs b/src/E2E/Internal/Time.cs index 9ca851841..2cff79f01 100644 --- a/src/E2E/Internal/Time.cs +++ b/src/E2E/Internal/Time.cs @@ -2,6 +2,7 @@ // Modified by Dario Kondratiuk. // SPDX-License-Identifier: Apache-2.0 +using System.Globalization; using E2E.Engine; namespace E2E.Internal; @@ -54,7 +55,7 @@ public TimeSpan Timeout() var capped = _cap.Remaining(now); var budget = capped < left ? capped : left; var least = TimeSpan.FromMilliseconds(1); - return budget > least ? budget : least; + return budget > Time.Unbounded ? Time.Unbounded : budget > least ? budget : least; } /// Marks a read starting now: the one judges until the next starts. @@ -167,6 +168,55 @@ public static CancellationToken Link(CancellationToken caller, CancellationToken return session.CanBeCanceled ? CancellationTokenSource.CreateLinkedTokenSource(caller, session).Token : caller; } + /// + /// The deadline of a step that has none of its own and no running phase to end it: far enough that nothing reaches it, and not + /// , so adding a read's time to it cannot overflow. + /// + public static readonly DateTimeOffset Never = new(9000, 1, 1, 0, 0, 0, TimeSpan.Zero); + + /// The longest budget handed to an engine read or a timer: a day, standing for no limit when nothing caps a step. + public static readonly TimeSpan Unbounded = TimeSpan.FromDays(1); + + /// + /// Refuses a per-call step timeout below zero as INVALID_ARGUMENT (upstream's checkStepTimeout; a is + /// always a finite number of milliseconds, so only the sign is left to check). Zero means no step deadline: the step waits until the + /// running phase's deadline (the test timeout in the body). + /// + public static void CheckStepTimeout(TimeSpan? timeout, string api) + { + if (timeout is { } given && given < TimeSpan.Zero) + { + throw new TestException("INVALID_ARGUMENT", api + " timeout must be a finite number of milliseconds, 0 or more; got " + ((long)given.TotalMilliseconds).ToString(CultureInfo.InvariantCulture)); + } + } + + /// + /// The deadline of a step on a call's own (upstream's stepTimeout, capped by the phase as + /// Deadline.min does): the timeout, or when none is given, from now. Zero sets no deadline of its + /// own, so alone bounds it; with no phase it is . + /// + public static Deadline StepDeadline(TimeSpan? timeout, string api, TimeSpan fallback, Deadline? phase, TimeProvider clock) + { + CheckStepTimeout(timeout, api); + return timeout == TimeSpan.Zero ? phase ?? new Deadline(Never) : new Deadline(timeout ?? fallback, clock); + } + + /// + /// as a budget, for a call that hands one to the engine: what is left of the deadline, at least 1 ms and + /// at most . + /// + public static TimeSpan StepBudget(TimeSpan? timeout, string api, TimeSpan fallback, Deadline? phase, TimeProvider clock) + { + if (timeout != TimeSpan.Zero) + { + CheckStepTimeout(timeout, api); + return timeout ?? fallback; + } + + var left = StepDeadline(timeout, api, fallback, phase, clock).Remaining(clock.GetUtcNow()); + return left < TimeSpan.FromMilliseconds(1) ? TimeSpan.FromMilliseconds(1) : left > Unbounded ? Unbounded : left; + } + /// Canonical polling cadence for locator and assertion loops. public static readonly TimeSpan PollInterval = TimeSpan.FromMilliseconds(100); diff --git a/src/E2E/Locator/LocatorEngine.cs b/src/E2E/Locator/LocatorEngine.cs index 223550985..74a6ad4e3 100644 --- a/src/E2E/Locator/LocatorEngine.cs +++ b/src/E2E/Locator/LocatorEngine.cs @@ -175,21 +175,20 @@ internal static TestException LateAction(string kind, string target) => /// /// The timeout of one action-family operation: when given, the action timeout otherwise. Upstream's - /// deadline(timeoutMs) builds the deadline itself; is also this type's name here (.NET-only name). + /// deadline(timeoutMs) builds the deadline itself; is also this type's name here (.NET-only name). A + /// negative is INVALID_ARGUMENT. Zero sets no deadline of its own: the budget is what is left of the + /// running phase's deadline. /// - internal TimeSpan TimeoutOf(TimeSpan? timeout) - { - if (timeout is TimeSpan chosen) - { - ArgumentOutOfRangeException.ThrowIfLessThan(chosen, TimeSpan.Zero, "timeout"); - return chosen; - } + internal TimeSpan TimeoutOf(TimeSpan? timeout) => Time.StepBudget(timeout, "the step", ActionTimeout, BudgetDeadline, Clock); - return ActionTimeout; - } + /// + /// Deadline for one action-family operation (upstream's deadline; .NET-only name, as Deadline is the type). Zero sets no + /// deadline of its own, so the running phase's alone bounds it. + /// + internal Deadline DeadlineFor(TimeSpan? timeout = null) => Time.StepDeadline(timeout, "the step", ActionTimeout, BudgetDeadline, Clock); - /// Deadline for one action-family operation (upstream's deadline; .NET-only name, as Deadline is the type). - internal Deadline DeadlineFor(TimeSpan? timeout = null) => new(TimeoutOf(timeout), Clock); + /// Deadline for one assertion on a matcher's own , the assertion timeout by default; names the call in a refusal. + internal Deadline AssertionDeadlineFor(TimeSpan? timeout, string api) => Time.StepDeadline(timeout, api, AssertionTimeout, BudgetDeadline, Clock); /// One observation of the screen, an unopened app reported as APP_NOT_OPEN. internal async Task ObserveAsync(CancellationToken cancellationToken) diff --git a/src/E2E/Locator/Screen.cs b/src/E2E/Locator/Screen.cs index 173d15320..eda412849 100644 --- a/src/E2E/Locator/Screen.cs +++ b/src/E2E/Locator/Screen.cs @@ -410,11 +410,7 @@ private async Task ReadTreeAsync(string api, ActionOptions? options, Can throw new TestException("INVALID_ARGUMENT", api + " reads the whole screen; call it on screen"); } - var timeout = options?.Timeout ?? ActionTimeout; - if (timeout != System.Threading.Timeout.InfiniteTimeSpan) - { - ArgumentOutOfRangeException.ThrowIfLessThan(timeout, TimeSpan.Zero, "timeout"); - } + var timeout = options?.Timeout is null ? ActionTimeout : Engine.TimeoutOf(options.Timeout); var token = Token(cancellationToken); async Task Read() @@ -918,7 +914,7 @@ private async Task WaitForCoreAsync(LocatorWaitForOptions? options, Cancellation var token = _screen.Token(cancellationToken); var clock = _screen.Clock; var startedAt = clock.GetTimestamp(); - var deadline = new Deadline(TimeoutOf(options?.Timeout), clock); + var deadline = _screen.Engine.DeadlineFor(options?.Timeout); var samples = new SampleHistory("waitFor", _screen.Redact); await samples.RecordAsync(_screen.Steps, token, () => Time.PollReadsAsync(new PollReadsOptions { @@ -1095,8 +1091,6 @@ private async Task ResolveReadableAsync(CancellationToken cancella internal Task ResolveExactlyOneAsync(Deadline deadline, CancellationToken token) => _screen.Engine.ResolveExactlyOneAsync(Query, deadline, token); - private TimeSpan TimeoutOf(TimeSpan? timeout) => _screen.Engine.TimeoutOf(timeout); - private static string StateName(WaitForState state) => state switch { WaitForState.Attached => "attached", @@ -1109,7 +1103,7 @@ internal Task ResolveExactlyOneAsync(Deadline deadline, Cancellati /// Options for one locator action. public class ActionOptions { - /// How long to wait for exactly one enabled match. Defaults to the configured action timeout. + /// How long to wait for exactly one enabled match. Defaults to the configured action timeout. Zero sets no deadline of its own: the test timeout bounds it. A negative value is INVALID_ARGUMENT. public TimeSpan? Timeout { get; init; } } @@ -1207,7 +1201,7 @@ public sealed class LocatorWaitForOptions { public WaitForState State { get; init; } = WaitForState.Visible; - /// How long to wait. Defaults to the configured action timeout. + /// How long to wait. Defaults to the configured action timeout. Zero sets no deadline of its own: the test timeout bounds it. A negative value is INVALID_ARGUMENT. public TimeSpan? Timeout { get; init; } } diff --git a/src/E2E/Run/Browser.cs b/src/E2E/Run/Browser.cs index e4fc13c25..1d5374648 100644 --- a/src/E2E/Run/Browser.cs +++ b/src/E2E/Run/Browser.cs @@ -62,6 +62,12 @@ internal Browser(IEngineSession session, string platform, string? baseUrl, strin internal TimeSpan AssertionTimeout => _assertionTimeout; + /// The deadline of the running phase, which a call with Timeout = TimeSpan.Zero waits for; null when nothing bounds the test. + internal Deadline? BudgetDeadline { get; set; } + + /// The budget of a call on its own , the action timeout by default (upstream's context.operation(stepTimeout(timeout, api))); zero is what is left of the test. + private TimeSpan StepBudget(TimeSpan? timeout, string api) => Time.StepBudget(timeout, api, _actionTimeout, BudgetDeadline, TimeProvider.System); + internal string? BaseUrl => _baseUrl; internal void NotifyVerified() => _verified(); @@ -92,15 +98,11 @@ internal Task RunStepAsync(StepKind kind, string api, string label, Func { + var budget = StepBudget(options?.Timeout, "browser.goto"); var resolved = Routes.Resolve(_baseUrl, url); - return AppNotOpen.GuardAsync(() => Require("goto").GotoAsync(resolved, options?.WaitUntil ?? GotoWaitUntil.Load, options?.Timeout ?? _actionTimeout, Token(cancellationToken))); + return AppNotOpen.GuardAsync(() => Require("goto").GotoAsync(resolved, options?.WaitUntil ?? GotoWaitUntil.Load, budget, Token(cancellationToken))); }); } @@ -207,7 +209,7 @@ private EngineFixtureContext Fixture() => /// Waits for a response whose complete URL matches the glob : /// * matches within one path segment, ** crosses /, ? /// matches one character, and \ escapes the next one. The timeout bounds - /// the match only, and defaults to the action timeout. + /// the match only, and defaults to the action timeout; zero waits for the test timeout. /// public Task WaitForResponseAsync(string pattern, TimeSpan? timeout = null, CancellationToken cancellationToken = default) { @@ -215,7 +217,7 @@ public Task WaitForResponseAsync(string pattern, TimeSpan? timeout return WaitForResponseCoreAsync(pattern, () => Routes.CompilePattern(pattern).IsMatch, timeout, cancellationToken); } - /// Waits for a response whose URL matches . The timeout bounds the match only, and defaults to the action timeout. + /// Waits for a response whose URL matches . The timeout bounds the match only, and defaults to the action timeout; zero waits for the test timeout. public Task WaitForResponseAsync(Regex pattern, TimeSpan? timeout = null, CancellationToken cancellationToken = default) { ArgumentNullException.ThrowIfNull(pattern); @@ -388,7 +390,7 @@ public Task> OnDialogAsync(Func handler, CancellationTo /// /// Runs and waits for the download it starts, within (the action timeout by - /// default). The file is kept under the attempt's downloads artifact folder, as an artifact of this step. A text download + /// default; zero waits for the test timeout). The file is kept under the attempt's downloads artifact folder, as an artifact of this step. A text download /// (text/* or application/json) is rewritten in place through the session's secrets when it holds any, and the report /// labels it complete; any other download stays as the app served it, incomplete. A trigger that /// throws fails the call with its own error, and one that starts no download fails with ACTION_FAILED, naming the wait and @@ -397,16 +399,12 @@ public Task> OnDialogAsync(Func handler, CancellationTo public async Task WaitForDownloadAsync(Func trigger, TimeSpan? timeout = null, CancellationToken cancellationToken = default) { ArgumentNullException.ThrowIfNull(trigger); - if (timeout is { } budget) - { - ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(budget, TimeSpan.Zero, nameof(timeout)); - } - var session = Require("waitForDownload"); BrowserDownload? download = null; await RunStepAsync(StepKind.Resource, "browser.waitForDownload", "", async () => { - download = await AppNotOpen.GuardAsync(() => session.WaitForDownloadAsync(trigger, timeout ?? _actionTimeout, Token(cancellationToken))).ConfigureAwait(false); + var budget = StepBudget(timeout, "browser.waitForDownload"); + download = await AppNotOpen.GuardAsync(() => session.WaitForDownloadAsync(trigger, budget, Token(cancellationToken))).ConfigureAwait(false); Attach("download", download.Path); }).ConfigureAwait(false); return download!; @@ -414,7 +412,7 @@ await RunStepAsync(StepKind.Resource, "browser.waitForDownload", "", async () => /// /// Runs once and waits for the first downloads it starts, within - /// (the action timeout by default), and returns them in start order. Each file is kept under the attempt's + /// (the action timeout by default; zero waits for the test timeout), and returns them in start order. Each file is kept under the attempt's /// downloads artifact folder as its own artifact of this step, and a text download is rewritten through the session's secrets /// as WaitForDownloadAsync does. One timeout bounds the start, completion and /// save of every file. When fewer start in time the call fails with ACTION_FAILED naming both counts; extra downloads are @@ -424,11 +422,6 @@ await RunStepAsync(StepKind.Resource, "browser.waitForDownload", "", async () => public async Task> WaitForDownloadsAsync(Func trigger, int count, TimeSpan? timeout = null, CancellationToken cancellationToken = default) { ArgumentNullException.ThrowIfNull(trigger); - if (timeout is { } budget) - { - ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(budget, TimeSpan.Zero, nameof(timeout)); - } - var session = Require("waitForDownloads"); IReadOnlyList downloads = []; await RunStepAsync(StepKind.Resource, "browser.waitForDownloads", "", async () => @@ -438,7 +431,8 @@ await RunStepAsync(StepKind.Resource, "browser.waitForDownloads", "", async () = throw new TestException("INVALID_ARGUMENT", "waitForDownloads: count must be a positive safe integer"); } - downloads = await AppNotOpen.GuardAsync(() => session.WaitForDownloadsAsync(trigger, count, timeout ?? _actionTimeout, Token(cancellationToken))).ConfigureAwait(false); + var budget = StepBudget(timeout, "browser.waitForDownloads"); + downloads = await AppNotOpen.GuardAsync(() => session.WaitForDownloadsAsync(trigger, count, budget, Token(cancellationToken))).ConfigureAwait(false); foreach (var download in downloads) { Attach("download", download.Path); @@ -516,7 +510,8 @@ private Task WaitForResponseCoreAsync(object pattern, Func { var session = Require("waitForResponse"); - var response = await session.WaitForResponseAsync(matcher(), timeout ?? _actionTimeout, Token(cancellationToken)).ConfigureAwait(false); + var budget = StepBudget(timeout, "browser.waitForResponse"); + var response = await session.WaitForResponseAsync(matcher(), budget, Token(cancellationToken)).ConfigureAwait(false); return new WebResponse(response, _actionTimeout, _token); }); diff --git a/src/E2E/Run/E2ESession.cs b/src/E2E/Run/E2ESession.cs index f2acc9f07..80e9cb89d 100644 --- a/src/E2E/Run/E2ESession.cs +++ b/src/E2E/Run/E2ESession.cs @@ -373,6 +373,7 @@ internal static async Task LaunchAsync(E2ESessionOptions options, IR screen.ActionKinds = engine.ActionKinds; screen.PointerActionKinds = engine.PointerActionKinds; screen.BudgetDeadline = budgetDeadline; + browser.BudgetDeadline = budgetDeadline; screen.ProjectRoot = projectRoot; screen.RememberSecret = secret => scope.Remember(new Dictionary(StringComparer.Ordinal) { [secret.Name] = secret }); screen.Redact = text => scope.Redactor.Redact(text); diff --git a/src/E2E/Run/GotoOptions.cs b/src/E2E/Run/GotoOptions.cs index 58cc3fb11..cab151cbc 100644 --- a/src/E2E/Run/GotoOptions.cs +++ b/src/E2E/Run/GotoOptions.cs @@ -23,6 +23,6 @@ public sealed record GotoOptions /// When the navigation counts as done. Defaults to . public GotoWaitUntil WaitUntil { get; init; } = GotoWaitUntil.Load; - /// The navigation budget. Defaults to the action timeout. + /// The navigation budget. Defaults to the action timeout. Zero sets no deadline of its own: the test timeout bounds it. A negative value is INVALID_ARGUMENT. public TimeSpan? Timeout { get; init; } } diff --git a/tests/E2E.NUnit.Tests/Click/PageClickTests.cs b/tests/E2E.NUnit.Tests/Click/PageClickTests.cs index 73edf187e..100d62be3 100644 --- a/tests/E2E.NUnit.Tests/Click/PageClickTests.cs +++ b/tests/E2E.NUnit.Tests/Click/PageClickTests.cs @@ -34,6 +34,8 @@ public sealed class PageClickTests : PlaywrightTest private static readonly ActionOptions Ten = new() { Timeout = TimeSpan.FromSeconds(10) }; + private static readonly ActionOptions NoTimeout = new() { Timeout = TimeSpan.Zero }; + private async Task ResultAsync() => (await Browser.EvaluateAsync("result"))!; [Test] @@ -155,7 +157,7 @@ private async Task WaitForPropertyToBeGoneAsync(string property, string hidden, var done = false; var clicked = Task.Run(async () => { - await Browser.Locator("button").TapAsync(Ten); + await Browser.Locator("button").TapAsync(NoTimeout); done = true; }); await Browser.EvaluateAsync(GiveItAChanceToClick); @@ -175,7 +177,7 @@ public async Task Should_waitFor_visible_when_parent_is_hidden() var done = false; var clicked = Task.Run(async () => { - await Browser.Locator("button").TapAsync(Ten); + await Browser.Locator("button").TapAsync(NoTimeout); done = true; }); await Browser.EvaluateAsync(GiveItAChanceToClick); diff --git a/tests/E2E.NUnit.Tests/LocatorConvenience/LocatorConvenienceTests.cs b/tests/E2E.NUnit.Tests/LocatorConvenience/LocatorConvenienceTests.cs index 65b74a060..21455ac47 100644 --- a/tests/E2E.NUnit.Tests/LocatorConvenience/LocatorConvenienceTests.cs +++ b/tests/E2E.NUnit.Tests/LocatorConvenience/LocatorConvenienceTests.cs @@ -11,7 +11,8 @@ namespace E2E.NUnit.Tests.LocatorConvenience; /// locator-convenience.spec.ts). The page.<read>(selector) twins of each locator read are locator reads, and a /// :text("...") selector is GetByText. Not ported, as upstream: should have a nice preview, innerHTML should work, /// innerText should work, innerText should throw, innerText should produce log, isEditable should work, allInnerTexts should work, -/// should return page, the five description tests, and the two toString() tests (the port has none of those reads). +/// should return page, the five description tests, and the two toString() tests (the port has none of those reads); textContent should work +/// (TextContentAsync reads rendered text with whitespace normalized on purpose, where Playwright keeps the raw text). /// public sealed class LocatorConvenienceTests : PlaywrightTest { @@ -45,18 +46,6 @@ await ExpectedToFailAsync("no input", async () => }); } - // Upstream: { fail: '`textContent()` normalizes whitespace, where Playwright keeps the raw text' }. - [Test] - public async Task TextContent_should_work() - { - await ExpectedToFailAsync("more text", async () => - { - await Browser.GotoAsync("/dom.html"); - var locator = Browser.Locator("#inner"); - Equal("Text,\nmore text", await locator.TextContentAsync()); - }); - } - [Test] public async Task IsEnabled_and_isDisabled_should_work() { diff --git a/tests/E2E.NUnit.Tests/Route/PageRouteTests.cs b/tests/E2E.NUnit.Tests/Route/PageRouteTests.cs index 697bf91a7..eb9425b72 100644 --- a/tests/E2E.NUnit.Tests/Route/PageRouteTests.cs +++ b/tests/E2E.NUnit.Tests/Route/PageRouteTests.cs @@ -17,7 +17,8 @@ namespace E2E.NUnit.Tests.Route; /// should not fulfill with redirect status (WebKit only), the four tests with the times parameter (no times), /// should contain sec-fetch headers in route (no allHeaders()), should contain raw response header and /// should contain raw response header after fulfill (no request.response()), should be able to intercept every navigation -/// to a page controlled by service worker (service workers), should respect URLPattern ignoreCase (no URLPattern). +/// to a page controlled by service worker (service workers), should respect URLPattern ignoreCase (no URLPattern), should not support ? in glob pattern +/// (a ? in a route glob matches one character on purpose, where Playwright reads it literally). /// public sealed class PageRouteTests : PlaywrightTest { @@ -81,40 +82,6 @@ await Browser.RouteAsync(new Regex("empty.html"), async route => Assert.That(intercepted, Is.EqualTo(new[] { 1 })); } - [Test] - public async Task Should_not_support_question_mark_in_glob_pattern() - { - await ExpectedToFailAsync("index1hello", async () => - { - await Browser.RouteAsync(new Regex(@"/index"), async route => - { - var url = new Uri(route.Request.Url); - var body = url.AbsolutePath switch - { - "/index" => "index-no-hello", - "/index123hello" => "index123hello", - "/index1hello" => "index1hello", - _ => url.AbsolutePath[1..] + url.Query, - }; - await route.FulfillAsync(new RouteFulfillResponse { Body = body, ContentType = "text/html" }); - }); - await Browser.RouteAsync("**/index?hello", route => route.FulfillAsync(new RouteFulfillResponse { Body = "intercepted any character" })); - await Browser.RouteAsync(@"**/index\?hello", route => route.FulfillAsync(new RouteFulfillResponse { Body = "intercepted question mark" })); - - await Browser.GotoAsync($"{PREFIX}/index?hello"); - Contain("intercepted question mark", (await Browser.EvaluateAsync("document.documentElement.outerHTML"))!); - - await Browser.GotoAsync($"{PREFIX}/index"); - Contain("index-no-hello", (await Browser.EvaluateAsync("document.documentElement.outerHTML"))!); - - await Browser.GotoAsync($"{PREFIX}/index1hello"); - Contain("index1hello", (await Browser.EvaluateAsync("document.documentElement.outerHTML"))!); - - await Browser.GotoAsync($"{PREFIX}/index123hello"); - Contain("index123hello", (await Browser.EvaluateAsync("document.documentElement.outerHTML"))!); - }); - } - [Test] public async Task Should_work_when_POST_is_redirected_with_302() { diff --git a/tests/E2E.NUnit.Tests/SelectOption/PageSelectOptionTests.cs b/tests/E2E.NUnit.Tests/SelectOption/PageSelectOptionTests.cs index c6fa45ba8..31e029fe1 100644 --- a/tests/E2E.NUnit.Tests/SelectOption/PageSelectOptionTests.cs +++ b/tests/E2E.NUnit.Tests/SelectOption/PageSelectOptionTests.cs @@ -17,7 +17,8 @@ namespace E2E.NUnit.Tests.SelectOption; /// multiple is not set, should return [] on no values, should not allow null items, should unselect with null, should deselect all options /// when passed no values for a multiple select, should deselect all options when passed no values for a select without multiple, should wait /// for multiple options to be present (SelectOptionAsync takes one option, no arrays, and returns nothing); should throw if passed wrong -/// types (asserts Playwright's protocol validator messages; the option is typed). +/// types (asserts Playwright's protocol validator messages; the option is typed); should select single option (upstream selects a bare +/// string by label only on purpose; the port's also matches the value). /// public sealed partial class PageSelectOptionTests : PlaywrightTest { @@ -32,17 +33,6 @@ public sealed partial class PageSelectOptionTests : PlaywrightTest private async Task ExpectResultAsync(string name, string expected) => Assert.That(await Browser.EvaluateAsync($"() => window.result.{name}"), Is.EqualTo(new[] { expected })); - [Test] - public async Task Should_select_single_option() - { - // Upstream marks this { fail: 'a bare string selects by label only, where Playwright matches the value or the label' }; this port's - // bare string matches the value too, so the test passes without the marker. - await Browser.GotoAsync("/input/select.html"); - await Browser.Locator("select").SelectOptionAsync("blue"); - await ExpectResultAsync("onInput", "blue"); - await ExpectResultAsync("onChange", "blue"); - } - [Test] public async Task Should_select_single_option_by_value() { diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/1.png b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/1.png new file mode 100644 index 0000000000000000000000000000000000000000..6768222729b7a487d338fdd7691e44ca4604b216 GIT binary patch literal 346 zcmeAS@N?(olHy`uVBq!ia0vp^Ahr+(3y?gqul)d!Vo7)Ob!1@J*w6hZkrl{SNcITw zWnidMV_;}#VPN<`%l_%+p4TGxUMOY(Ga43W5;{O5cF=M0GtoN~YQ|NXb^`8@xj{o(qyZXTZh zNB`|_{xm~E;-A5pf9w0RzSOs614Wzvrz@>Y`EmY3PvY_a|9PY*vP4Qqs7R_vN=noT zzEz3h*rdQ|G)c~jg_Tj2N2{sHz90fFVdQ&MBb@0M_4YL;wH) literal 0 HcmV?d00001 diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/2.png b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/2.png new file mode 100644 index 0000000000000000000000000000000000000000..b1daa4735d8a8c8dcce6be0fc2db02beb265860b GIT binary patch literal 413 zcmeAS@N?(olHy`uVBq!ia0vp^Ahr+(3y?gqul)d!Vo7)Ob!1@J*w6hZkrl{SNcITw zWnidMV_;}#VPN<`%l_%$`QSZ$aB6k6)(;us=vdFljxE~Y{OxBK}UC0Lr@F!n?rT`(_E{}JO6 z<{7z73T*rf7DVR9aWl3E8iRZQbg$2f$a-VDO8#vl&KeD#DWG<1jqwYkJ(8lLS zB4RWT1dM<5ebWu_3N}u7Cea|(Ea3RP_Gw+vkLTX@hooODEC@-v@oNsy!Kx*$5hW>! zC8<`)MX5lF!N|bST-U%%*U&7)(A3Jr(8|O>*TCG$z`$)w_#PAux%nxXX_dG&n7@1v QRL{WR>FVdQ&MBb@0Eyv<`%l_%$`QSZ$aB6x!wK;us=vdFq6XS%(-TTK3zgoV~U1u8i>$)?1-gCGWI< z@aS2U3)ZwcEm*ubc;$ti-mV3rF6`=#s{>A4SDeUI_Oe&LoV{Fey4Mfsycbe!vf}Dh z3k0h9j%Z)+Fc6$CIUO_QmvAUQh^kMk%6JPu7R1Zp;?Hbsg;SLm5G6_ nfw`4|f!mhwJt!J-^HVa@DsgKtfB7D$o`J#B)z4*}Q$iB}nZcB~ literal 0 HcmV?d00001 diff --git a/tests/E2E.NUnit.Tests/WaitForResponse/PageWaitForResponseTests.cs b/tests/E2E.NUnit.Tests/WaitForResponse/PageWaitForResponseTests.cs new file mode 100644 index 000000000..68a598021 --- /dev/null +++ b/tests/E2E.NUnit.Tests/WaitForResponse/PageWaitForResponseTests.cs @@ -0,0 +1,63 @@ +// 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.WaitForResponse; + +/// +/// test.describe('page wait for response') of upstream's apps/testbed/tests/wait-for-response.e2e.ts (Playwright's +/// page-wait-for-response.spec.ts). Not ported, as upstream: should respect timeout (needs page.waitForEvent('response')), +/// should respect default timeout (needs page.setDefaultTimeout and a predicate), should work with predicate, should work with +/// async predicate, and sync predicate should be only called once (no response predicates). +/// +public sealed class PageWaitForResponseTests : PlaywrightTest +{ + private static string EmptyPage => $"{PREFIX}/empty.html"; + + [Test] + public async Task Should_work() + { + await Browser.GotoAsync(EmptyPage); + var response = await AllAsync( + Browser.WaitForResponseAsync($"{PREFIX}/digits/2.png"), + Browser.EvaluateAsync(""" + () => { + void fetch('/digits/1.png'); + void fetch('/digits/2.png'); + void fetch('/digits/3.png'); + } + """)); + Assert.That(response.Url, Is.EqualTo($"{PREFIX}/digits/2.png")); + } + + // Partial: the timeout error here is Playwright's own, which does not name the pattern, where upstream's names "foo.css" and /foo.css/i. So + // it checks that both patterns time out, not that the message logs the url. + [Test] + public async Task Partial_Should_log_the_url() + { + await Browser.GotoAsync(EmptyPage); + var error1 = await Assert.CatchAsync(() => Browser.WaitForResponseAsync("foo.css", TimeSpan.FromSeconds(1))); + Assert.That(error1!.Message, Does.Contain("Timeout 1000ms exceeded")); + var error2 = await Assert.CatchAsync(() => Browser.WaitForResponseAsync(new Regex("foo.css", RegexOptions.IgnoreCase), TimeSpan.FromSeconds(1))); + Assert.That(error2!.Message, Does.Contain("Timeout 1000ms exceeded")); + } + + [Test] + public async Task Should_work_with_no_timeout() + { + await Browser.GotoAsync(EmptyPage); + var response = await AllAsync( + Browser.WaitForResponseAsync($"{PREFIX}/digits/2.png", TimeSpan.Zero), + Browser.EvaluateAsync(""" + () => setTimeout(() => { + void fetch('/digits/1.png'); + void fetch('/digits/2.png'); + void fetch('/digits/3.png'); + }, 50) && null + """)); + Assert.That(response.Url, Is.EqualTo($"{PREFIX}/digits/2.png")); + } +} diff --git a/tests/E2E.Tests/ExpectPoll/ExpectPollTests.cs b/tests/E2E.Tests/ExpectPoll/ExpectPollTests.cs index 3b3d7c178..576266315 100644 --- a/tests/E2E.Tests/ExpectPoll/ExpectPollTests.cs +++ b/tests/E2E.Tests/ExpectPoll/ExpectPollTests.cs @@ -129,6 +129,17 @@ public void Refuses_a_timeout_or_interval_that_could_never_expire_before_the_fir Expect.Poll(() => 1, new PollOptions { Timeout = TimeSpan.Zero, Interval = TimeSpan.FromMilliseconds(1) }); } + // Partial: the port has no attempt, and a poll's phase is the caller's cancellation token, so a token that cannot end stands for outside a test. + [Fact] + public async Task Partial_Refuses_timeout_0_outside_an_attempt_where_no_test_deadline_bounds_it() + { + var error = await Assert.ThrowsAsync(() => + Expect.Poll(() => "running", new PollOptions { Timeout = TimeSpan.Zero }).ToBeAsync("done")); + + Assert.Equal("INVALID_CONFIG", error.Code); + Assert.Contains("needs a cancellation token that ends with the test", error.Message, StringComparison.Ordinal); + } + private PollOptions Every(int milliseconds) => new() { Interval = TimeSpan.FromMilliseconds(milliseconds), Clock = _time }; private PollOptions Options(int timeout, int interval) => diff --git a/tests/E2E.Tests/ExpectPoll/InsideAnAttemptTests.cs b/tests/E2E.Tests/ExpectPoll/InsideAnAttemptTests.cs index 0fa33fb22..9748659e2 100644 --- a/tests/E2E.Tests/ExpectPoll/InsideAnAttemptTests.cs +++ b/tests/E2E.Tests/ExpectPoll/InsideAnAttemptTests.cs @@ -33,6 +33,20 @@ public async Task Stops_reading_the_moment_the_attempt_is_cancelled() Assert.Equal(readsAtCancel, reads); } + // Partial: the port's attempt deadline is its cancellation token, which ends the poll as a cancel, not as "stopped at the attempt deadline". + [Fact] + public async Task Partial_Polls_with_timeout_0_past_the_assertion_timeout_until_the_attempt_deadline() + { + using var cancel = new CancellationTokenSource(); + var options = new PollOptions { Timeout = TimeSpan.Zero, Interval = TimeSpan.FromMilliseconds(10) }; + cancel.CancelAfter(TimeSpan.FromMilliseconds(150)); + var started = DateTimeOffset.UtcNow; + + await Assert.ThrowsAnyAsync(() => Expect.Poll(() => "running", options).ToBeAsync("done", cancel.Token)); + + Assert.True(DateTimeOffset.UtcNow - started >= TimeSpan.FromMilliseconds(140)); + } + [Fact] public async Task Cuts_a_read_in_flight_when_the_attempt_is_cancelled() { diff --git a/tests/E2E.Tests/LocatorEngine/LocatorEngineStepDeadlineTests.cs b/tests/E2E.Tests/LocatorEngine/LocatorEngineStepDeadlineTests.cs new file mode 100644 index 000000000..57b7f2c9a --- /dev/null +++ b/tests/E2E.Tests/LocatorEngine/LocatorEngineStepDeadlineTests.cs @@ -0,0 +1,47 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using E2E.Engine; +using E2E.Internal; + +namespace E2E.Tests.LocatorEngine; + +/// +/// Upstream's describe('LocatorEngine step deadline') (tests/unit/locator-engine.test.ts). Not ported: "keeps an operation +/// budget of 0 an expired one", because the port has no operation(timeoutMs); its engine calls take a budget. +/// "Refuses a negative, NaN, or infinite timeout before resolving" is partial: a cannot be NaN or infinite. +/// +public sealed class LocatorEngineStepDeadlineTests +{ + [Fact] + public async Task Waits_past_the_action_timeout_with_timeout_0_until_the_phase_deadline() + { + var phase = new Deadline(TimeSpan.FromMilliseconds(600), TimeProvider.System); + var scripted = ScriptedLocatorEngine.Make(Enumerable.Repeat(ScriptedLocatorEngine.Nodes(), 50), actionTimeout: TimeSpan.FromMilliseconds(100)); + scripted.Engine.BudgetDeadline = phase; + + Assert.Equal(phase.EndsAt, scripted.Engine.DeadlineFor(TimeSpan.Zero).EndsAt); + var started = DateTimeOffset.UtcNow; + var error = await Assert.ThrowsAsync(() => scripted.Engine.PerformAsync( + ScriptedLocatorEngine.Expression, (_, _) => Task.FromResult(new LocatorAction.Tap()), TimeSpan.Zero, CancellationToken.None)); + + Assert.Equal("LOCATOR_NOT_FOUND", error.Code); + Assert.True(DateTimeOffset.UtcNow - started >= TimeSpan.FromMilliseconds(550)); + } + + [Fact] + public async Task Partial_Refuses_a_negative_NaN_or_infinite_timeout_before_resolving() + { + var scripted = ScriptedLocatorEngine.Make(); + + foreach (var timeout in new[] { TimeSpan.FromMilliseconds(-1), Timeout.InfiniteTimeSpan }) + { + var error = await Assert.ThrowsAsync(() => scripted.Engine.PerformAsync( + ScriptedLocatorEngine.Expression, (_, _) => Task.FromResult(new LocatorAction.Tap()), timeout, CancellationToken.None)); + Assert.Equal("INVALID_ARGUMENT", error.Code); + } + + Assert.Equal(0, scripted.Resolves); + } +} diff --git a/tests/E2E.Tests/Routes/BrowserRouteDecisionsTests.cs b/tests/E2E.Tests/Routes/BrowserRouteDecisionsTests.cs index 784d62044..861f3414a 100644 --- a/tests/E2E.Tests/Routes/BrowserRouteDecisionsTests.cs +++ b/tests/E2E.Tests/Routes/BrowserRouteDecisionsTests.cs @@ -78,6 +78,25 @@ await routes.Browser.RouteAsync("**/redirect", async route => // Not portable, because the C# signature refuses them at compile time (upstream's tests/types/downloads.ts): a batch with no count, // and a trigger that is not asynchronous. + // Partial: upstream hands a recording operation the timeouts and checks the budgets it was asked for (Infinity for 0). The port has no + // operation to record, so this runs real calls: 0 waits for the test deadline instead of failing, and a negative timeout is refused. + [Fact] + public Task Partial_Hands_timeout_0_to_the_operation_as_a_budget_only_the_test_deadline_caps_and_refuses_a_negative_one() => WithRoutesAsync(async routes => + { + await routes.Browser.GotoAsync(routes.Site.Origin + "/", new GotoOptions { Timeout = TimeSpan.Zero }); + await routes.Browser.WaitForURLAsync(routes.Site.Origin + "/", TimeSpan.Zero); + var negative = TimeSpan.FromMilliseconds(-1); + foreach (var call in new Func[] + { + () => routes.Browser.GotoAsync(routes.Site.Origin + "/", new GotoOptions { Timeout = negative }), + () => routes.Browser.WaitForURLAsync(routes.Site.Origin + "/", negative), + () => routes.Browser.WaitForDownloadAsync(() => Task.CompletedTask, negative), + }) + { + Assert.Equal("INVALID_ARGUMENT", (await Assert.ThrowsAsync(call)).Code); + } + }); + [Fact] public Task Rejects_an_invalid_download_count_before_running_the_trigger() => WithRoutesAsync(async routes => { diff --git a/tests/E2E.Tests/ScreenshotAssertions/ToHaveScreenshotTests.cs b/tests/E2E.Tests/ScreenshotAssertions/ToHaveScreenshotTests.cs index 55b41ff21..63aa60326 100644 --- a/tests/E2E.Tests/ScreenshotAssertions/ToHaveScreenshotTests.cs +++ b/tests/E2E.Tests/ScreenshotAssertions/ToHaveScreenshotTests.cs @@ -110,7 +110,7 @@ public async Task Tolerates_the_differences_its_options_allow_and_not_passes_on_ using var project = new ScreenProject(engine); static async Task Body(Screen screen) { - await Expect.That(screen).ToHaveScreenshotAsync("home", new ScreenshotOptions { MaxDiffPixels = 800, Timeout = OneSecond }); + await Expect.That(screen).ToHaveScreenshotAsync("home", new ScreenshotOptions { MaxDiffPixels = 800, Timeout = TimeSpan.Zero }); await Expect.That(screen).ToHaveScreenshotAsync("home", new ScreenshotOptions { MaxDiffPixelRatio = 0.001, Timeout = OneSecond }); await Expect.That(screen).Not.ToHaveScreenshotAsync("home", Quick); } @@ -345,6 +345,10 @@ public Task Refuses_a_name_with_a_path_separator_before_it_reads_the_screen() => public Task Refuses_a_threshold_above_1_before_it_reads_the_screen() => RefusesBeforeItReadsTheScreen("home", new ScreenshotOptions { Threshold = 2 }, "threshold must be a number from 0 to 1"); + [Fact] + public Task Refuses_a_negative_timeout_before_it_reads_the_screen() => + RefusesBeforeItReadsTheScreen("home", new ScreenshotOptions { Timeout = TimeSpan.FromMilliseconds(-1) }, "timeout must be a finite number of milliseconds, 0 or more"); + [Fact] public Task Refuses_a_mask_that_is_not_a_locator_before_it_reads_the_screen() => RefusesBeforeItReadsTheScreen("home", new ScreenshotOptions { Mask = [null!] }, "mask must be an array of locators"); diff --git a/tests/E2E.Tests/Time/CheckStepTimeoutTests.cs b/tests/E2E.Tests/Time/CheckStepTimeoutTests.cs new file mode 100644 index 000000000..9366b39ed --- /dev/null +++ b/tests/E2E.Tests/Time/CheckStepTimeoutTests.cs @@ -0,0 +1,51 @@ +// Copyright 2026 TesterArmy. +// Modified by Dario Kondratiuk. +// SPDX-License-Identifier: Apache-2.0 + +using E2E.Internal; +using Microsoft.Extensions.Time.Testing; +using InternalTime = E2E.Internal.Time; + +namespace E2E.Tests.Time; + +/// +/// Upstream's describe('checkStepTimeout') (tests/unit/time.test.ts). A is always a finite number of +/// milliseconds, so NaN, infinite, and non-number timeouts cannot be written, and "refuses negative, NaN, infinite, and non-number timeouts" +/// is partial. "Gives withTimeout no timer for the infinite budget of 0" is not ported: the port has no withTimeout. +/// +public sealed class CheckStepTimeoutTests +{ + [Fact] + public void Takes_no_timeout_0_and_finite_positive_milliseconds() + { + foreach (var timeout in new TimeSpan?[] { null, TimeSpan.Zero, TimeSpan.FromMilliseconds(1), TimeSpan.FromMilliseconds(2.5), TimeSpan.FromMilliseconds(60_000) }) + { + InternalTime.CheckStepTimeout(timeout, "tap"); + } + } + + [Fact] + public void Partial_Refuses_negative_NaN_infinite_and_non_number_timeouts_as_INVALID_ARGUMENT() + { + foreach (var timeout in new[] { TimeSpan.FromMilliseconds(-1), Timeout.InfiniteTimeSpan }) + { + var error = Assert.Throws(() => InternalTime.CheckStepTimeout(timeout, "tap")); + Assert.Equal("INVALID_ARGUMENT", error.Code); + Assert.Contains("tap timeout", error.Message, StringComparison.Ordinal); + } + } + + [Fact] + public void Partial_Turns_0_into_a_deadline_only_the_phase_caps() + { + var clock = new FakeTimeProvider(); + var phase = new Deadline(TimeSpan.FromMilliseconds(1000), clock); + var fallback = TimeSpan.FromMilliseconds(30); + + Assert.Same(phase, InternalTime.StepDeadline(TimeSpan.Zero, "tap", fallback, phase, clock)); + Assert.Equal(clock.GetUtcNow().AddMilliseconds(250), InternalTime.StepDeadline(TimeSpan.FromMilliseconds(250), "tap", fallback, phase, clock).EndsAt); + Assert.Equal(clock.GetUtcNow().AddMilliseconds(30), InternalTime.StepDeadline(null, "tap", fallback, phase, clock).EndsAt); + Assert.Equal(TimeSpan.FromMilliseconds(1000), InternalTime.StepBudget(TimeSpan.Zero, "tap", fallback, phase, clock)); + Assert.Equal(InternalTime.Never, InternalTime.StepDeadline(TimeSpan.Zero, "tap", fallback, null, clock).EndsAt); + } +} From 95bd56ade6cfa0b9c26ee16829dfbe8ec9800c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Thu, 5 Nov 2026 11:03:38 -0300 Subject: [PATCH 2/3] Build every action deadline from the step rule, and document WaitForURL timeout 0 Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- src/E2E/Locator/LocatorEngine.cs | 8 ++++---- src/E2E/Run/Browser.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/E2E/Locator/LocatorEngine.cs b/src/E2E/Locator/LocatorEngine.cs index 74a6ad4e3..9ee4fbfdf 100644 --- a/src/E2E/Locator/LocatorEngine.cs +++ b/src/E2E/Locator/LocatorEngine.cs @@ -435,14 +435,14 @@ internal async Task ResolveExactlyOneAsync(LocatorExpression expre internal async Task PerformAsync(LocatorExpression expression, Func> build, TimeSpan? timeout, CancellationToken token, bool anyState = false) { var started = Clock.GetUtcNow(); - var deadline = started + TimeoutOf(timeout); + var window = DeadlineFor(timeout); + var deadline = window.EndsAt; var startedAt = DateTimeOffset.UtcNow; var stamp = Stopwatch.GetTimestamp(); // Each resolve counts its own rounds and wait, as upstream's resolveCounted does: a stale retry starts them over. var resolveStamp = stamp; var rounds = 0; var stale = 0; - var window = new Deadline(deadline); var reads = Reads(window); while (true) { @@ -556,7 +556,7 @@ internal async Task PerformUntilAsync(LocatorExpression expression, LocatorActio internal async Task PerformAtAsync(Point point, PointerAction action, TimeSpan? timeout, CancellationToken token) { CheckPointerAction(action); - await DispatchAtAsync(point, action, new Deadline(TimeoutOf(timeout), Clock), token).ConfigureAwait(false); + await DispatchAtAsync(point, action, DeadlineFor(timeout), token).ConfigureAwait(false); } /// @@ -567,7 +567,7 @@ internal async Task PerformAtAsync(Point point, PointerAction action, TimeSpan? internal async Task PerformWithinAsync(LocatorExpression expression, Point offset, PointerAction action, TimeSpan? timeout, CancellationToken token) { CheckPointerAction(action); - var deadline = new Deadline(TimeoutOf(timeout), Clock); + var deadline = DeadlineFor(timeout); var started = Clock.GetTimestamp(); if (ActionKinds is not { } declared || declared.Contains("scrollIntoView")) { diff --git a/src/E2E/Run/Browser.cs b/src/E2E/Run/Browser.cs index 1d5374648..c2f754b89 100644 --- a/src/E2E/Run/Browser.cs +++ b/src/E2E/Run/Browser.cs @@ -137,7 +137,7 @@ public Task TitleAsync(CancellationToken cancellationToken = default) => /// /// Waits until the current URL equals , resolved /// against the base URL, as . - /// The default timeout is the assertion timeout. + /// The default timeout is the assertion timeout; zero waits for the test timeout. /// public Task WaitForURLAsync(string url, TimeSpan? timeout = null, CancellationToken cancellationToken = default) { @@ -149,7 +149,7 @@ public Task WaitForURLAsync(string url, TimeSpan? timeout = null, CancellationTo }, verifies: true); } - /// Waits until the current URL matches . The default timeout is the assertion timeout. + /// Waits until the current URL matches . The default timeout is the assertion timeout; zero waits for the test timeout. public Task WaitForURLAsync(Regex pattern, TimeSpan? timeout = null, CancellationToken cancellationToken = default) { ArgumentNullException.ThrowIfNull(pattern); From 52d9f13fe0879713f7f90da641387788bb29e83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Thu, 5 Nov 2026 11:04:45 -0300 Subject: [PATCH 3/3] Leave the wait-for-response tests to the network branch Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- .../Testbed/playwright/assets/digits/1.png | Bin 346 -> 0 bytes .../Testbed/playwright/assets/digits/2.png | Bin 413 -> 0 bytes .../Testbed/playwright/assets/digits/3.png | Bin 434 -> 0 bytes .../PageWaitForResponseTests.cs | 63 ------------------ 4 files changed, 63 deletions(-) delete mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/1.png delete mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/2.png delete mode 100644 tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/3.png delete mode 100644 tests/E2E.NUnit.Tests/WaitForResponse/PageWaitForResponseTests.cs diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/1.png b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/1.png deleted file mode 100644 index 6768222729b7a487d338fdd7691e44ca4604b216..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 346 zcmeAS@N?(olHy`uVBq!ia0vp^Ahr+(3y?gqul)d!Vo7)Ob!1@J*w6hZkrl{SNcITw zWnidMV_;}#VPN<`%l_%+p4TGxUMOY(Ga43W5;{O5cF=M0GtoN~YQ|NXb^`8@xj{o(qyZXTZh zNB`|_{xm~E;-A5pf9w0RzSOs614Wzvrz@>Y`EmY3PvY_a|9PY*vP4Qqs7R_vN=noT zzEz3h*rdQ|G)c~jg_Tj2N2{sHz90fFVdQ&MBb@0M_4YL;wH) diff --git a/tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/2.png b/tests/E2E.NUnit.Tests/Testbed/playwright/assets/digits/2.png deleted file mode 100644 index b1daa4735d8a8c8dcce6be0fc2db02beb265860b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 413 zcmeAS@N?(olHy`uVBq!ia0vp^Ahr+(3y?gqul)d!Vo7)Ob!1@J*w6hZkrl{SNcITw zWnidMV_;}#VPN<`%l_%$`QSZ$aB6k6)(;us=vdFljxE~Y{OxBK}UC0Lr@F!n?rT`(_E{}JO6 z<{7z73T*rf7DVR9aWl3E8iRZQbg$2f$a-VDO8#vl&KeD#DWG<1jqwYkJ(8lLS zB4RWT1dM<5ebWu_3N}u7Cea|(Ea3RP_Gw+vkLTX@hooODEC@-v@oNsy!Kx*$5hW>! zC8<`)MX5lF!N|bST-U%%*U&7)(A3Jr(8|O>*TCG$z`$)w_#PAux%nxXX_dG&n7@1v QRL{WR>FVdQ&MBb@0Eyv<`%l_%$`QSZ$aB6x!wK;us=vdFq6XS%(-TTK3zgoV~U1u8i>$)?1-gCGWI< z@aS2U3)ZwcEm*ubc;$ti-mV3rF6`=#s{>A4SDeUI_Oe&LoV{Fey4Mfsycbe!vf}Dh z3k0h9j%Z)+Fc6$CIUO_QmvAUQh^kMk%6JPu7R1Zp;?Hbsg;SLm5G6_ nfw`4|f!mhwJt!J-^HVa@DsgKtfB7D$o`J#B)z4*}Q$iB}nZcB~ diff --git a/tests/E2E.NUnit.Tests/WaitForResponse/PageWaitForResponseTests.cs b/tests/E2E.NUnit.Tests/WaitForResponse/PageWaitForResponseTests.cs deleted file mode 100644 index 68a598021..000000000 --- a/tests/E2E.NUnit.Tests/WaitForResponse/PageWaitForResponseTests.cs +++ /dev/null @@ -1,63 +0,0 @@ -// 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.WaitForResponse; - -/// -/// test.describe('page wait for response') of upstream's apps/testbed/tests/wait-for-response.e2e.ts (Playwright's -/// page-wait-for-response.spec.ts). Not ported, as upstream: should respect timeout (needs page.waitForEvent('response')), -/// should respect default timeout (needs page.setDefaultTimeout and a predicate), should work with predicate, should work with -/// async predicate, and sync predicate should be only called once (no response predicates). -/// -public sealed class PageWaitForResponseTests : PlaywrightTest -{ - private static string EmptyPage => $"{PREFIX}/empty.html"; - - [Test] - public async Task Should_work() - { - await Browser.GotoAsync(EmptyPage); - var response = await AllAsync( - Browser.WaitForResponseAsync($"{PREFIX}/digits/2.png"), - Browser.EvaluateAsync(""" - () => { - void fetch('/digits/1.png'); - void fetch('/digits/2.png'); - void fetch('/digits/3.png'); - } - """)); - Assert.That(response.Url, Is.EqualTo($"{PREFIX}/digits/2.png")); - } - - // Partial: the timeout error here is Playwright's own, which does not name the pattern, where upstream's names "foo.css" and /foo.css/i. So - // it checks that both patterns time out, not that the message logs the url. - [Test] - public async Task Partial_Should_log_the_url() - { - await Browser.GotoAsync(EmptyPage); - var error1 = await Assert.CatchAsync(() => Browser.WaitForResponseAsync("foo.css", TimeSpan.FromSeconds(1))); - Assert.That(error1!.Message, Does.Contain("Timeout 1000ms exceeded")); - var error2 = await Assert.CatchAsync(() => Browser.WaitForResponseAsync(new Regex("foo.css", RegexOptions.IgnoreCase), TimeSpan.FromSeconds(1))); - Assert.That(error2!.Message, Does.Contain("Timeout 1000ms exceeded")); - } - - [Test] - public async Task Should_work_with_no_timeout() - { - await Browser.GotoAsync(EmptyPage); - var response = await AllAsync( - Browser.WaitForResponseAsync($"{PREFIX}/digits/2.png", TimeSpan.Zero), - Browser.EvaluateAsync(""" - () => setTimeout(() => { - void fetch('/digits/1.png'); - void fetch('/digits/2.png'); - void fetch('/digits/3.png'); - }, 50) && null - """)); - Assert.That(response.Url, Is.EqualTo($"{PREFIX}/digits/2.png")); - } -}