dequelabs / axe-core-nuget

Axe Core integration for C# .NET
19 stars 6 forks source link

Selenium: add WebDriver BiDi extension methods #183

Open radmorecameron opened 2 months ago

radmorecameron commented 2 months ago

Which package is this feature for?

Feature description

Version v4.25.0 of Selenium added some support for WebDriver BiDi (https://w3c.github.io/webdriver-bidi/) this should make it possible to execute javascript asyncronously. I think it'd be good to add extensions for the BrowsingContext to run axe against the page if possible.

BiDi information:

Here is an example of some code using BiDi to get the title of the page asyncronously:

using OpenQA.Selenium.BiDi;
using OpenQA.Selenium.BiDi.Modules.BrowsingContext;

namespace BidiExample;

public class BidiTest
{
    public async Task MyMethod()
    {
        var options = new ChromeOptions
        {
            UseWebSocketUrl = true
        };
        var driver = new ChromeDriver(options);
        var biDiContext = await driver.AsBiDiContextAsync();
        var title = await biDiContext.GetPageTitleAsync();
        Assert.NotNull(title);
    }

    // Here is some example code on how to execute a script and return the value using the BrowsingContext from BiDi:
    public static async Task<string> GetPageTitleAsync(this BrowsingContext bidiContext)
    {
        return (await bidiContext.Script.EvaluateAsync<StringRemoteValue>("document.title", true)).Value;
    }
}