LighthousePlaywright.Net
1.0.1
dotnet add package LighthousePlaywright.Net --version 1.0.1
NuGet\Install-Package LighthousePlaywright.Net -Version 1.0.1
<PackageReference Include="LighthousePlaywright.Net" Version="1.0.1" />
<PackageVersion Include="LighthousePlaywright.Net" Version="1.0.1" />
<PackageReference Include="LighthousePlaywright.Net" />
paket add LighthousePlaywright.Net --version 1.0.1
#r "nuget: LighthousePlaywright.Net, 1.0.1"
#:package LighthousePlaywright.Net@1.0.1
#addin nuget:?package=LighthousePlaywright.Net&version=1.0.1
#tool nuget:?package=LighthousePlaywright.Net&version=1.0.1
LighthousePlaywright.Net
This is a .NET (c#) library for Google Lighthouse tool.
Lighthouse is a tool developed by Google that analyzes web apps and web pages, collecting modern performance metrics and insights on developer best practices.
Playwright is a Node library to automate Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.
Project based on https://github.com/dima-horror/lighthouse.net but instead of the need for an installed version of chrome it uses playwright.
How to install
You need to install lighthouse and playwright-lighthouse as Node module on machine (more info).
- Install the current version of Node.
- Install Lighthouse and playwright-lighthouse. The
-g
flag installs it as a global modules.
> npm install -g lighthouse playwright-lighthouse
- Install lighthouse.net into your project via NuGet
PM> Install-Package LighthousePlaywright.Net
Basic example
public class LighthouseTest
{
[Fact]
public async Task ExampleComAudit()
{
var lh = new Lighthouse();
var res = await lh.Run("http://example.com");
res.Should().NotBeNull();
res.Performance.Should().NotBeNull();
(res.Performance > 0.5m).Should().BeTrue();
res.Accessibility.Should().NotBeNull();
(res.Accessibility > 0.5m).Should().BeTrue();
res.BestPractices.Should().NotBeNull();
(res.BestPractices > 0.5m).Should().BeTrue();
res.Seo.Should().NotBeNull();
(res.Seo > 0.2m).Should().BeTrue();
}
}
Options
You can parse options to the lighthouse constructor..
var options = new Options
{
Port = 9222
};
var lh = new Lighthouse(options);
Port
The Chrome Port - Default: 9222
Thresholds
var options = new Options
{
Thresholds = new Thresholds
{
Performance = 50,
Accessibility = 50,
BestPractices = 50,
Seo = 50,
Pwa = 50
}
};
var lh = new Lighthouse(options);
If you don't provide any threshold argument to the playAudit command, the test will fail if at least one of your metrics is under 50.
Reports
This library can produce Lighthouse CSV, HTML and JSON audit reports. These reports can be useful for ongoing audits and monitoring from build to build.
var options = new Options
{
Reports = new Reports
{
Formats = new Formats
{
Json = true, //defaults to false
Html = true, //defaults to false
Csv = true //defaults to false
},
Name = "name-of-the-report", // defaults to $"lighthouse-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"
Directory = "path/to/directory" // defaults to '../lighthouse'
}
};
var lh = new Lighthouse(options);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net9.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.