Coded UI Framework Visual Studio 2013

The ability to test a web-based solution was the most interesting feature of Visual Studio 2010 but the major limitation of this technology was that it only supported the Internet Explorer browser. Visual Studio 2013 provides many improvements and the major one is that we can now test the UI of not only Internet Explorer (including Internet Explorer 11) but also all other modern browsers, such as Google Chrome and Mozilla Firefox. But this article is not about comparing Visual Studio versions. We will instead understand how to use the coded UI framework.

Environment setting

To start you need to first install either Visual Studio 2013 Ultimate or Premium from MSDN. Refer to the link: Installing Visual Studio.

Procedure to create a simple coded UI test in Visual Studio 2013

  1. Open Visual Studio as “Administrator” and go to File -> New -> Project.

  2. The New Project dialog opens, select “Coded UI Test Project”.

    coded test project

  3. The “Generate code for coded UI test” dialog appears, click on the cancel button (we will not be using a coded UI record/playback).

    coded ui

  4. Go to the Solution folder and delete the “CodedUITest1.cs” class file.

    coded ui test

  5. Right-click on test Project and add one class file (the LoadGooglePage.cs file).
    1. namespace TestCodedUI   
    2. {   
    3.       using Microsoft.VisualStudio.TestTools.UITesting;   
    4.       using Microsoft.VisualStudio.TestTools.UnitTesting;   
    5.       using System;   
    6.       [CodedUITest]   
    7.       public class LoadGooglePage   
    8.       {   
    9.             private const string BaseURL = "https://www.google.com/";   
    10.             [TestMethod]   
    11.             public void SearchTest()   
    12.             {   
    13.                   BrowserWindow window = BrowserWindow.Launch(BaseURL);   
    14.             }   
    15.       }   
    16. }  
  6. Click on build solution (or press Ctrl+Shift+B). To run a test case go to Test -> Windows -> Test Explorer and then right-click on test case and select “Run Selected tests”.

    run selected test

The test case starts executing. The Google search page opens and the test case es. In this article I have not implemented the concept of test case validation using “Assertions “ and web element interaction. I will do that in my next article. It was just a basic coded UI test to get started with the framework and I hope you like it.


Similar Articles