Futile.SpecFlow.Actions.WindowsAppDriver 0.1.350.7

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

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

Futile.SpecFlow.Actions.WindowsAppDriver

Nuget

This SpecFlow.Action will help you use Windows App Driver together with SpecFlow. It handles the lifetime of the Windows App Driver, and the Appium instance created to interact with the application.

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

Updated examples can be found here: Futile.SpecFlow-Examples.

Prerequisites

Included Features

  • Lifetime handling of Windows App Driver and the application being tested
  • Configuration via specflow.actions.json
  • Automatic screenshot capture

Configuration

You can configure this plugin by adding a json file into your project named specflow.actions.json. Set the file as 'content' and to 'copy if newer'.

Example:

{
  "windowsAppDriver": {
    "capabilities": {
      "app": "../SpecFlowCalculator/bin/Debug/net5.0-windows/SpecFlowCalculator.exe"
    },
    "WindowsAppDriverPath": "C:/Program Files/Windows Application Driver/WinAppDriver.exe",
    "WindowsAppDriverPort": 4723,
    "EnableScreenshots": true,
    "CloseAppAutomatically": false
  }
}
  1. windowsAppDriver.capabilities - The capabilities used to configure the appium instance. In this case, we have provided the path to the WinForms application being tested (path is combined with the current directory, so you must take this into consideration)

    if (string.Equals(capability.Key, "app", StringComparison.OrdinalIgnoreCase))
    {
        options.AddAdditionalCapability(capability.Key, Path.Combine(Directory.GetCurrentDirectory(), capability.Value)); 
    }
    
  2. WindowsAppDriverPath - The path to the Windows App Driver CLI (must be absolute, not relative)

  3. EnableScreenshots - If no value is provided, then this resolves to false. If you want to enable screenshots, then set the value to true. Screenshots will be taken after each step automatically using the following folder structure: \TestResults\Screenshots\{yyyy-MM-dd_Hmmss}\{Feature title}\{Scenario title}\{Step name} ({execution status}).png e.g.

    \TestResults\Screenshots\2021-10-11_171822\Calculator\Add two numbers\the first number is 50 (OK).png
    
  4. WindowsAppDriverPort - If specified, the Windows App Driver will be launched using this port. If not specified, the default port 4723 will be used. (This setting is useful, if the default port is already in use by another application.)

  5. CloseAppAutomatically - This setting is optional and defaults to true. If false, the app will not be closed automatically after each scenario.

Important information

If you do not provide these configuration values, then the next default fallback is to check for the following environment variables:

Environment.GetEnvironmentVariable("TEST_SUBJECT_FILE_PATH");
Environment.GetEnvironmentVariable("WINDOWS_APP_DRIVER_EXECUTABLE_PATH")

The path to the test subject is required either from the configuration value, or the environment variable.

The path to the Windows App Drive CLI is not required, so if the configuration value and the environment variable returns null then the Windows App Drive CLI wont launch. This gives you the oppertunity for the Windows App Driver CLI to be handled via a CI/CD pipeline instead of having to manually install it on the agent.

How to use it

  1. Inject the AppDriver class into your consuming class using constructor/parameter injection inside of your test project. This will give you access to the current instance of the AppDriver. The lifetime of this object is handled and disposed once no longer required.

    public class CalculatorFormElements
    {
        private readonly AppDriver _appDriver;
    
        public CalculatorFormElements(AppDriver appDriver)
        {
            _appDriver = appDriver;
        }
    
        public WindowsElement FirstNumberTextBox =>
            _appDriver.Current.FindElementByAccessibilityId("textBox_firstNumber");
    
        public WindowsElement SecondNumberTextBox =>
            _appDriver.Current.FindElementByAccessibilityId("textBox_secondNumber");
    
        public WindowsElement AddButton =>
            _appDriver.Current.FindElementByAccessibilityId("button_add");
    
        public WindowsElement SubtractButton =>
            _appDriver.Current.FindElementByAccessibilityId("button_subtract");
    
        public WindowsElement MultiplyButton =>
            _appDriver.Current.FindElementByAccessibilityId("button_multiply");
    
        public WindowsElement DivideButton =>
            _appDriver.Current.FindElementByAccessibilityId("button_divide");
    
        public WindowsElement ResultTextBox =>
            _appDriver.Current.FindElementByAccessibilityId("textBox_result");
    }
    
  2. The handling of the AppDriverCli class is abstracted away inside the plugin, so there is no need for you to do anything here. If you do not need the plugin to handle the Windows App Driver CLI, then do not provide the path in the configuration or the environment variable demonstrated below.

    public void Start()
    {
        var path = _windowsAppDriverConfiguration.WindowsAppDriverPath ??
                  Environment.GetEnvironmentVariable("WINDOWS_APP_DRIVER_EXECUTABLE_PATH") ?? null;
    
        if (path != null)
        {
            _appDriverProcess = Process.Start(path); 
        }
    }
    

How to get it

Add the latest version of the Futile.SpecFlow.Actions.WindowsAppDriver 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.7 81 9/19/2024
0.1.350.6 125 9/14/2024
0.1.350.5 272 10/21/2023
0.1.350.4 153 10/11/2023
0.1.350.3 144 10/8/2023
0.1.350.2 147 10/7/2023 0.1.350.2 is deprecated because it has critical bugs.
0.1.350.1 138 10/1/2023