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
- Open Visual Studio as “Administrator” and go to File -> New -> Project.
- The New Project dialog opens, select “Coded UI Test Project”.
- The “Generate code for coded UI test” dialog appears, click on the cancel button (we will not be using a coded UI record/playback).
- Go to the Solution folder and delete the “CodedUITest1.cs” class file.
- Right-click on test Project and add one class file (the LoadGooglePage.cs file).
- namespace TestCodedUI
- {
- using Microsoft.VisualStudio.TestTools.UITesting;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using System;
- [CodedUITest]
- public class LoadGooglePage
- {
- private const string BaseURL = "https://www.google.com/";
- [TestMethod]
- public void SearchTest()
- {
- BrowserWindow window = BrowserWindow.Launch(BaseURL);
- }
- }
- }
- 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”.
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.