Deque.AxeCore.Playwright 4.4.0-alpha.c9651f2c2284967c64d2f28e460b5181d0af5c6d

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of Deque.AxeCore.Playwright.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Deque.AxeCore.Playwright --version 4.4.0-alpha.c9651f2c2284967c64d2f28e460b5181d0af5c6d
NuGet\Install-Package Deque.AxeCore.Playwright -Version 4.4.0-alpha.c9651f2c2284967c64d2f28e460b5181d0af5c6d
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="Deque.AxeCore.Playwright" Version="4.4.0-alpha.c9651f2c2284967c64d2f28e460b5181d0af5c6d" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Deque.AxeCore.Playwright --version 4.4.0-alpha.c9651f2c2284967c64d2f28e460b5181d0af5c6d
#r "nuget: Deque.AxeCore.Playwright, 4.4.0-alpha.c9651f2c2284967c64d2f28e460b5181d0af5c6d"
#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 Deque.AxeCore.Playwright as a Cake Addin
#addin nuget:?package=Deque.AxeCore.Playwright&version=4.4.0-alpha.c9651f2c2284967c64d2f28e460b5181d0af5c6d&prerelease

// Install Deque.AxeCore.Playwright as a Cake Tool
#tool nuget:?package=Deque.AxeCore.Playwright&version=4.4.0-alpha.c9651f2c2284967c64d2f28e460b5181d0af5c6d&prerelease

Deque.AxeCore.Playwright

Deque.AxeCore.Playwright NuGet package NuGet package download counter

Automated web accessibility testing with .NET, C#, and Playwright. Wraps the axe-core accessibility scanning engine and the Playwright browser automation framework.

Compatible with .NET Standard 2.1.

Getting Started

Install via NuGet:

PM> Install-Package Deque.AxeCore.Playwright
# or, use the Visual Studio "Manage NuGet Packages" UI

Example usage:

using System.Threading.Tasks;
using Microsoft.Playwright;
using Deque.AxeCore.Playwright;

class Program
{
    public static async Task Main()
    {
        using var playwright = await Playwright.CreateAsync();
        await using var browser = await playwright.Chromium.LaunchAsync(new() { Headless = false });
        var page = await browser.NewPageAsync();
        await page.GotoAsync("https://playwright.dev/dotnet");

        AxeResults axeResults = await page.RunAxe();

        // Assert.AreEqual(axeResults.Violations.Count, 0);
    }
}

API Reference

This library essentially wraps the axe-core library. Currently the two supported functions are for rule retrieval and for running.

GetAxeRules

This method retrieves metadata about the rules that axe is capable of running.


IList<AxeRuleMetadata> axeRules = await page.GetAxeRules();
foreach(var rule in axeRules)
{
    Console.WriteLine($"Rule name: {rule.RuleId} Help: {rule.Help} HelpUrl: {rule.HelpUrl}");
    Console.WriteLine($"Tags: {string.Join(", ", rule.Tags)}");
}

It is also possible to run this only selecting for rules with particular tags. Tags are considered in a disjunctive fashion.


// Only take rules which are wcag2aa or wcag2a.
IList<string> tags = new List<string>() { "wcag2aa", "wcag2a"}

IList<AxeRuleMetadata> axeRules = await page.GetAxeRules(tags);
foreach(var rule in axeRules)
{
    Console.WriteLine($"Rule name: {rule.RuleId} Help: {rule.Help} HelpUrl: {rule.HelpUrl}");
    Console.WriteLine($"Tags: {string.Join(", ", rule.Tags)}");
}

RunAxe

This method executes the axe run method, which will run rules against the current state of the page.


AxeResults axeResults = await page.RunAxe();

Console.WriteLine($"Axe ran against {axeResults.Url} on {axeResults.Timestamp}.");

Console.WriteLine($"Rules that failed:");
foreach(var violation in axeResults.Violations)
{
    Console.WriteLine($"Rule Id: {violation.Id} Impact: {violation.Impact} HelpUrl: {violation.HelpUrl}.");

    foreach(var node in violation.Nodes)
    {
        Console.WriteLine($"\tViolation found in Html: {node.Html}.");

        foreach(var target in node.Target)
        {
            Console.WriteLine($"\t\t{target}.");
        }
    }
}

Console.WriteLine($"Rules that passed successfully:");
foreach(var pass in axeResults.Passes)
{
    Console.WriteLine($"Rule Id: {pass.Id} Impact: {pass.Impact} HelpUrl: {pass.HelpUrl}.");
}

Console.WriteLine($"Rules that did not fully run:");
foreach(var incomplete in axeResults.Incomplete)
{
    Console.WriteLine($"Rule Id: {incomplete.Id}.");
}

Console.WriteLine($"Rules that were not applicable:");
foreach(var inapplicable in axeResults.Inapplicable)
{
    Console.WriteLine($"Rule Id: {inapplicable.Id}.");
}

This method can be run on an element via the context parameter. This allows the inclusion and exclusion of string selectors. When exclude is only specified, include will default to the entire document. Currently the node and node lists functionality are not supported.


AxeRunContext runContext = new AxeRunSerialContext("#my-id"); // Only run on this id.

runContext = new AxeRunSerialContext(null, "#my-id"); // Run on everything but this id.

runContext = new AxeRunSerialContext("button", "#my-id"); // Run on every button that does not have this id.

runContext = new AxeRunSerialContext(new List<string>()
{
    new List<string>()
    {
        "#my-frame",
        "#my-id"
    }
}); // Run on the element with my-id Id and which is inside the frame with id my-frame.

AxeResults axeResults = await page.RunAxe(runContext);

The run method can also be run on a Playwright Locator. This does not support context parameter.

ILocator locator = page.Locator("text=Sign In");

AxeResults axeResults = await locator.RunAxe();

All these run methods support an AxeRunOptions parameter. This is roughly the equivalent of axe options .


AxeRunOptions options = new AxeRunOptions(
    // Run only tags that are wcag2aa.
    runOnly: new AxeRunOnly(AxeRunOnlyType.Tag, new List<string> { "wcag2aa" }),

    // Specify rules.
    rules: new Dictionary<string, AxeRuleObjectValue>()
    {
        // Don't run color-contrast.
        {"color-contrast", new AxeRuleObjectValue(false)}
    },

    // Limit result types to Violations.
    resultTypes: new List<AxeResultGroup>()
    {
        AxeResultGroup.Violations
    },

    // Don't return css selectors in results.
    selectors: false,

    // Return CSS selector for elements, with all the element's ancestors.
    ancestry: true,

    // Don't return xpath selectors for elements.
    xpath: false,

    // Don't run axe on iframes inside the document.
    iframes: false
);

AxeResults axeResults = await page.RunAxe(options);
axeResults = await page.RunAxe(context, options);
axeResults = await locator.RunAxe(options);


RunAxeLegacy

Set the frame testing method to "legacy mode". In this mode, axe will not open a blank page in which to aggregate its results. This can be used in an environment where opening a blank page causes issues.

With legacy mode turned on, axe will fall back to its test solution prior to the 4.3 release, but with cross-origin frame testing disabled. The frame-tested rule will report which frames were untested.

Important: Use of .RunAxeLegacy() is a last resort. If you find there is no other solution, please report this as an issue. It will be removed in a future release.

AxeResults axeResults = await page.RunAxeLegacy();

Migrating from Playwright.Axe (PlaywrightAxeDotnet)

This project acts as a drop-in replacement for most of the functionality from Playwright.Axe. (PlaywrightAxeDotnet). To migrate:

  1. Update your test .csproj file's <PackageReference> for Playwright.Axe to Deque.AxeCore.Playwright
  2. Add a new <PackageReference> to Deque.AxeCore.Commons at the same version number as Deque.AxeCore.Playwright
  3. Update all using Playwright.Axe; statements in your tests to using Deque.AxeCore.Playwright; and/or using Deque.AxeCore.Commons;

In a move to standardize, we migrated this package away from Playwright specific typings, instead opting to use the typings from the Deque.AxeCore.Commons package instead. The result is several minor breaking changes that may require updates to your code:

Replacements/Renamings

  1. AxeResults has now been renamed to AxeResult; the previously used AxeResult for this package will now be AxeResultItem.

  2. AxeNodeResult has been replaced with AxeResultNode

  3. AxeCheckResult has been replaced with AxeResultCheck

  4. AxeRelatedNode has been replaced with AxeResultRelatedNode

  5. AxeResultGroup has been replaced with ResultType

  6. AxeRuleObjectValue has been replaced with RuleOptions

  7. AxeRunOnly has been replaced with RunOnlyOptions

  8. AxeResultRelatedNode is now used in lieu of AxeRelatedNode. With this type, the Targets property is changed from a IList<string> to a List<AxeResultTarget>; users should expect to modify usages of the Targets property to include a .ToString() method call.

  9. AxeRunSerialContext has been replaced by AxeRunContext and AxeSelector types. Here are some examples of how to use the new types:

    ```cs
    //finding a single element using the Playwright Locator API
     ILocator locator = page.GetByRole("menu").RunAxe();
    
     //including/excluding elements in the main frame
    new AxeRunContext()
         {
             Include = new List<AxeSelector> { new AxeSelector("#foo") },
             Exclude = new List<AxeSelector> {},
         };
    
     //including/excluding an element in a child frame
    new AxeRunContext()
         {
             Include = new List<AxeSelector> { new AxeSelector("#element-in-child-frame", new List<string> { "#iframe-in-main-frame" })},
             Exclude = new List<AxeSelector> {},
         };
     ```
    

Type Modifications

  1. The Timestamp type in AxeResult changed from System.DateTime to System.DateTimeOffset
  2. The url type in AxeResult changed from Uri to string
  3. The OrientationAngle type in AxeTestEnvironment changed from int to double
  4. The HelpUrl in AxeResultItem changed from Uri to string

Removals

  1. Removed AxeEnvironmentData interface and using the existing environment data info in Deque.AxeCore.Commons.AxeResult
  2. Removed AxeImpactValue and AxeRunOnlyType enums in favor of using string in the Commons typings (AxeResultItem.cs and AxeRunOptions.cs, respectively)
  3. FailureSummary was removed from AxeResultNode (formerly AxeNodeResult)
  4. ElementRef and PerformanceTimer were removed from AxeRunOptions

Contributing

Refer to the general axe-core-nuget CONTRIBUTING.md.

License

This package is distributed under the terms of the MIT License.

However, note that it has a dependency on the (MPL licensed) Deque.AxeCore.Commons NuGet package.

Acknowledgements

This package builds on past work from the PlaywrightAxeDotnet project (see NOTICE.txt). We @IsaacWalker for his work on that project.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.9.0 470 3/29/2024
4.9.0-alpha.76 32 3/29/2024
4.9.0-alpha.75 47 3/26/2024
4.8.2 2,122 2/14/2024
4.8.2-alpha.74 45 3/26/2024
4.8.2-alpha.73 58 2/14/2024
4.8.2-alpha.72 46 2/14/2024
4.8.2-alpha.71 47 2/14/2024
4.8.2-alpha.70 53 2/8/2024
4.8.1 1,189 1/11/2024
4.8.1-alpha.69 41 2/8/2024
4.8.1-alpha.68 45 2/8/2024
4.8.1-alpha.65 59 1/9/2024
4.8.0 6,728 10/2/2023
4.8.0-alpha.67 45 2/7/2024
4.8.0-alpha.64 56 1/9/2024
4.8.0-alpha.63 59 1/9/2024
4.8.0-alpha.62 62 1/9/2024
4.7.2 1,802 8/30/2023
4.7.2-alpha.61 52 12/21/2023
4.7.2-alpha.59 53 11/21/2023
4.7.2-alpha.58 61 11/2/2023
4.7.2-alpha.57 66 11/1/2023
4.7.2-alpha.56 55 10/30/2023
4.7.2-alpha.55 54 10/19/2023
4.7.2-alpha.54 65 10/16/2023
4.7.2-alpha.53 59 10/16/2023
4.7.2-alpha.52 61 10/5/2023
4.7.2-alpha.51 66 10/3/2023
4.7.2-alpha.50 54 10/3/2023
4.7.2-alpha.49 65 9/27/2023
4.7.1-alpha.48 58 9/27/2023
4.7.1-alpha.47 67 9/27/2023
4.7.1-alpha.46 76 9/14/2023
4.7.1-alpha.45 66 9/13/2023
4.7.1-alpha.44 65 9/8/2023
4.7.1-alpha.43 82 8/30/2023
4.7.1-alpha.42 78 8/30/2023
4.4.0-alpha.c9651f2c2284967... 17,998 11/10/2022
4.4.0-alpha.41 76 8/30/2023
4.4.0-alpha.40 79 8/30/2023