Futile.Specflow.Actions.FlaUI 1.0.3

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

// Install Futile.Specflow.Actions.FlaUI as a Cake Tool
#tool nuget:?package=Futile.Specflow.Actions.FlaUI&version=1.0.3                

Futile.SpecFlow.Actions.FlaUI

Nuget

This SpecFlow.Action will help you use FlaUI together with SpecFlow.

Futile?

Work on Specflow has been discontinued and the successor is reqnroll (status May 2024). This nuget package is an addition to a fork.

Included Features

  • Lifetime handling of the application being tested
  • Configuration via specflow.actions.json
  • Launch of executables and Windows Store Apps (e.g. Calculator)
  • Appium-like interactions

Configuration

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

{
  "flaui": {
    "settings": {
      "uia": "UIA2"
    },
    "profiles": {
      "Calculator.exe with Hello FlaUI": {
        "app": "[path]\Calculator.exe",
        "arguments": "Hello FlaUI",
        "launch": "Exe"
      },
      "Windows 11 Calculator": {
        "app": "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App",
        "launch": "StoreApp"
      }
    }
  }
}

uia

Supported values:

  • UIA2
  • UIA3

app

filename of the executable or the name of the Windows App. The Windows App names can be found in folder %userprofile%\AppData\Local\Packages.

arguments

Optional list of arguments.

launch

Supported values:

  • Exe
  • StoreApp

How to use it

The application is started automatically when you try to use it 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.

Elements object

Wraps the FlaUI access to the application.

public class CalculatorMainWindowElements
{
  private readonly FlaUIDriver _driver;

  public CalculatorMainWindowElements(FlaUIDriver driver)
  {
    _driver = driver;
  }

  public TextBox FirstNumberTextBox => _driver.Current.FindFirstDescendant("TextBoxFirst").AsTextBox();
  public TextBox SecondNumberTextBox => _driver.Current.FindFirstDescendant("TextBoxSecond").AsTextBox();
  public TextBox ResultTextBox => _driver.Current.FindFirstDescendant("TextBoxResult").AsTextBox();

  public Button AddButton => _driver.Current.FindFirstDescendant("ButtonAdd").AsButton();
}

Proxy object

Represents the application under test.

public class CalculatorProxy
{
  private readonly FlaUIDriver _driver;
  private readonly CalculatorMainWindowElements _elements;

  public CalculatorProxy(FlaUIDriver driver)
  {
    _driver = driver;
    _elements = new CalculatorMainWindowElements(driver);        
  }

  public void EnterFirstNumber(string number)
  {
    _elements.FirstNumberTextBox.Text += number;
  }

  public void EnterSecondNumber(string number)
  {
    _elements.SecondNumberTextBox.Text += number;
  }

  public void ClickAdd()
  {
    _elements.AddButton.Click();
  }

  public string GetResult()
  {
    return _elements.ResultTextBox.Text;
  }
}

Step definitions

[Binding]
public sealed class CalculatorStepDefinitions
{
  private readonly CalculatorProxy _proxy;

  public CalculatorStepDefinitions(CalculatorProxy proxy)
  {
    _proxy = proxy;
  }

  [Given("the first number is (.*)")]
  public void GivenTheFirstNumberIs(int number)
  {
    _proxy.EnterFirstNumber(number.ToString());
  }
}

FlaUI Interactions

FlaUIDriver.Current returns the automation element of the application's main window. Some common operations to get descendants or children without automation id are "ByName" or "ByClassName":

  • var okButton = _driver.Current.FindFirstDescendant(_driver.Get.ByName("OK"));
  • var otherWindow = _driver.Current.FindFirstDescendant(_driver.Get.ByClassName("Configuration"));

Examples can be found on the FlaUI website.

Appium-like Interactions

The class AppiumLikeInteractions is for convenience if you are familiar with Appium or if you migrate a project based on the SpecFlow.Actions.WindowsAppDriver .

public class CalculatorMainWindowElements
{
  private readonly AppiumLikeInteractions _interactions;

  public CalculatorMainWindowElements(FlaUIDriver driver)
  {
    _interactions = new AppiumLikeInteractions(driver);
  }

  public TextBox FirstNumberTextBox => _interactions.FindElementByAccessibilityId("TextBoxFirst").AsTextBox();
  public TextBox SecondNumberTextBox => _interactions.FindElementByAccessibilityId("TextBoxSecond").AsTextBox();
  public TextBox ResultTextBox => _interactions.FindElementByAccessibilityId("TextBoxResult").AsTextBox();

  public Button AddButton => _interactions.FindElementByAccessibilityId("ButtonAdd").AsButton();
}

The class CalculatorMainWindowElements from the example above with Appium-like interactions

How to get it

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

Latest version: Nuget

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows 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
1.0.3 95 9/19/2024
1.0.2 127 9/14/2024
1.0.1 122 6/10/2024
1.0.0 109 6/1/2024