Skip to content

Power Automate: Mock action outcomes

Learn how to speed up your Power Automate flows testing by mocking action outcomes using the “static result” action property. Speed up your testing, and reduce these ten minutes of wasted time per run, to zero minutes!

Imagine this scenario. You are building a complex Power Automate flow which involves hundreds of actions. You want to test a specific section, which unluckily comes after a five-layer approval, therefore, every time you want to test your section, you’re wasting at least ten minutes to complete all the five layers of approvals, before you can get to the section which you actually want to test. The worst part of the process is that the approvals aren't what you're after, they're already tested: what you want is for the flow to proceed to the section you  do want to test.

Well… you don’t need to deal with this frustration anymore.

In this blog post, you’ll learn how to speed up your testing, and reduce these ten minutes of wasted time per run, to zero minutes. Yes… ZERO!

One of the most time-consuming actions to complete is the “Start and wait for an approval”. This is because you must leave your flow designer, open Teams or Outlook, find your notification and complete the approval, then come back to the designer. So, for this blog post, I chose the “Start and wait for an approval” action as our example for a long running action whose outcome we can mock. However, you can use the same concept for most actions.

Let’s see how it works

In the steps below we will mock the outcome of the “Start and wait for an approval” action.

We will do it in two steps:

  1. Capture the action’s outcome
  2. Configure the action to return the same outcome for future flow runs, without manual intervention

  1. Capture the action’s outcome
    1. Create a new, manually triggered, flow with two actions:
      1. Start and wait for an approval
      2. And Compose
        PowerAutomate-1

    2. For Start and wait for an approval action, fill in the fields as you please
    3. In the Compose action, enter the outcome of the Start and wait for an approval action:

    outputs('Start_and_wait_for_an_approval')?['body/outcome']

  2. Use the Start and wait for an approval outcome for future flow runs
    1. Run the flow once, and complete the approval
    2. Now, go to your flow history and open the last run instance
      PowerAutomate-2

    3. Expand Start and wait for an approval
    4. Click on Show raw outputs
      PowerAutomate-3

    5. Copy the body, starting with: “body”, all the way to the closing bracket: }
      PowerAutomate-4

    6. Now, in the flow editor, click on the three dots on the Start and wait for an approval action –> Static result (Preview)
      PowerAutomate-5

    7. Toggle Enable Static Result (Preview)
      PowerAutomate-6

    8. Click on Switch to JSON mode
      PowerAutomate-7

    9. The static result will show up without a “body” key/value:
      PowerAutomate-8

    10. Add a comma after the “headers” line
    11. Paste the body you copied in step (5) above, on a new line
      PowerAutomate-9

    12. The full JSON looks like the following:
      PowerAutomate-10

    13. Click Done
    14. Now run your flow
    15. It will skip running the Start and wait for an approval action, while Compose will still show the outcome that you selected in step (1) above
      PowerAutomate-11

A few notes

  1. Notice that when we manually completed the approval action the first time, it took 26 seconds:

PowerAutomate-12

  1. While when we used the mock result, it took zero seconds

  PowerAutomate-13

  1. The beaker icon means that the flow has used the mock result

PowerAutomate-14

In conclusion

Mocking action outcomes is one of the less-known features of Power Automate which can save us, developers, a lot of time. Even though we demonstrated the feature on the “Start and wait for an approval” action, the feature is available for most actions in Power Automate. I encourage you now to go ahead and try it on a different action.

If you need to automate a simple or complex process, but don’t know where to start, DevFacto is here to guide you on your journey to automation. Schedule a consult today to learn more about how we can help you automate your business in ways humans will love to use! Let us put the “auto” in automation so that you and your team can focus on what matters most!

 


 

About the author

Wisam Fawzi is a senior consultant with our Modern Workplace practice and is based in Edmonton, Alberta. Armed with a computer engineering degree he has been delivering SharePoint and business process automation projects for 11+ years. When Wisam is not building software, you will find him at the gym or on the squash court. Connect with him on LinkedIn!

About the artist

Jeff Martin is an award-winning cartoonist and comics educator from Edmonton, Alberta, and is definitely not a robot. When not at comic book conventions or teaching classes, he can usually be found in the section of his living room that he refers to as his “comics bunker,” which doesn't make him sound crazy at all. 

You can find his webcomic, Hell, Inc. at his website, hell.rentathugcomics.com, and keep up with his machinations on Twitter @HEATcomic

He writes... "To me, the idea of future-proofing and risk readiness speaks toward anticipating what is coming and preparing for it, which immediately made me think of wizards scrying the future to formulate their plans. To be fair, though, most ideas can lead me to wizards."

 


 

References:

Test workflows with mock data in Azure Logic Apps (applies to Power Automate as well): https://docs.microsoft.com/en-us/azure/logic-apps/test-logic-apps-mock-data-static-results?tabs=consumption