Skip to main content

Creating Coded UI Test

  1. Create a Coded UI Test project.
    Coded UI tests must be contained in a coded UI test project. If you don’t already have a coded UI test project, create one. In Solution Explorer, on the shortcut menu of the solution, choose AddNew Projectand then select either Visual Basic or Visual C#. Next, choose TestCoded UI Test.

    • I don't see the Coded UI Test project templates.
      You might be using a version of Microsoft Visual Studio 2012 that does not support coded UI tests. To create coded UI tests, you must use either Visual Studio Ultimate or Visual Studio Premium.
  2. Add a coded UI test file.
    If you just created a Coded UI project, the first CUIT file is added automatically. To add another test file, open the shortcut menu on the coded UI test project, point to Add, and then choose Coded UI Test.
    Create a coded UI test
    In the Generate Code for Coded UI Test dialog box, choose Record actions, edit UI map or add assertions.
    Select record actions
    The Coded UI Test Builder appears and Visual Studio is minimized.
    Coded UI Test Builder
  3. Record a sequence of actions.
    To start recording, choose the Record icon. Perform the actions that you want to test in your application, including starting the application if that is required.
    For example, if you are testing a web application, you might start a browser, navigate to the web site, and log in to the application.
    To pause recording, for example if you have to deal with incoming mail, choose Pause.
    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.
  4. Verify the values in UI fields such as text boxes.
    Choose Add Assertions in the Coded UI Test Builder, and then choose a UI control in your running application. In the list of properties that appears, select a property, for example, Text in a text box. On the shortcut menu, choose Add Assertion. In the dialog box, select the comparison operator, the comparison value, and the error message.
    Close the assertion window and choose Generate Code.
    Coded UI test targeting element
    Tip Tip
    Alternate between recording actions and verifying values. Generate code at the end of each sequence of actions or verifications. If you want, you will be able to insert new actions and verifications later.

  5. View the generated test code.
    To view the generated code, close the UI Test Builder window. In the code, you can see the names that you gave to each step. The code is in the CUIT file that you created:
        [CodedUITest]
        public class CodedUITest1
        { ...
          [TestMethod]
          public void CodedUITestMethod1()
          {
              this.UIMap.AddTwoNumbers();
              this.UIMap.VerifyResultValue();
              // To generate more code for this test, select 
              // "Generate Code" from the shortcut menu.
          }
        }
    
  6. Add more actions and assertions.
    Place the cursor at the appropriate point in the test method and then, on the shortcut menu, chooseGenerate Code for Coded UI Test. New code will be inserted at that point.
  7. Edit the detail of the test actions and the assertions.
    Open UIMap.uitest. This file opens in the Coded UI Test Editor, where you can edit any sequence of actions that you recorded as well as edit your assertions.
    Coded UI Test Editor

  8. Run the test.
    Use Test Explorer, or open the shortcut menu in the test method, and then choose Run Tests.
To see next post on Coded UI click this link

Popular posts from this blog

Creating package in Oracle Database using Toad For Oracle

What are Packages in Oracle Database A package is  a group   of procedures, functions,  variables   and  SQL statements   created as a single unit. It is used to store together related objects. A package has two parts, Package  Specification  and Package Body.

Resolving 'Setup Account Privileges' error while installing SQL Server

A new installation of Microsoft SQL Server 2012 or Microsoft SQL Server 2008 R2 fails You see the following error message when you try to install a new instance of SQL Server 2012 or SQL Server 2008 R2: Rule "Setup account privileges" failed.

Creating Oracle stored Procedures using TOAD for Oracle

In a database management system, a  stored procedure  is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database in compiled form so that it can be shared by a number of programs. The use of  stored procedures  can be helpful in controlling  access to data, preserving  data integrity  and  improving  productivity.