Coded UI Test in Visual Studio 2012

During my job I got a new challenge to test an application with manual and automated processes. So I accepted that challenge and did some hands-on testing. Here I am sharing my experience with my C# Corner family. In this challenge I created some CodedUI test using Visual Studio 2012. So here I am explaining step-by-step.

What testing is

Testing is used for locating the bugs in our application. It helps by finding the failures of the software before it crashes the application.

We have the following 2 types of testing.

Manual Testing
Automated Testing

Software Testing = Manual Testing + Automated Testing

Manual Testing

Manual testing is basically done by the user themself without any help of a script. Manual software testing is done by a human sitting in front of a computer carefully going through the application screens, trying in various uses and input combinations, comparing the results to the expected behavior and recording their observations. Test management can be taken care of by using test plans and test cases.

Automated Testing

Automated testing is done using some automated script and executing the scripts to run the application using some automation tool. Automated software testing is the best way to increase the effectiveness, efficiency and coverage of your software testing.

An automated testing tool is able to playback pre-recorded and predefined actions and compare the results to the expected behavior and report the success or failure of these manual tests to a test engineer.

Benefits of Automated Testing

  • Testing Improves Accuracy
  • Increases Test Coverage
  • Automation Does What Manual Testing Cannot
  • Automated QA Testing Helps Developers and Testers
  • Team Morale Improves

What a Coded UI is

A Coded UI is an automation framework that enables us to record a set of actions, creates the code for that and allows us to playback the recording for testing the application. It also gives the flexibility to write the custom code (hard-coded).

Automated tests that drive your application using its User Interface (UI) are known as Coded UI Tests (CUITs). These tests include the functional testing of the UI controls. They let you verify that the entire 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.

So, what do we need to create a CodedUI test with Visual Studio 2012?





Now we will learn step-by-step how to create a Coded UI test in Visual Studio 2012.

Open Visual Studio 2012 then select Create New project. Then select Test Template -> Coded UI Test Project.



Now It will ask you here to record or use an existing action. I will show with new action recording.



After clicking OK, a small window will appear in the botttom-right side in the task bar.



Here you can see 4 buttons in this window.



Now we will create a CodedUI test for a calculator. So click on the Start Recording button as in the following:



After clicking the Start Recording Button select Run Command then type "Calc".



Here you will see what action you will perform. It will show the preceding CodedUI window.









Now click on Pause Recording and click on the 4th button to generate the code for your actions.



Here provide a name for your method.





Here you will see some files and a test Method created.

Coded UI File Structure Coded UI maintains a specific file structure as follows: 

  • CodedUITest.cs file
  • UIMap.uitest file
  • UIMap.Designer.cs file
  • UIMap.cs file
CodedUITest.cs file: the CodedUITest.cs file is a unit test file having TestClass decorated with the [CodedUITest] attribute and contains multiple methods decorated with the [TestMethod] attribute.

UIMap.uitest file: UIMap.uitest is an XML file containing all the windows, controls, properties, methods, actions and assertions and so on used for playback.

UIMap.Designer.cs file: UIMap.the Designer.cs file is a partial class that contains the classes for various controls and their fields, properties and methods.

UIMap.cs file: UIMap.cs is also a partial class of UIMap.Designer.cs. It can contain all the recorded methods that need customization.

Now to run your test. So you can choose TEST from the Menu bar then select Run -> All test or the following option:





Now in the next article I will provide some more examples.

Up Next
    Ebook Download
    View all
    Learn
    View all