EasyRepro – Retrieve record to validate test case

By | June 9, 2020

Introduction

EasyRepro is the library that provides Dynamics 365 CRM developers the ability to facilitate automated UI testing. It provides several methods to interact with Dynamics 365 CRM UI and allows us to use those to perform automated UI testing.

In this blog, we will share one hack that we used to validate the test case.

While working on the UI automation of the project, we reached to the point where we wanted to check whether a record of a particular entity is created in the background on some action.

Often in our Dynamics 365 CRM project, we create or update records (OOB entity records or custom entity records like Setting, Configuration) in the background when some operation is performed in the Dynamics 365 CRM UI.

Our test case consists below steps,

  • On HTML Webresource fill up the details
  • Click on the submit button

The expected result is that the record of the custom entity called Setting should get created in the background.

We can validate this test case by navigating to the sitemap and to the view of Setting entity. However, in our case the Setting entity is not present on the sitemap.

So how we can check the record is created or not?

Well, we found Xrm.WebApi client API helpful to get this job done. We use ExecuteScript method of Selenium and execute the JavaScript code that returns the record using Xrm.WebApi.retrieveMultipleRecords method.

IJavaScriptExecutor js = (IJavaScriptExecutor)driver;

Dictionary<string, object> recordData = (Dictionary<string, object>)js.ExecuteScript(“return Xrm.WebApi.retrieveMultipleRecords(‘ikl_setting’).then(function(result){ return result;}, function(error){ return error;})”);

This single line of code gives us the entity record object. We can then use this result to validate our test case.

EasyRepro - Retrieve record to validate test case

Conclusion

Thus we can validate the test case by retrieving the actual data from CRM.