C3D.Extensions.Playwright.AspNetCore 0.1.35

There is a newer version of this package available.
See the version list below for details.
dotnet add package C3D.Extensions.Playwright.AspNetCore --version 0.1.35                
NuGet\Install-Package C3D.Extensions.Playwright.AspNetCore -Version 0.1.35                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="C3D.Extensions.Playwright.AspNetCore" Version="0.1.35" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add C3D.Extensions.Playwright.AspNetCore --version 0.1.35                
#r "nuget: C3D.Extensions.Playwright.AspNetCore, 0.1.35"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install C3D.Extensions.Playwright.AspNetCore as a Cake Addin
#addin nuget:?package=C3D.Extensions.Playwright.AspNetCore&version=0.1.35

// Install C3D.Extensions.Playwright.AspNetCore as a Cake Tool
#tool nuget:?package=C3D.Extensions.Playwright.AspNetCore&version=0.1.35                

C3D.Extensions.Playwright.AspNetCore

An extension to Microsoft.AspNetCore.Mvc.Testing which adds Microsoft.Playwright support to the WebApplicationFactory (and keeps the existing HttpClient infrastucture).

This allows you to write browser based tests as well as API based tests using this as the bases for a test fixture.

There are also a number of utility methods available to install playwrite and to help with tracing.

Factory

The main factory is PlaywrightWebApplicationFactory which can be used in place of WebApplicationFactory. You can derive your own type from this factory, with a concrete type and override the various members to allow customizing the instance.

Extension Points

    public override string? Environment => "Staging";
    public override PlaywrightBrowserType BrowserType => PlaywrightBrowserType.Firefox;
    public override LogLevel MinimumLogLevel => LogLevel.Debug;

These can be used to adjust the hosting environment, browser, and log level.

Usage

The factory adds a CreatePlaywrightPageAsync method to compliment the CreateClient method. This returns an IPage from playwright which allows you to do your browser testing. The underlying engine will spin up an instance of your website on a random port above 5000, and set the base url for playwright so you can use relative URLs for GotoPageAsync. Remember the factory is IAsyncDisposable so you should dispose it when finished with.

    using var webApplication = new PlaywrightWebApplicationFactory<Program>();
    var page = await webApplication.CreatePlaywrightPageAsync();

    await page.GotoAsync("/");
    var title = await page.TitleAsync();

Extensions

There are a number of overloads of an extension method TraceAsync added to IPage to allow easier creation of traces. The only required parameter is the title for the trace. The filename is generated from the CallerMemberName. It appends .zip and optionally adds the prefix parameter (with an _ to seperate).

If you use one of the overloads that takes a type

.TraceAsync<MyType>("title")
.TraceAsync("title",typeof(MyType))

it will use the type's FullName as the prefix.

There is another overload that will ToString on an object passed in to get the prefix. The factory implements

public override string ToString() => $"{Environment}_{BrowserType}_{typeof(TProgram).FullName}";

The object returned is IAsyncDisposable and will close the trace when disposed.

    using var webApplication = new PlaywrightWebApplicationFactory<Program>();
    var page = await webApplication.CreatePlaywrightPageAsync();
    using var trace = await page.TraceAsync("MyTrace");

    await page.GotoAsync("/");
    var title = await page.TitleAsync();

The trace object has a public TraceName property with the built path, and a ShowOnClose property which, if set to true, will attempt to open the trace file on dispose.

Utilities

The PlaywrightUtilities class provides a couple of methods to make recording traces easier.

The ShowTrace method takes a filename and optional parameters which are passed to the trace.

Note that the filename must include the .zip extension.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on C3D.Extensions.Playwright.AspNetCore:

Package Downloads
C3D.Extensions.Playwright.AspNetCore.Xunit

Assembly Version: 0.1.0.0 File Version: 0.1.40.31910 Informational Version: 0.1.40+7ca679ce39 Build Configuration: Release

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.43 112 10/2/2024
0.1.40 151 8/12/2024
0.1.39 57 7/29/2024
0.1.38 119 7/16/2024
0.1.37 95 7/12/2024
0.1.36 482 12/28/2023
0.1.35 125 12/28/2023
0.1.34 1,291 9/26/2023
0.1.33 143 9/18/2023
0.1.32 727 9/16/2023
0.1.30 741 8/21/2023
0.1.25 483 8/13/2023
0.1.24 186 8/13/2023
0.1.22 208 8/12/2023
0.1.7 190 8/11/2023