C3D.Extensions.Playwright.AspNetCore.Xunit
0.1.35
See the version list below for details.
dotnet add package C3D.Extensions.Playwright.AspNetCore.Xunit --version 0.1.35
NuGet\Install-Package C3D.Extensions.Playwright.AspNetCore.Xunit -Version 0.1.35
<PackageReference Include="C3D.Extensions.Playwright.AspNetCore.Xunit" Version="0.1.35" />
paket add C3D.Extensions.Playwright.AspNetCore.Xunit --version 0.1.35
#r "nuget: C3D.Extensions.Playwright.AspNetCore.Xunit, 0.1.35"
// Install C3D.Extensions.Playwright.AspNetCore.Xunit as a Cake Addin #addin nuget:?package=C3D.Extensions.Playwright.AspNetCore.Xunit&version=0.1.35 // Install C3D.Extensions.Playwright.AspNetCore.Xunit as a Cake Tool #tool nuget:?package=C3D.Extensions.Playwright.AspNetCore.Xunit&version=0.1.35
C3D.Extensions.Playwright.AspNetCore.Xunit
Adds Xunit logging and fixture support to C3D.Extensions.Playwright.AspNetCore
to allow easy unit testing of AspNetCore web applications using Xunit
.
Usage
Basic
Create an Xunit est with a class fixture. Use Playwright with tracing support to check a page title.
public class UnitTestDefault : IClassFixture<PlaywrightFixture<Program>>
{
private readonly PlaywrightFixture<Program> webApplication;
private readonly ITestOutputHelper outputHelper;
public UnitTestDefault(PlaywrightFixture<Program> webApplication, ITestOutputHelper outputHelper)
{
this.webApplication = webApplication;
this.outputHelper = outputHelper;
}
[Fact]
public async Task CanTrace()
{
var page = await webApplication.CreatePlaywrightPageAsync();
await using var trace = await page.TraceAsync($"Testing Tracing on {webApplication.BrowserType}", true, true, true);
outputHelper.WriteLine($"Tracing to {trace.TraceName}");
Assert.Equal("CanTrace.zip", trace.TraceName);
await page.GotoAsync("/");
Assert.Equal("Home page", await page.TitleAsync());
Assert.True(System.IO.File.Exists(trace.TraceName));
}
}
Advanced
Create a base fixture wrapping your program.
public abstract class ProgramFixtureBase : PlaywrightFixture<Program> {
protected ProgramFixtureBase(IMessageSink output) : base(output) {}
}
Create multiple fixtures for each combination of Environment and/or browser that you desire.
public class ProgramFixtureChrome : ProgramFixtureBase {
public ProgramFixtureChrome(IMessageSink output) : base(output) {}
}
public class ProgramFixtureFirefox : ProgramFixtureBase {
public ProgramFixtureFirefox(IMessageSink output) : base(output) {}
public override PlaywrightBrowserType BrowserType => PlaywrightBrowserType.Firefox;
}
public class ProgramFixtureWebkit : ProgramFixtureBase {
public ProgramFixtureWebkit(IMessageSink output) : base(output) {}
public override PlaywrightBrowserType BrowserType => PlaywrightBrowserType.Webkit;
}
Create a base unit test class
public abstract class UnitTestBase
{
protected readonly ProgramFixtureBase webApplication;
protected readonly ITestOutputHelper outputHelper;
protected UnitTestBase(ProgramFixtureBase webApplication, ITestOutputHelper outputHelper)
{
this.webApplication = webApplication;
this.outputHelper = outputHelper;
}
[Fact]
public async Task TestRootTitle()
{
var page = await webApplication.CreatePlaywrightPageAsync();
await page.GotoAsync("/");
Assert.Equal("Home page", await page.TitleAsync());
}
}
Create a unit test class for each fixture
public class UnitTestChrome : UnitTestBase, IClassFixture<ProgramFixtureChrome>
{
public UnitTestChrome(ProgramFixtureChrome webApplication, ITestOutputHelper outputHelper) :
base(webApplication, outputHelper)
{
}
}
public class UnitTestFirefox : UnitTestBase, IClassFixture<ProgramFixtureFirefox>
{
public UnitTestFirefox(ProgramFixtureFirefox webApplication, ITestOutputHelper outputHelper) :
base(webApplication, outputHelper)
{
}
}
public class UnitTestWebkit : UnitTestBase, IClassFixture<ProgramFixtureWebkit>
{
public UnitTestWebkit(ProgramFixtureWebkit webApplication, ITestOutputHelper outputHelper) :
base(webApplication, outputHelper)
{
}
}
Now each test in UnitTestBase
will be run for each browser.
If using tracing, in order to prevent clashes between tests which will have the same name by default, use the overload taking the type of the fixture.
There is an overload that takes an object and calls ToString to get the prefix. Using this with the fixture class will return
{Environment}_{BrowserType}_{typeof(TProgram).FullName}
You can override this in your base fixture depending on what variants you have defined.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- C3D.Extensions.Logging.Xunit (>= 0.2.2)
- C3D.Extensions.Playwright.AspNetCore (>= 0.1.39)
-
net7.0
- C3D.Extensions.Logging.Xunit (>= 0.2.2)
- C3D.Extensions.Playwright.AspNetCore (>= 0.1.39)
-
net8.0
- C3D.Extensions.Logging.Xunit (>= 0.2.2)
- C3D.Extensions.Playwright.AspNetCore (>= 0.1.39)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on C3D.Extensions.Playwright.AspNetCore.Xunit:
Repository | Stars |
---|---|
FritzAndFriends/TagzApp
An application that discovers content on social media for hashtags
|
Version | Downloads | Last updated |
---|---|---|
0.1.40 | 94 | 10/2/2024 |
0.1.36 | 131 | 8/12/2024 |
0.1.35 | 55 | 7/29/2024 |
0.1.34 | 97 | 7/16/2024 |
0.1.33 | 92 | 7/12/2024 |
0.1.32 | 446 | 12/28/2023 |
0.1.31 | 141 | 12/28/2023 |
0.1.30 | 1,296 | 9/26/2023 |
0.1.29 | 152 | 9/18/2023 |
0.1.28 | 733 | 9/16/2023 |
0.1.26 | 738 | 8/21/2023 |
0.1.25 | 488 | 8/13/2023 |
0.1.24 | 169 | 8/12/2023 |
0.1.22 | 179 | 8/12/2023 |
0.1.7 | 170 | 8/11/2023 |