Selenium with Dynamics CRM Automating Clicks in Navigation Groups | Magnetism Solutions | NZ (Auckland, Wellington, Christchurch and Dunedin)

Dynamics 365 is Better with Infinity Buttons. Try it for Free for 30 Days

Selenium with Dynamics CRM Automating Clicks in Navigation Groups

Miguel Nepomuceno, 03 October 2016

I’ve been experimenting with different types of test automation tools such as Selenium with Microsoft Dynamics CRM. So far, I’ve been experimenting with how I can navigate through a Microsoft Dynamics CRM solution such that I can simulate test cases and automate tests later on. Selenium is a tool suite to automate web browsers across many platforms, primarily used for test automation. It is a popular open-source software that can be deployed across Windows, Linux and Macintosh platforms.

Working with the Microsoft .NET stack and Microsoft Dynamics 365 means I can use the Visual Studio IDE to execute and automate my tests with Selenium. Using the Selenium WebDriver allows me to identify browser elements and execute various actions such as clicks, enter text and selecting option sets. With Visual Studio, I can use the Selenium WebDriver with the NUnit framework to run my automated tests and validated results (e.g. using Assert and Verify methods).

Web browsers usually have a navigation path contained in URL to indicate web pages or web content (for example: websiteURLexample.com/homepage/contactspage). Since components in Microsoft Dynamics 365 are composed primarily via forms and don’t show navigation paths via URL link, being able to automate and access the sitemap is crucial in making our test cases. Using Selenium with Visual Studio allows me to navigate the Dynamics CRM solutions with the following example code:

image

Easy as that right? Well, the problem in regards to navigating the sitemap with the following example code is that the areas in the sitemap don’t fully drop down to show all the groups and subareas when simulating to click the button. For the example code above, I wanted to automate navigation of the sitemap in Dynamics CRM by clicking the sitemap home button, then clicking the Sales area button, and then finally clicking the Accounts subarea button (which would hopefully take me to Accounts).

image

If you encounter a NoSuchElement Exception from this example test code, this means that the Accounts subarea element does not exist, in context with the WebDriver not being able to find and use the Accounts subarea element.  After further investigation, this exception occurs even though the button attribute is set as selected. Inspecting the browser elements shows the Sales button element is set as selected, and would also visually be shown as selected when conducting the automated test case.

I would usually execute all my manual testing with Internet Explorer 11 for Dynamics CRM but it was more convenient for me to learn Selenium by using the Chromium Chrome Web Driver. My final conclusion was that it was an unusual behaviour attributed to using Dynamics CRM with Chrome considering the various bugs that are evident with Dynamics CRM in Chrome.

Threading and Loading

The Threading class allows for parallel execution such that we can create applications that use more than one thread of execution. By stating the following line of code below, we can dictate to the current thread of execution to wait for an extended stated amount of time (e.g. 2 seconds) before automating the click action. This way, it gives the associated subareas and groups time to load, seeing as how the Selenium Web Driver automates browser functions quickly when simulated.

image

For our example code, test automation would execute and automate navigation of the sitemap in Dynamics CRM by clicking the sitemap home button, then clicking the Sales area button. It would then wait for 2 seconds after the FindElement() call to load all the attributed groups and subareas for the Sales area, and then finally clicking the Accounts subarea button (which would hopefully take me to Accounts). Voila!

For testers who are new to test automation or do not have a lot of programming experience with testing for web browser applications, I imagine it would be difficult to encounter weird behaviours such as this (seeing as how users may have already been accustomed to and familiar with the system you are testing). It is important to recognize unusual test automation behaviours compared to how we intend and expect our automations to execute. Hopefully, using the following solution can solve any similar problems relating to NoSuchElement exceptions and loading system components when conducting test automation. Best of luck my fellow testers!