Code Monkey home page Code Monkey logo

powerautomate-testenginemodule's Introduction

Power Automate - Test Engine Module

This repository provides a proof of concept implementation of unit testing for Power Automate Cloud flows making use of extensions to the Power Apps Test Engine.

Key concepts demonstrated by this sample:

  • Make use of extensibility model of Power Apps Test Engine to implement a Power Automate unit test provider

  • Implement new Power FX actions that allow mocking of automation actions and triggers

  • Validate the logic path of the cloud flow

  • Assert the results of process and workflow results

Prerequisites for building module

  1. Install .NET Core 6.0.x SDK

  2. Ensure that your MSBuildSDKsPath environment variable is pointing to .NET Core 6.0.x SDK.

Getting Started

  1. Clone the repo and submodules
git clone --recurse-submodules https://github.com/Grant-Archibald-MS/PowerAutomate-TestEngineModule.git
  1. Build the module
cd PowerAutomate-TestEngineModule\src
dotnet build
  1. Run sample test
cd ..\samples\basic
dotnet ..\..\PowerApps-TestEngine\bin\Debug\PowerAppsTestEngine\PowerAppsTestEngine.dll -i testPlan2.fx.yaml -t 00000000-0000-0000-0000-000000000000 -e 00000000-0000-0000-0000-000000000000 -p powerautomate -u local

Read More

Want to discover more about using Test Engine to test Power Automate Cloud flows? Our README.md provides more information.

powerautomate-testenginemodule's People

Contributors

grant-archibald-ms avatar

Watchers

 avatar

powerautomate-testenginemodule's Issues

[PowerAutomate-TestEngineModule - Feature]: Extend MockAction() to Accept JSON

Is your feature request related to a problem? Please describe.

As shown in testPlan2.yaml the current MockAction() Power FX function accepts an action name and boolean for success / failure

While this enables mocking of actions it does not provide the ability to mock the action output.

Describe the solution you'd like

Add a new optional pamarameter for the MockAction that allows the action name, complete with success and action output as json

For example:
MockAction("Get_a_record_-_Valid_Id", true,"{'accountid':1, 'name':'test'}");

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Download workflow from Dataverse

Is your feature request related to a problem? Please describe.

The current version of OpenWorkflow() provides the ability to load the definition of the Power Automate Cloud Flow from a local json file like PowerAutomateMockUpSampleFlow.json

From this solution to work that definition of the cloud flow needs to be saved to source control or unpacked.

Describe the solution you'd like

Provide an alternative implementation that allows the definition of solution aware Cloud Flows to be downloaded from the Dataverse Workflow.

Provide new IUserManager implementations that provide for Managed Identity and Service Principal to authenticate with dataverse to query the workflow definition

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Extend MockAction for error result

Is your feature request related to a problem? Please describe.

The current MockAction() allows for True or False to indicate the success of an Action.

Allowing for error state information would allow for testing of Error handling and Scope used to Try / Catch errors

Describe the solution you'd like

Extend the function to allow for unsuccessful actions to specify an error type and message. For example

MockAction("Get_a_record_-_Valid_Id", false, "{'error':true, 'type':'Timeout', 'message':'Unable to reach https://contoso.crm.dynamics.com', 'count':1}")

In this example the first request for the action the action request should fail, if a second time the action is called it should be successful.

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Unit Test State using Power FX

Is your feature request related to a problem? Please describe.

While MockAction provides the ability to test call and set the ActionOutput. Extend this functionality by the ability to control variable state and expression evaluation using Power FX

Describe the solution you'd like

Make use of Power FX Recalc engine and UpdateVariable and Eval functions from inside the Test Engine ITestEngineModule

Power Fx is a C# Plugin with PowerFx.Interpreter
var powerFxConfig = new PowerFxConfig(Features.PowerFxV1);
_engine = new RecalcEngine(powerFxConfig);
_engine.UpdateVariable(key, value.ToString());
var newValue = _engine.Eval(text.Substring(1));

Implement mapping of expression to Power FX functions.

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Video Demo

Is your feature request related to a problem? Please describe.

To help communicate the concepts in Docs and show a live demo a test

Describe the solution you'd like

Cover the following key elements:

  • How this project used the extension model of the Power Apps Test Engine to include use cases for Power Automate Cloud flows
  • What the expected DevOps model from local development model, CI/CD deployment model and gated deployment
  • What is the extension model Authentication, Providers, Power FX actions
  • Interactive demo of a test case executing

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Support Comments in Test Case steps

Is your feature request related to a problem? Please describe.

The current implementation of the Test case steps does not support comments in the Test Steps.

The addition of comments would allow additional context and structure to be added to the step

Describe the solution you'd like

Allow for comments on a separate line starting with //

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: New IUserManager for Dataverse access

Is your feature request related to a problem? Please describe.

The current testengine.user.local module implements local authentication assuming the files already exist.

Create new IUserManager implementation that provides authentication with Datavesre to retrieve the workflow

Describe the solution you'd like

Consider the following:

  • Interactive user login
  • Service Principal authentication
  • Managed Identity authentication

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Documentation of Power FX Functions.

Is your feature request related to a problem? Please describe.

Provide documentation and examples for

Also add documentation on how other PowerFX functions like With can be used to validate the values returned from Power FX functions

Describe the solution you'd like

Describe what each function, why the function is important and provide examples of how each function can be used

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Pipeline Quality Gate

Is your feature request related to a problem? Please describe.

Created tests run locally, demonstrate how the created tests can be included as a quality gate prior to deployment to a new environment

Describe the solution you'd like

Demonstrate how extensibility points of Pipelines for Power Platform could execute tests.

Optionally provide an example of how to prevent the deployment of a solution if tests fail

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Add Sample of unit test child flow

Is your feature request related to a problem? Please describe.

The basic example demonstrates unit testing of a single cloud flow.

Describe the solution you'd like

Demonstrate how to unit test two related cloud flows. The first cloud flow that calls a child flow and tests for the child flow

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Test Cases for Cloud Flow

Is your feature request related to a problem? Please describe.

Provide examples of how-to unit test control logic, expressions and control logic

Describe the solution you'd like

Provide test case implementation examples of:

Key concepts to consider:

  • Initialize, Set, Increment and Decrement Variables
  • Evaluation of expressions with variables and control results

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: JSON data type mapping

Is your feature request related to a problem? Please describe.

The TriggerWorkflow Power FX provides the ability to specify JSON of the input to use trigger the unit test.

The current support exists to map String, Boolean and Numeric values

Describe the solution you'd like

Extend the function to also support:

  • Dates
  • GUID
  • The results of PowerFX expressions. PowerFX expressions should be a string and start with =

Some examples of possible Power FX expresions {'id':GUID()'} or {'created':'=Now()'}

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Sample Loop

Is your feature request related to a problem? Please describe.

Extend on the basic example to demonstrate how to unit test a loop.

Describe the solution you'd like

Implement new samples that demonstrate how to create simple and edge cases for loops

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Add TriggeredActions() and GetActionOutput()

Is your feature request related to a problem? Please describe.

The TriggerWorkflow() returns the total number of actions executed.

Expand additional functions that provide more information on each of the actions executed in the test case.

Describe the solution you'd like

Consider adding the following Power FX functions:

  • TriggedActions() which should return a Table of records like {action:"Action Name", count: 1} so that list of actions and count of times called is available
  • GetActionOutput(actionName) which should return JSON of the output of an action

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Add VerifyAction() Power FX

Is your feature request related to a problem? Please describe.

As shown in testPlan2.yaml MockAction() can be used to set the continue execution state for an action

The addition of VerifyAction() would allow checks to be created to determine if an action was called and how many times.

Describe the solution you'd like

Provide a new VerifyAction(actionName, occurrences) function

actionName would the name of the action
occurrences would be optional but allow the expected number of times that the action should be called

Describe alternatives you've considered

No response

Additional context?

No response

[PowerAutomate-TestEngineModule - Feature]: Integration Test Examples

Is your feature request related to a problem? Please describe.

The samples basic sample illustrate how to perform a local unit test.

As part of the overall testing scenario there is also a place for integration test that run the Cloud flow.

Describe the solution you'd like

Provide examples of:

  • Using Static Results
  • How to trigger workflows with different trigger types. For example Dataverse Trigger

Describe alternatives you've considered

No response

Additional context?

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.