How to: using PowerShell for automated testing of PowerApps

By | May 28, 2019

 

If you have not looked at the EasyRepro yet, you probably should:

https://github.com/microsoft/EasyRepro

I wrote a post about EasyRepro before with some explanations of how it works, so this may also be helpful:

https://www.itaintboring.com/dynamics-crm/easy-repro-what-is-it/

Now, I am not sure if Microsoft is “all in” on making PowerApps development a primarily dev-only activity, but, at the moment, it seems not everyone would have the skills and licenses to build tests in the Visual Studio, and, so, not everyone would be able to create tests in the Visual Studio. Otherwise, this whole post might not make a lot of sense since one might use Visual Studio Test tasks instead:

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/vstest?view=azure-devops

Yet EasyRepro github solution already provides over 200 sample tests:

image

However, what if we were more on the functional consulting side with limited access to the Visual Studio licenses (and to the skillset required to utilize all that)?

This is where, in theory, one might use PowerShell. Of course PowerShell itself is not necessarily one of those tools everyone would know how to use either, but, at least, it’s available pretty much anywhere. It’s also available in Azure Pipelines.

First things first, though. In order to use EasyRepro with PowerShell, some kind of wrapper module might be required which would expose EasyRepro methods as PowerShell cmdlets. I’ve started building one out, and it’s on the github here: https://github.com/ashlega/ItAintBoring.EasyReproPowershell

image

EasyRepro folder contains compiled EasyRepro dll-s. There is, also, a wrapper powershell module which defines the cmdlet-s. Of course it’s called EasyRepro.psm1. A few cmdlets have been added to far, but there is still work to do.

Azure-pipelines.yml is a build pipeline definition for the sample pipeline – you will see that pipeline below.

Settings.ps1 defines a couple of environment variables in case you wanted to run the tests manually (otherwise, those environment variables should be configured in Azure Pipelines)

Finally, RunTests.ps1 is an example of how to run the tests:

image

That script starts by importing EasyRepro.psm1 module. Then it defines a hashtable to store test results. After that, it defines a sample test (creating an account). And, finally, it proceeds to initialize EasyRepro, run the tests, clear EasyRepro objects (mostly to close the browser), and, then, does a bit of reporting on the results.

For example, the test above will fail since there is no “123name123” field on the account form. It’s easy to see if I just run the script manually. However, I can also use it in a build pipeline like this (notice the variables, btw. When running manually, they are defined in the settings.ps1):

image

This pipeline, once started, will fail with the error below:

image

And, if I wanted to review the details, I could always click on that failed step and see what happened:

image

Just as expected, there was a failure in the “Create Account” test.

Of course writing and maintaining those tests can still be a challenge, so I probably would not suggest going “all in” on automated testing with this. Although, it might make sense to spend that extra time and cover at least some of the core regression testing. As in the example above – creating an account should just work, all the time, so when there is a failure, it’s certainly a problem. Mind you it’s a problem with the test in this particular caseSmile

Leave a Reply

Your email address will not be published.