A SpecFlow bindings library for Power Apps.
The aim of this project is to make Power Apps test automation easier, faster and more accessible. It does this by providing a library of generic SpecFlow step bindings that adhere to test automation best practices. This allows effective automated tests to be written without the dependency on developers who are both proficient with Power Apps and test automation.
Follow the guidance in the Installation and Setup section in https://specflow.org/getting-started/. After installing the IDE integration and setting up your project, install the NuGet package.
PM> Install-Package Capgemini.PowerApps.SpecFlowBindings
Once the NuGet package is installed, follow the SpecFlow documentation on referencing an external binding library. At the time of writing - for SpecFlow 3.x - you should update a specflow.json file in your project root as follows -
{
"stepAssemblies": [
{ "assembly": "Capgemini.PowerApps.SpecFlowBindings" }
]
}
We do not have a dependency on any specific WebDrivers. You will need to ensure that the correct WebDrivers are available in your project based on the browser that you are targetting. For example - if your configuration file is targetting Chrome - you can install the Chrome WebDriver via NuGet -
PM> Install-Package Selenium.Chrome.WebDriver
Installing the NuGet package creates a power-apps-bindings.yml file in your project's root. This is used to configure the URL, browser, and users that will be used for your tests.
url: SPECFLOW_POWERAPPS_URL
browserOptions:
browserType: Chrome
headless: true
width: 1920
height: 1080
startMaximized: false
users:
- username: SPECFLOW_POWERAPPS_USERNAME_SALESPERSON
password: SPECFLOW_POWERAPPS_PASSWORD_SALESPERSON
alias: a salesperson
The URL, usernames, and passwords will be set from environment variable (if found). Otherwise, the value from the config file will be used. The browserOptions node supports anything in the EasyRepro BrowserOptions
class.
You can use the predefined step bindings to write your tests.
Scenario: User can create a new account
Given I am logged in to the 'Sales Team Member' app as 'an admin'
When I open the 'Accounts' sub area of the 'Customers' group
Then I can see the 'New' command
Alternatively, write your own step bindings (see below).
You can write your own step bindings that have thread-safe access to EasyRepro and the Selenium WebDriver. This ensures that your tests can be ran safely in parallel. You can do this by creating a class decorated with the SpecFlow BindingAttribute
and inheriting from the PowerAppsStepDefiner
base class. You can then create your SpecFlow step bindings by interacting with the XrmApp
and Driver
properties.
[Binding]
public class MyCustomSteps : PowerAppsStepDefiner
{
[Given(@"I have a custom step")]
public void GivenIHaveACustomStep()
{
// Interact with the inherited EasyRepro 'Browser' object.
// Interact with the inherited Selenium 'Driver' object.
}
}
We are avoiding performing test setup via the UI. This speeds up test execution and makes the tests more robust (as UI automation is more fragile than using supported APIs). Given steps should therefore be carried out using the Client API, WebAPI or Organization Service.
You can create test data by using the following Given step -
Given I have created "a record"
It will look for a JSON file in the data folder. You must ensure that these files are copying to the build output directory. You do not need to include the .json extension when writing the step (the example above would look for 'a record.json').
The JSON is the same as expected by WebAPI when creating records via a deep insert. The example below will create the following -
- An account
- An primary contact related to the account
- An opportunity related to the account
- A task related to the opportunity
{
"@logicalName": "account",
"@alias": "sample account",
"name": "Sample Account",
"primarycontactid": {
"firstname": "John",
"lastname": "Smith"
},
"opportunity_customer_accounts": [
{
"name": "Opportunity associated to Sample Account",
"Opportunity_Tasks": [{ "subject": "Task associated to opportunity" }]
}
]
}
The @logicalName
property is required for the root record.
@alias
property can optionally be added to any record and allows the record to be referenced in certain bindings including the json for subsequent data creation steps per the example below:
Step 1 Given I have created "a contact"
{
"@logicalName": "contact",
"@alias": "sample contact",
"firstname": "John",
"lastname": "Smith"
}
Step 2 Given I have created "a account"
{
"@logicalName": "account",
"@alias": "sample account",
"name": "Sample Account",
"[email protected]": "sample contact"
}
Ensure that your changes are thoroughly tested before creating a pull request. If applicable, update the UI test project within the tests folder to ensure coverage for your changes.
Power Apps SpecFlow Bindings is released under the MIT licence.