Meziantou.AspNetCore.Testing
0.1.2
Prefix Reserved
dotnet add package Meziantou.AspNetCore.Testing --version 0.1.2
NuGet\Install-Package Meziantou.AspNetCore.Testing -Version 0.1.2
<PackageReference Include="Meziantou.AspNetCore.Testing" Version="0.1.2" />
<PackageVersion Include="Meziantou.AspNetCore.Testing" Version="0.1.2" />
<PackageReference Include="Meziantou.AspNetCore.Testing" />
paket add Meziantou.AspNetCore.Testing --version 0.1.2
#r "nuget: Meziantou.AspNetCore.Testing, 0.1.2"
#:package Meziantou.AspNetCore.Testing@0.1.2
#addin nuget:?package=Meziantou.AspNetCore.Testing&version=0.1.2
#tool nuget:?package=Meziantou.AspNetCore.Testing&version=0.1.2
Meziantou.AspNetCore.Testing
Tests of Blazor components and of ASP.NET Core applications (MVC, Razor Pages, Blazor, minimal APIs...) in a browser engine written in .NET (Meziantou.Framework.WebPlatform): the pages have a real DOM, the CSS applies, the scripts run, and the user input (mouse, keyboard, touch) goes through the hit testing of the page. Compare the HTML, the accessibility tree and the screenshots with snapshots.
Render a Blazor component alone with ComponentTestHost (in the Meziantou.AspNetCore.Testing.Components namespace):
await using var host = new ComponentTestHost();
var counter = await host.RenderAsync<Counter>(parameters => parameters.Add(c => c.IncrementAmount, 2));
// A real click: the pointer moves to the center of the button, the hit testing finds the button
await counter.Find("button").ClickAsync();
await counter.GetByRole("button", "Click me").ClickAsync();
Assert.Equal("Current count: 4", counter.GetByRole("status").TextContent);
Assert.Equal("""
<p role="status">Current count: 4</p>
<button class="btn">Click me</button>
""", counter.Markup);
Open the pages of an application, in memory with TestServer or on a server, with WebAppBrowser:
// The application runs in memory: Program is the entry point of the application under test
await using var factory = new WebApplicationFactory<Program>();
await using var browser = WebAppBrowser.Create(factory.Server);
var page = await browser.OpenAsync("/");
await Expect(page).ToHaveTitleAsync("Home");
// Follow a link, fill a form and submit it: the POST, the redirect and the cookie go through the application
await page.GetByRole("link", "Sign in").ClickAsync();
await page.GetByLabel("Name").FillAsync("Ada");
await page.GetByRole("button", "Sign in").ClickAsync();
await Expect(page).ToHaveUrlAsync("/profile");
await Expect(page.Locator("#greeting")).ToHaveTextAsync("Hello Ada");
As in Playwright, GetByRole, GetByLabel, GetByText and the other locators find their element again each time they
are used, the actions wait until the element is visible, stable, enabled and not covered, and the assertions of
Expectations.Expect retry until they pass. The elements are the DOM elements of Meziantou.Framework.WebPlatform.Dom.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- Meziantou.Framework.WebPlatform (>= 1.0.14)
- Meziantou.Framework.WebPlatform.Imaging (>= 1.0.12)
- Meziantou.Framework.WebPlatform.JavaScript (>= 1.0.10)
- Microsoft.AspNetCore.TestHost (>= 10.0.14)
-
net11.0
- Meziantou.Framework.WebPlatform (>= 1.0.14)
- Meziantou.Framework.WebPlatform.Imaging (>= 1.0.12)
- Meziantou.Framework.WebPlatform.JavaScript (>= 1.0.10)
- Microsoft.AspNetCore.TestHost (>= 11.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.