Repository navigation
Migrate Components.Testing from xUnit v3 to MSTest on MTP - #67083
Conversation
241d42c to
5b1deb2
Compare
166eb27 to
4088cb2
Compare
There was a problem hiding this comment.
Pull request overview
This PR migrates the Blazor Components E2E testing infrastructure under src/Components/Testing from xUnit v3 + Microsoft.Playwright.Xunit.v3 to MSTest 4.x running on the Microsoft Testing Platform (MTP), while updating the public testing APIs and testassets accordingly.
Changes:
- Replaces xUnit fixture-based server lifecycle with
ServerFactory<T>and adds MSTest-oriented attachment/tracing helpers. - Introduces MSTest-compatible Playwright base classes (
PlaywrightTest/BrowserTest/ContextTest/PageTest) and updatesTestApp.E2E.Teststo MSTest attributes and setup/teardown. - Updates repo dependency metadata (
eng/) and reference-resolution rules to support MSTest buildTransitive behavior.
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Components/Testing/testassets/TestApp.E2E.Tests/Tests/WeatherServiceOverrideTests.cs | Migrates test class to MSTest lifecycle + server output attachment on failure. |
| src/Components/Testing/testassets/TestApp.E2E.Tests/Tests/TracingTests.cs | Updates tracing tests to use explicit MSTest TestContext plumbing + new traced-context APIs. |
| src/Components/Testing/testassets/TestApp.E2E.Tests/Tests/RenderModeTests.cs | Converts render-mode coverage tests to MSTest and new browser/context creation pattern. |
| src/Components/Testing/testassets/TestApp.E2E.Tests/Tests/PrerenderingTests.cs | Converts prerendering tests to MSTest and new server startup pattern. |
| src/Components/Testing/testassets/TestApp.E2E.Tests/Tests/HomePageTests.cs | Converts basic navigation tests to MSTest and new server startup pattern. |
| src/Components/Testing/testassets/TestApp.E2E.Tests/Tests/EnhancedNavTests.cs | Converts enhanced navigation tests to MSTest and new server startup pattern. |
| src/Components/Testing/testassets/TestApp.E2E.Tests/Tests/AsyncStateTests.cs | Converts async-state/lock tests to MSTest and new server startup pattern. |
| src/Components/Testing/testassets/TestApp.E2E.Tests/TestApp.E2E.Tests.csproj | Switches test host to MTP runner + MSTest references and pinned adapter package reference. |
| src/Components/Testing/testassets/TestApp.E2E.Tests/Fixtures/TestRoot.cs | Adds assembly-level initialization/cleanup owner for ServerFactory<E2ETestAssembly>. |
| src/Components/Testing/testassets/TestApp.E2E.Tests/Fixtures/E2ECollection.cs | Removes xUnit collection fixture definition. |
| src/Components/Testing/test/Microsoft.AspNetCore.Components.Testing.Tests.csproj | Avoids MSTest implicit-using collisions in xUnit unit tests; allows reference-resolution exceptions. |
| src/Components/Testing/test/GlobalUsings.cs | Adds explicit System.* global usings after disabling implicit usings. |
| src/Components/Testing/src/PublicAPI.Unshipped.txt | Updates unshipped API surface for new MSTest/Playwright and server APIs. |
| src/Components/Testing/src/Playwright/PlaywrightTest.cs | Adds MSTest-friendly Playwright base with shared IPlaywright and Expect helpers. |
| src/Components/Testing/src/Playwright/BrowserTest.cs | Adds shared IBrowser + per-test context tracking/cleanup for MSTest. |
| src/Components/Testing/src/Playwright/ContextTest.cs | Adds per-test IBrowserContext base built on BrowserTest. |
| src/Components/Testing/src/Playwright/PageTest.cs | Adds per-test IPage base built on ContextTest. |
| src/Components/Testing/src/Microsoft.AspNetCore.Components.Testing.csproj | Updates package description/tags and references to MSTest/MTP-era dependencies. |
| src/Components/Testing/src/Infrastructure/TracingSession.cs | Switches tracing outcome determination to MSTest TestContext + result-file attachment. |
| src/Components/Testing/src/Infrastructure/TracedContext.cs | Fixes context-ownership semantics so contexts created by helpers are always disposed. |
| src/Components/Testing/src/Infrastructure/ServerStartOptions.cs | Updates docs and adds RecycleOnRetry option tied to MTP retry env-var. |
| src/Components/Testing/src/Infrastructure/ServerInstance.cs | Adds captured output buffering APIs and file emission helpers. |
| src/Components/Testing/src/Infrastructure/ServerFactory.cs | Renames/re-frames xUnit fixture into consumer-owned factory/registry; updates docs. |
| src/Components/Testing/src/Infrastructure/ServerAttachmentExtensions.cs | Adds MSTest TestContext extension to attach server stdout/stderr to TRX. |
| src/Components/Testing/src/Infrastructure/PlaywrightExtensions.cs | Replaces xUnit-centric tracing APIs with MSTest TestContext-explicit overloads. |
| src/Components/Testing/src/Infrastructure/PlaywrightAttachmentExtensions.cs | Adds screenshot + browser-console attachment helpers using TestContext.AddResultFile. |
| eng/Versions.props | Introduces MSTest/MTP version properties; removes Playwright xUnit v3 version. |
| eng/Dependencies.props | Tracks MSTest/MTP packages as repo “latest package references” for dependency management. |
| eng/targets/ResolveReferences.targets | Adjusts reference-resolution erroring to allow injected references that carry a HintPath. |
Comments suppressed due to low confidence (2)
src/Components/Testing/src/Infrastructure/ServerFactory.cs:57
- The XML doc sample references
Microsoft.Playwright.MSTest.PageTest, but this library explicitly avoids taking that dependency and ships its ownMicrosoft.AspNetCore.Components.Testing.Playwright.PageTest. The sample should point to the in-box base type so consumers don’t copy/paste a broken example.
src/Components/Testing/src/Infrastructure/ServerFactory.cs:40 - The usage snippet declares
TestRootas astatic[TestClass]. MSTest discovery/assembly init hooks require a non-static test class, so the example should avoidstatichere (the members can remain static).
| // Microsoft.AspNetCore.Components.Testing.Playwright.BrowserTest (or its derivatives), | ||
| // which manage the shared IPlaywright + IBrowser themselves. | ||
| [TestClass] | ||
| public static class TestRoot |
| var context = await NewContext(new BrowserNewContextOptions().WithServerRouting(_server)); | ||
| _page = await context.NewPageAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| [TestCleanup] | ||
| public void AttachServerOutput() => TestContext.AttachServerOutputIfFailed(_server); |
| var context = await NewContext(new BrowserNewContextOptions().WithServerRouting(_server)); | ||
| _page = await context.NewPageAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| [TestCleanup] | ||
| public void AttachServerOutput() => TestContext.AttachServerOutputIfFailed(_server); |
| _server = await _fixture.StartServerAsync<App>(); | ||
| } | ||
| [TestCleanup] | ||
| public void AttachServerOutput() => TestContext.AttachServerOutputIfFailed(_server); |
| { | ||
| options.ConfigureServices<TestOverrides>(nameof(TestOverrides.FakeWeather)); | ||
| }); | ||
| var context = await NewContext(new BrowserNewContextOptions().WithServerRouting(_server)); | ||
| _page = await context.NewPageAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| [TestCleanup] | ||
| public void AttachServerOutput() => TestContext.AttachServerOutputIfFailed(_server); |
| var context = await NewContext(new BrowserNewContextOptions().WithServerRouting(_server)); | ||
| _page = await context.NewPageAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| [TestCleanup] | ||
| public void AttachServerOutput() => TestContext.AttachServerOutputIfFailed(_server); |
| { | ||
| options.ConfigureServices<TestOverrides>(nameof(TestOverrides.LockableWeather)); | ||
| }); | ||
| } | ||
|
|
||
| [Fact] | ||
| [TestCleanup] | ||
| public void AttachServerOutput() => TestContext.AttachServerOutputIfFailed(_server); |
| _server = await _fixture.StartServerAsync<App>(); | ||
| } | ||
| [TestCleanup] | ||
| public void AttachServerOutput() => TestContext.AttachServerOutputIfFailed(_server); |
|
@javiercn please feel free to ping me if you need help with finishing this PR! |
Rename ServerFixture<T> -> ServerFactory<T> (it is a factory + registry of
ServerInstances in front of one YARP proxy, no longer an xUnit fixture).
Drop the IAsyncLifetime base; public InitializeAsync / DisposeAsync /
StartServerAsync surface is unchanged.
Replace the ambient xUnit TestContext.Current reads with explicit MSTest
TestContext parameters on TracingSession.StartAsync and the two
NewTracedContextAsync overloads. The xUnit-typed extension over
Microsoft.Playwright.Xunit.v3.BrowserTest is removed; new overloads target
Microsoft.Playwright IBrowser and IBrowserContext, each taking a TestContext
explicitly.
Add new helpers for the MSTest world:
* TracedContext now owns the IBrowserContext when it created it (the
IBrowser overload of NewTracedContextAsync) and closes it on dispose so
the previously-implicit BrowserTest.NewContext tracking is not needed.
* ServerInstance.WriteCapturedOutputTo / Get{Stdout,Stderr}Since /
*BufferLength expose per-test slices of captured app output.
* ServerStartOptions.RecycleOnRetry opts a launch into a fresh process on
test retries.
* ServerAttachmentExtensions.AttachServerOutputIfFailed flushes the
captured stdout/stderr for given ServerInstances and routes them through
TestContext.AddResultFile when the test failed.
* PlaywrightAttachmentExtensions.AttachScreenshotAsync /
CaptureBrowserConsole provide per-test screenshot and browser-console
attachment helpers, both taking TestContext explicitly.
Ship MTP defaults in the package's buildTransitive props:
EnableMSTestRunner=true, OutputType=Exe, MSTestRunCommandLineArguments=
--timeout 15m --maximum-failed-tests 25 --minimum-expected-tests 1
--report-trx.
Migrate the TestApp.E2E.Tests test asset: replace the xUnit collection
fixture with a TestRoot static class driving [AssemblyInitialize] /
[AssemblyCleanup] and owning ServerFactory + IPlaywright + IBrowser; rewrite
all seven test classes from [Collection] / BrowserTest / [Fact] to
[TestClass] / [TestInitialize] (creating an IBrowserContext per test) /
[TestCleanup] (disposing the context and calling
TestContext.AttachServerOutputIfFailed) / [TestMethod].
Update eng/Versions.props and eng/Dependencies.props: add MSTest.TestFramework
4.0.2, Microsoft.Testing.Platform.MSBuild 2.0.2, and
Microsoft.Testing.Extensions.Retry 2.0.2; drop Microsoft.Playwright.Xunit.v3.
The MSTest.TestAdapter is referenced directly as a PackageReference in the
test asset (with NETSDK1023 suppressed) so its version stays in lockstep
with MSTest.TestFramework.
Three subtleties worth noting in the csproj layer:
* Microsoft.Playwright.MSTest 1.60 is not used: it ships a BrowserTest
typed against MSTest 2.x, which is binary-incompatible with MSTest 4.x.
Test classes create their IBrowser themselves and pass it to
NewTracedContextAsync; no PageTest / BrowserTest base class is needed.
* DisablePackageReferenceRestrictions=true is set on the library, the
test asset, and the library unit tests so that the
MSTest.TestFramework.Extensions Reference (injected with a HintPath by
MSTest.TestFramework's buildTransitive .targets) is not rejected by the
aspnetcore custom reference-resolver.
* The library unit tests stay on xUnit. <ImplicitUsings>disable</> +
explicit System.* entries in GlobalUsings.cs avoid the MSTest analyzer's
implicit global using clashing with `using Xunit;` (Assert / TestContext).
PublicAPI.Unshipped.txt is rewritten to reflect the new public surface.
Verified: library + library tests + test asset all build clean (0/0); all
88 library xUnit unit tests pass; MTP discovers the 23 migrated MSTest
tests in the test asset.
Co-authored-by: Copilot <[email protected]>
Add PlaywrightTest, BrowserTest, ContextTest, and PageTest under
Microsoft.AspNetCore.Components.Testing.Playwright, providing the same
ergonomics as Microsoft.Playwright.MSTest's base classes (shared IPlaywright
and IBrowser per assembly, per-test NewContext tracking, Expect helpers)
without taking a dependency on that package — Microsoft.Playwright.MSTest
1.60 still ships against MSTest 2.x, which is binary-incompatible with the
MSTest 4.x runtime this library targets.
Behavior matches the upstream pattern:
* PlaywrightTest owns the shared IPlaywright (lazy, thread-safe via
SemaphoreSlim, leaked at process exit) and the static Expect(IPage),
Expect(ILocator), Expect(IAPIResponse) forwarders.
* BrowserTest owns the shared IBrowser, virtual BrowserName (chromium |
firefox | webkit) and GetBrowserLaunchOptions, and exposes a NewContext
helper that tracks every context for automatic disposal at [TestCleanup].
* ContextTest creates a per-test Context with virtual GetContextOptions.
* PageTest creates a per-test Page on top of that context.
Slim the TestApp.E2E.Tests test asset's TestRoot down to just the
ServerFactory — Playwright / IBrowser ownership moves into the inherited
base class. All seven test classes now derive from BrowserTest, create
their per-test IBrowserContext via the inherited NewContext(options) (so
contexts are tracked and cleaned up automatically), and use the inherited
static Expect(...) instead of qualified Assertions.Expect(...).
PublicAPI.Unshipped.txt updated with the four new types and their members.
Verified: library + library tests + test asset build clean (0/0); all 88
library xUnit unit tests pass; MTP still discovers the 23 migrated MSTest
tests.
Co-authored-by: Copilot <[email protected]>
NuGet buildTransitive targets (e.g. MSTest.TestFramework) can inject
<Reference> items with a HintPath pointing to DLLs inside the NuGet
package cache. The aspnetcore custom reference resolver validated
every remaining Reference item using Exists('%(Reference.Identity)'),
which checks for a file at the bare assembly name -- that check always
fails for injected references (the identity is 'MSTest.TestFramework.Extensions',
not a path).
References that carry an explicit HintPath already have a resolved
location; MSBuild's own resolver will validate the HintPath. Skip the
aspnetcore check for those items so that shipping projects that
transitively depend on MSTest.TestFramework (via
Microsoft.AspNetCore.Components.Testing) don't get a spurious MSB3245
error.
Co-authored-by: Copilot <[email protected]>
- Remove OutputType=Exe from buildTransitive .props (unsafe to set from NuGet packages; consumer projects set it themselves) - Rename MSTestRunCommandLineArguments -> TestingPlatformCommandLineArguments (correct MTP property name) - Move xunit.v3 LatestPackageReference entries alongside other xunit entries; they were misplaced under the Components.Testing comment but are still needed by the library's unit test project - Bump MSTestVersion 4.0.2 -> 4.2.3 - Bump MicrosoftTestingPlatformMSBuildVersion and MicrosoftTestingExtensionsRetryVersion 2.0.2 -> 2.2.3 - Replace StringAssert.Contains(url, expected) with Assert.Contains(expected, url) per MSTest v4 style - Drop now-unnecessary DisablePackageReferenceRestrictions from library .csproj (HintPath check in ResolveReferences.targets handles the MSTest.TestFramework.Extensions injection) - Update stale comments in test project .csproj files Co-authored-by: Copilot <[email protected]>
…nsumer project These are test-runner concerns that should not be pushed onto every consumer of the library via buildTransitive. The .props file now only contains E2EAppMode and E2EAppsRelativeDir — build-time controls that genuinely apply to all consumers. The MTP properties live in the concrete test project where they belong. Co-authored-by: Copilot <[email protected]>
Ship Microsoft.AspNetCore.Components.Testing with no MSTest.TestFramework reference and no runtime reporter abstraction. All MSTest-specific glue (TestContext access, [TestClass]/[TestInitialize]/[TestCleanup]) is emitted by a new source generator into the consumer test assembly, which already references MSTest. - Agnostic tracing core: TracingSession/PlaywrightExtensions become delegate driven (shouldSave + onArtifactsSaved callbacks) with no TestContext coupling. - New UITest root base + [UITest] attribute drive framework-agnostic lifecycle (InitializeCoreAsync/CleanupCoreAsync, chained base-first). - New UITestGenerator emits [TestClass], the TestContext property, the [TestInitialize]/[TestCleanup] hooks, and the E2EGeneratedTestContextExtensions bridge, all gated on the consumer referencing MSTest. - E2EArtifacts/E2EArtifactPaths resolve the artifacts directory from the build-injected AssemblyMetadata attribute. - Remove MSTest.TestFramework reference; rewrite consumer E2E tests to [UITest] partial classes; reconcile PublicAPI baseline. Library builds clean and all 88 unit tests pass. Co-authored-by: Copilot App <[email protected]> Copilot-Session: cde6a225-279c-4cf0-967a-8ef19d954d90
2b517c2 to
f38d5a8
Compare
Move the on-failure server-output orchestration into the framework-agnostic UITest.SaveServerDiagnostics seam driven by delegates (mirroring the tracing APIs), so the generated cleanup no longer reconstructs paths. This lets ServerInstance.WriteCapturedOutputTo, AppName, Id, AppUrl, PublicUrl and E2EArtifactPaths.ServerOutput become internal, and removes the unused ServerStartOptions.RecycleOnRetry. Co-authored-by: Copilot App <[email protected]> Copilot-Session: cde6a225-279c-4cf0-967a-8ef19d954d90
|
|
||
| <Error | ||
| Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework' AND '%(Reference.Identity)' != '' AND ! Exists('%(Reference.Identity)') AND '$(DisablePackageReferenceRestrictions)' != 'true'" | ||
| Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework' AND '%(Reference.Identity)' != '' AND ! Exists('%(Reference.Identity)') AND '%(Reference.HintPath)' == '' AND '$(DisablePackageReferenceRestrictions)' != 'true'" |
There was a problem hiding this comment.
Is this change still needed? Or was it relevant only in trials to use MSTest.Sdk?
| <Reference Include="Microsoft.Playwright.Xunit.v3" /> | ||
| <Reference Include="xunit.v3" /> | ||
| <Reference Include="MSTest.TestFramework" /> | ||
| <Reference Include="Microsoft.Testing.Platform.MSBuild" /> |
There was a problem hiding this comment.
Why do we need to reference it explicitly? The test adapter package brings it, along with VSTestBridge and other deps as well.
| <PropertyGroup> | ||
| <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
| <OutputType>Exe</OutputType> | ||
| <EnableMSTestRunner>true</EnableMSTestRunner> |
There was a problem hiding this comment.
How do we run this project in CI? Do we really run it as MTP? 👀
Co-authored-by: Copilot App <[email protected]> Copilot-Session: a5425cd4-aa5e-4199-846c-fbf11893985b
Order the E2E manifest task project before the test project and update Dependabot discovery for the MSTest package set. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a5425cd4-aa5e-4199-846c-fbf11893985b
Build the manifest task before use, mark MTP applications explicitly, and preserve Helix publish mode for nested publishes. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a5425cd4-aa5e-4199-846c-fbf11893985b
When the manifest task assembly is missing, remove NoBuild from the isolated task-project invocation so Source Build can produce the required tool. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a5425cd4-aa5e-4199-846c-fbf11893985b
Pack the library into an isolated feed and build package-only consumers to validate the shipped generator, MSBuild assets, and local and published E2E manifests. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a5425cd4-aa5e-4199-846c-fbf11893985b
Build package inputs before package-consumer validation, preserve configured restore sources, and force missing MSBuild task outputs to rebuild in a fresh project configuration. Co-authored-by: Copilot App <[email protected]>
Preserve the package project's packability, skip E2E preparation for excluded source-build tests, and honor redirected artifact roots in the tracing test. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Use Arcade's Microsoft.Testing.Platform runner, rely on MSTest adapter transitive build assets, and keep publish payload preparation local to the E2E test project. Remove custom MTP markers and direct Helix execution while preserving uploaded browser artifacts through the existing VSTest path. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Keep shipped buildTransitive targets product-neutral and move source-tree task building and build gating into testassets. Make package publish preparation deterministic for standalone consumers. Consolidate artifact path resolution and test-name sanitization behind the approved TestArtifactDirectory.GetPath API. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Clarify the shipped package boundary, repository integration placement, and portable payload expectations for future changes. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Describe durable product boundaries, package determinism, repository integration, and external-consumer validation without coupling the guidance to the current implementation. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 52e861dd-f191-4025-a0b3-a39c95a958b4
Summary
This document proposes adding
Microsoft.AspNetCore.Components.Testing, a package for authoring and running end-to-end ASP.NET Core Components tests with MSTest on Microsoft Testing Platform (MTP), Playwright, and application processes described by a generated manifest. It addresses the need for a reusable test model that can discover applications under test, prepare them for local or portable execution, manage browser and server lifecycles, and preserve diagnostics when failures occur.The package keeps test lifecycle capabilities independent of repository infrastructure. Consumers opt into UI-test lifecycle generation, identify applications through project-reference metadata, and receive build or publish manifests that can run locally or as a complete payload on a separately provisioned CI machine.
Goals
Provide a concise MSTest-on-MTP authoring model. Consumers can derive tests from Playwright capability classes, mark them with
UITestAttribute, and receive the MSTest lifecycle binding required to initialize and clean up browser, context, page, server, and artifact resources.Make applications under test discoverable and reproducible. A test project can identify one or more application projects, build or publish them, and generate a deterministic manifest describing how each application starts, where it runs, and which public URL the test should use.
Produce portable test payloads. Publishing a test project can include the test executable, manifests, application outputs, and runtime files needed to move the payload to a separately provisioned machine or CI service without depending on the original source-tree layout.
Preserve actionable diagnostics. Browser traces, videos, screenshots, application output, and other test artifacts are written to deterministic locations and attached to failed test results where the test framework supports attachments.
Use established configuration providers and infrastructure. Browser selection and launch options follow
Microsoft.Playwright.TestAdapter; test execution follows MSTest and MTP; package behavior remains independent of ASP.NET Core repository build properties or CI-specific orchestration.Non-goals
Supporting every test framework in this initial package. Product lifecycle capabilities remain test-framework-neutral, but the generated binding in this proposal targets MSTest. Additional framework adapters can be evaluated independently without changing the core lifecycle model.
Replacing Playwright, MSTest, or MTP. The package composes their supported APIs and configuration models rather than introducing a competing browser driver, assertion library, test runner, or runsettings format.
Redesigning Playwright worker or browser pooling. The default browser remains shared for the test assembly, with per-test contexts and pages. Worker-aware pools, remote-browser connection APIs, and alternate concurrency models are outside this proposal.
Embedding CI-service orchestration in the package. Producing a portable payload is product behavior; selecting queues, submitting jobs, provisioning machines, installing browsers, and collecting service-specific artifacts belong to the consuming CI system.
Depending on the ASP.NET Core repository layout. Shipped package assets do not require
RepoRoot,ArtifactsBinDir, source-build flags, repository-only projects, or repository-specific build hooks.Proposed solution
Microsoft.AspNetCore.Components.Testingprovides Playwright-based test capability classes, a test-framework binding generator, server and proxy lifecycle support, deterministic artifact routing, and transitive build assets. The build assets inspect application project references marked withE2EApp, prepare those applications according to the selected mode, and write a manifest consumed at test runtime. Build mode favors local development, while publish mode produces a self-contained directory structure suitable for transfer to another machine.Reference the package and identify an application
A consumer creates an executable MSTest project, enables the MSTest runner, references the package, and marks each application under test.
Building the test project creates a manifest entry for
App. A project with noE2EAppreferences remains valid and app preparation naturally performs no work.Author a basic browser test
The consumer marks a partial test class and selects the minimum Playwright capability it needs.
Generated code supplies the MSTest class marker,
TestContext, and initialization and cleanup hooks. Test methods use the initializedPage,Context, orBrowserproperties and Playwright assertions without manually coordinating shared browser startup or per-test disposal.Run applications from the local build
With the default build mode, the manifest points to the application project and records a
dotnet run --no-build --no-restore --no-launch-profilelaunch contract. The test can start the application without copying source into the test output, which keeps local iteration fast while preserving an explicit launch description.Publish a portable payload
A consumer selects publish mode when the test and applications must run without access to their original source directories.
Publishing the test project places each published application beneath the test publish directory and writes manifest paths relative to that directory.
allmode may be used when a payload must contain both source-based and published launch forms.Start an application and route browser traffic
Tests use the manifest-backed server factory to launch an application and create a browser context whose requests are routed through the test proxy.
The lifecycle tracks the application process, proxy routing, browser context, and captured output. Cleanup occurs after the framework has finalized the test outcome so diagnostics can be retained for failures.
Configure the browser consistently for the test run
Browser selection and launch options use
Microsoft.Playwright.TestAdapter.PlaywrightSettingsProvider. Consumers can use the supportedBROWSERandHEADEDenvironment variables or Playwright runsettings without package-specific equivalents.The selected browser is fixed when the assembly-shared browser is created. Later environment changes cannot cause test instances to report a browser name different from the browser already running.
Collect traces and deterministic artifacts
Consumers can create traced contexts or start tracing an existing context. Artifact paths default beneath the test output and can be configured at build time or overridden for a run.
Relative paths resolve against the test assembly directory, absolute paths remain absolute, and
E2E_ARTIFACTS_DIRtakes precedence at runtime. Failed tests attach saved files throughTestContextand retain application output alongside browser diagnostics.Extend application, browser-context, and server behavior
Consumers can customize application public URLs through
E2EPublicUrl, choose build, publish, or combined preparation throughE2EAppMode, customize browser contexts through the existing context-options extensibility point, and supply server-start options when launching an application. These extensions do not change manifest portability or require exposing repository-specific build controls.Surface configuration and payload failures
An invalid browser name fails with the Playwright provider’s supported-browser message. A declared application without an available manifest-generation task produces a build warning rather than a success-shaped payload, and a missing runtime manifest produces an actionable exception identifying the expected file and required
E2EAppmetadata. Application startup failures preserve captured process output; incomplete publish outputs fail validation because manifest launch paths must resolve inside the published payload.Assumptions
MSTest.TestFrameworkandMSTest.TestAdapterthat support executable test applications.Microsoft.Playwright.TestAdapterandMicrosoft.Playwrightuse exactly aligned versions; the provider remains the authoritative source for browser and launch configuration.ProjectReference.References
212a4ec861