Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium: add WebDriver BiDi extension methods #183

Open
1 task done
radmorecameron opened this issue Sep 23, 2024 · 0 comments
Open
1 task done

Selenium: add WebDriver BiDi extension methods #183

radmorecameron opened this issue Sep 23, 2024 · 0 comments

Comments

@radmorecameron
Copy link

Which package is this feature for?

  • Deque.AxeCore.Selenium

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:

  • WebDriverOptions (ex: ChromeOptions) need to have UseWebSocketUrl enabled in order to use BiDi
  • to get a bidi driver use AsBiDiContextAsync on a WebDriver object.

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;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant