I was recently working on an established project that already had a collection of unit tests. I was trying to write a test for a complex record creation that has convoluted JavaScript automation that proved to be tricky using the backend APIs. So I thought why not retrospectively add EasyRepro and create the record using the front-end?
In the past I blogged about getting started with EasyRepro starting from the official GitHub repository. In this post I demonstrate how to retrospectively add EasyRepro to your unit test solution (or in this example from a blank unit test project).
Disclaimer I am bypassing some of the best practices just for the purpose of the demo. Please don’t save your password in plain text, don’t hard code things, and always refactor your code.
Steps
- From your Unit Test project add
Dynamics365.UIAutomation.Api and Selenium.WebDriver.ChromeDriver NuGet packages. - Add the following using statements to your unit test.
using Microsoft.Dynamics365.UIAutomation.Api.UCI;
using Microsoft.Dynamics365.UIAutomation.Browser;
using Microsoft.VisualStudio.TestTools.UnitTesting; - Add the following code to your Test – don’t forget to change the username, password, and url pointing to your instance.
var Options = new BrowserOptions
{
BrowserType = BrowserType.Chrome,
PrivateMode = true
};
var username = "username@yourorganisation.onmicrosoft.com";
var password = "password";
var xrmUri = new Uri("https://organisationname.crm.dynamics.com");
var client = new WebClient(Options);
using (var xrmApp = new XrmApp(client))
{
xrmApp.OnlineLogin.Login(xrmUri, username.ToSecureString(), password.ToSecureString());
xrmApp.Navigation.OpenApp("Sales Hub");
}
Your test is ready to run..
You can download the sample code from my GitHub repository https://github.com/ramimounla/SimpleEasyRepro.