Automated tests that drive your application through its user interface (UI) are known as Coded UI tests (CUITs). These tests include functional testing of the UI controls. They let you verify that the whole application, including its user interface, is functioning correctly. Coded UI Tests are particularly useful where there is validation or other logic in the user interface, for example in a web page. They are also frequently used to automate an existing manual test.

Use UI Automation To Test Your Code“, MSDN

Coded UI can be applied to Dynamics CRM to test if the user interface is functioning properly. You could also resort to this option should you want to know how or what steps are involved in the testing process. This will give you visual presentation of step-by-step testing of the system.

In this blog, I will demonstrate the procedure of building Coded UI testing fresh from the start as well as give you some insights and feedback on using this technology.

Base Instruction

  1. Open Visual Studio (I am using VS 2015). Create a new project, and under test, select a Coded UI Test Project.

coded ui test project

 

  1. In the Generate Code for Coded UI Test dialog box, choose Record actions, edit UI map or add assertions. Click OK.

generate-code-for-coded-ui-test

 

  1. Select Start Recording on the UIMap – Coded UI Test Builder.

 

coded-ui-test-builder

You can pause the recording if needed, for example, if you have to deal with incoming mail.

pause-coded-ui-test-builder

 

All actions performed on the desktop will be recorded. Pause the recording if you are performing actions that may lead to sensitive data being included in the recording. To start recording, choose the Record icon and make the actions that you want to test in your application.

In CRM side, you need to start performing the steps from logging into the application since there is a need to authenticate credentials before you can leverage the Dynamics CRM functionality. To delete actions that you recorded by mistake, choose Edit Actions. To generate code that will replicate your actions, choose the Generate Code icon and type a name and description for your coded UI test method.

  1. View your generated test method.

generated-test-method

 

  1. Add more actions and assertions. Place the cursor at the appropriate point in the test method, then on the shortcut menu, choose Generate Code for Coded UI Test. New code will be inserted at that point.
  2. Run the test. Use Test Explorer, or open the shortcut menu in the test method, and then choose Run Tests.

Problems/Issues Faced

As I was using Coded UI in Dynamics CRM 2016, I must say that there are some issues I faced in executing the test scripts.

  • Inconsistencies in results. There comes a time that it fails, while sometimes it executes successfully. Finding controls/UI elements is very slow and unstable, that is why there is a need to implement a playback to repeat the readings of UI controls if it failed to find the unique ID.
  • Sitemaps could not be read properly. As a workaround, you should access the desired entity URL.
  • Adding delays and WaitforControlReady also gives inconsistencies when reading controls. To resolve this, before I click a button, I make sure that the button is totally ready for execution. I added a condition that checks whether the WaitforControlExist and WaitforControlReady.

Conclusion

Coded UI Test when applied to Dynamics CRM is useful and a great way to present to client the visual procedures of how a specific functionality works. It could also save time to test a simple functionality. However, with increasing complexity, there might be some issues that could arise along the way.

The Coded UI is not yet stable in giving results when testing Dynamics CRM. Some factors that might affect the testing are the speed of the network and the loading speed of the browser which I think is essential in this test method since it is reading the control properties before executing it. Once it lags, it automatically won’t be able to find the control and execute it, and so it will fail. There are also inconsistencies in reading the control properties, sometimes it can locate the ID of the control, sometimes not.

Considering the pros and cons, it’s still your choice whether the Coded UI Test is applicable to what you aim for.

Happy CRMing!