Futile.SpecFlow.Actions.Playwright 0.1.350.5

dotnet add package Futile.SpecFlow.Actions.Playwright --version 0.1.350.5
NuGet\Install-Package Futile.SpecFlow.Actions.Playwright -Version 0.1.350.5
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="Futile.SpecFlow.Actions.Playwright" Version="0.1.350.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Futile.SpecFlow.Actions.Playwright --version 0.1.350.5
#r "nuget: Futile.SpecFlow.Actions.Playwright, 0.1.350.5"
#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 Futile.SpecFlow.Actions.Playwright as a Cake Addin
#addin nuget:?package=Futile.SpecFlow.Actions.Playwright&version=0.1.350.5

// Install Futile.SpecFlow.Actions.Playwright as a Cake Tool
#tool nuget:?package=Futile.SpecFlow.Actions.Playwright&version=0.1.350.5

Futile.SpecFlow.Actions.Playwright

Nuget

This SpecFlow.Action will help you use Playwright together with SpecFlow. It handles the initialisation and lifetime of your browser, provides methods to work with your page selectors and a configuration that makes it easy to set up the browser instance.

Futile?

Work on Specflow has been discontinued and the successor is reqnroll (status May 2024). This nuget package comes from a fork that:

  1. Includes some bug fixes
  2. Uses net48 and net6.0

An updated example can be found here.

Setup

You will need to read through the setup process for Playwright so that your environment is ready for execution.

Included Features

  • Lifetime handling of Browser
    • Supported Browsers
      • Chromium
      • Firefox
      • Edge
      • Chrome
  • Configuration via specflow.actions.json

Configuration

You can configure this plugin via the specflow.actions.json.

{
  "playwright": {
    "browser": "edge",
    "args": [
      "arg1",
      "arg2",
      "arg3"
    ],
    "defaultTimeout": 60,
    "headless": false,
    "slowmo": 100,
    "traceDir": "traces"
  }
}

browser

Supported values:

  • chrome
  • firefox
  • chromium
  • edge

arguments

Supported broswer arguments can be defined from the configuration, these are browser specific.

defaultTimeout

Expressed in seconds, the maximum time the browser will wait for interactions before failing.

headless

Whether the browser should run in headless mode or not.

slowmo

Optional. Expressed in miliseconds. If present, will reflect Playwright's slowmo functionality, which determines the time between each individual actions are made, like clicking or typing.

traceDir

Optional. If specified, traces are saved into this directory. See also record traces.

How to use it

The browser is started automatically when you try to use the browser instance for the first time. It is closed after the scenario ends. You can use constructor and/or parameter injection to inject dependencies into your classes, this way the class instances are managed automatically.

Page object

public class BasePage
{
    public readonly Task<IPage> _page;

    // BrowserDriver resolved automatically
    public BasePage(BrowserDriver browserDriver)
    {
        // Assignes the page instance
        _page = CreatePageAsync(browserDriver.Current);
    }

    private async Task<IPage> CreatePageAsync(Task<IBrowser> browser)
    {
        // Creates a new page instance
        return await (await browser).NewPageAsync();
    }
}

public class SomePageObjectClass : BasePage
{
    // Used to interact with the selectors
    private Interactions _interactions;

    public CalculatorPageObject(BrowserDriver browserDriver) : base(browserDriver)
    {
        // Creates the Interactions instance using the page object
        _interactions = new Interactions(_page);
    }

    public async Task FillOutSomeInput(string str)
    {
        //Enter text
        await _interactions.SendTextAsync(FirstNumberFieldSelector, str);
    }
}

Step implementation

[Binding]
public sealed class CalculatorStepDefinitions
{
    private readonly SomePageObjectClass _somePageObjectClass;

    //SomePageObjectClass resolved automatically
    public CalculatorStepDefinitions(SomePageObjectClass somePageObjectClass)
    {
        _somePageObjectClass = somePageObjectClass;
    }

    [Given("something (.*)")]
    public async Task GivenSomething(string value)
    {
        await _somePageObjectClass.FillOutSomeInput(value);
    }
}

Interactions

This class has methods to perform browser interactions per page instance

Available Helper Methods:

/// Navigates to the specified URL
public async Task GoToUrl(string url)

/// Gets the current URL
public async Task<string?> GetUrl()

/// Sends a string to the specified selector
public async Task SendTextAsync(string selector, string keys, PageFillOptions? pageFillOptions = null)

/// Sends individual keystrokes to the specified selector
public async Task SendKeystrokesAsync(string selector, string keys, PageTypeOptions? pageTypeOptions = null)

/// Sends a click to an element
public async Task ClickAsync(string selector, PageClickOptions? pageClickOptions = null)

/// Gets the value attribute of an element
public async Task<string?> GetValueAttributeAsync(string selector, PageInputValueOptions? pageInputValueOptions = null)

/// Waits for the value attribute of an element to not be empty
public async Task WaitForNonEmptyValue(string selector)

/// Waits for the value attribute of an element to be empty
public async Task WaitForEmptyValue(string selector)

/// Selects the option from a select element by its value
public async Task SelectDropdownOptionAsync(string selector, string value, PageSelectOptionOptions? pageSelectOptionOptions = null)

/// Selects the option from a select element by its index
public async Task SelectDropdownOptionAsync(string selector, int index, PageSelectOptionOptions? pageSelectOptionOptions = null)

How to get it

Add the latest version of the Futile.SpecFlow.Actions.Playwright NuGet Package to your project.

Latest version: Nuget

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 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 Framework net48 is compatible.  net481 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
0.1.350.5 234 10/21/2023