Automation Testing for Dynamics 365 Using Selenium

Automate Dynamics CRM using Selenium with Visual Studio C#: Basics

In today’s world everything is evolving at such a high pace that it’s hard to keep up. Similarly, many of the techniques and technologies in the IT world are surfacing every day while the previous ones go obsolete. If we look at this from a testing point of view we will notice that “ Automation Testing ” is becoming key for many problems being faced in the IT world - not only is it providing effective solutions to the problems but also improving the rapidity of providing results.

Dynamics CRM is extensively being used as a platform where business applications are being developed on top of existing xRM platform. By developing automation testing solutions, we can speed up the process where applications developed with Dynamics CRM are easily tested. This means as new modules are being developed, old modules get mature but still they need to be tested before deployment. It is important to maintain regression suites of mature modules for making sure that application is stable over time and after number of deployments.

The recommended tool that can be used for implementing and integrating the automation process with CRM is “Selenium”. Selenium is an open source automation testing tool that can interact with Dynamics CRM in multiple programming languages during its implementation phase. It can be used for developing and maintaining the automation test suites. Selenium web driver allows you to identify different elements and perform actions on the application under scope. The elements include text boxes, clicks, keystrokes and substituting buttons with mouse movement during interactions.

Tools Required to Integrate Selenium with Microsoft Dynamics CRM

Now let’s get to the part where we can learn how to automate our Dynamics CRM test suites using selenium with Visual Studio 2017 Enterprise edition (C#).

  1. Download and Install Visual Studio 2017 Enterprise Edition
  2. Create the new project of type Test
  3. Right click on the project name and click on Manage NuGet packages
  4. Download and install NUnit
  5. Download and install NUnit3TestAdapter
  6. Download and install Selenium.Support
  7. Download and install Selenium.WebDriver
    • Download and install Selenium.WebDriver.ChromeDriver
    • Download and install Selenium.WebDriver.IEDriver

How to write automation Scripts for projects in CRM

Now that we have downloaded all the necessary tools required, let’s learn how to write automation scripts in selenium.

 

Step 1: Setup the webdriver (Chrome, IE or any of the choice) and setup the page timeouts as per the environment.

 

SetUp Selenium for Automation Testing in Dynamics CRM

 

Step 2: Now write your test cases and test methods and try to do exception handling just to be sure of what type of error is encountered during the execution or debugging.

TestCase in Selenium for CRM Automation Testing

 

Step 3: After that, start defining the Web Element controls using “findElementBy,”. Xpath is preferred as an Identifier as it is directly associated with Chrome for any controls and evades setbacks for any other identifier written by developers.

 

Step 4: The challenge that is mostly faced is associated with the Webdriver in CRM when taking click() action; it keeps the emphasis on the clicked element even if it causes a navigation already. Since CRM is implemented as a Single App page, it contains frames. When stuck, you just need to switch focus to the desired frame by getting it through firebug or another investigating tool.

 

Step 5: Some of the CRM structures that have been discovered during our exploration are mentioned below

- Whole App page
- iFrames
- Divs and spans
- Controls (Input, Auto-complete, Button,…etc)

 

You need to identify WebElements starting from Divs then perform the click() action to be able to see your controls. Afterwards, you can perform any action on page controls such as sendKeys(), click(), getText(), etc.

 

Step 6: There are multiple ways which can help in implementing and recognizing the elements that are clicked:

- ImplicitWait
- ExplicitWait
- Execution Pause Time

 

Implicit Wait:

It enables driver to wait for all elements to be loaded in a page for specific seconds or minutes.

Example:
webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMinutes(3);
webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(3);
webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromMinutes(3);

 

Explicit Wait:

It postpones Webdriver so that a specific element can be displayed, located or is clickable.

Example:
var wait = new WebDriverWait(webDriver,TimeSpan.FromSeconds(timeoutInSeconds));
wait.Until(ExpectedConditions.ElementIsVisible(by));

Execution Pause Time:

It holds the execution for the defined time.

Example:
Thread.sleep(5000); //waits for 5 seconds

 

Step 7: You can run the script in any language you want i.e. C#, Java, Python. I prefer C# therefore all these examples are C# specific.

 

I hope this blog will help you perform automation testing on Dynamics CRM so you could deliver BOLDQuality solutions.