📜 ⬆️ ⬇️

Testing UI with Coded UI Test

image
In the life of any serious project a lot of attention is always paid and a lot of testing time. The testing process may take several hours, and may take weeks, it all depends on the size of your project. There are many options for testing your solution. Visual Studio 2010 has a new way of testing, which makes it easy to find flaws in the graphical interface.

 

I will demonstrate the new features of Visual Studio using the example of a WPF application. imageimage

For simplicity, the application will be able to perform two normal operations: addition and division. Now, let's add a testing project to our solution (Test -> New Test). image
')
Visual Studio prompts you to select a test creation script. In this example, I will use the second item (UI Recorder), which is very similar to the well-known Web Recorder in IE.
imageimage

After I chose the right script, I need to record some actions using the recorder. I propose to write a simple script - the addition of numbers. To do this, I click the Record Action button and perform the required operations. image


We see that Recorder recognized the elements and the events of our application - this is a huge innovation in comparison with Web Recorder. In this case, the analysis of events and elements occurs at a lower level, I want to note that recognition for different applications works differently, and for some it is not supported at all. The list of supported applications is described in the table below. image

The final version of Visual Studio 2010 will allow you to create UI tests for the main types of applications, which will allow you to use this type of tests without any special problems. After the UI Recorder has recorded all the steps I have done, I can save them as the .Net Static Method and use it anywhere in my test project. All recorded methods are stored in the RecordedMethods class, which, if desired, can always be changed. image

Visual Studio searches for items using the filters described in the “Search Criteria” areas. Coded UI Test allows you to check the parameters of the elements by using the binding (UI Locator). imageimage

Using “Sight”, I chose an element of interest to me - a label with the result. When we click the save button, Visual Studio will create a UIMap class describing the selected item and make it available within my project. image

Now let's take a practical look at how this opportunity can be applied. To do this, I must pass the UIMap class to a previously written method. image

Suppose I want to check how the addition operation works in my application. To do this, I will add the ability to read parameters from the console when the test is run. image

In the last step, I need to create a simple validation logic in the required method. This can be done using the AreEqual method of the Assert class. image

And finally, let's run our test and see how our application works correctly. image

This is a new feature appeared in VS10, I hope you will find an application for it.

Source: https://habr.com/ru/post/65632/


All Articles