Skip to main content

Generate the Code for recorded control in Coded UI

When you choose Generate Code, several pieces of code are created:


  • A line in the test method.
        [CodedUITest]
        public class CodedUITest1
        { ...
          [TestMethod]
          public void CodedUITestMethod1()
          {
              this.UIMap.AddTwoNumbers();
              // To generate more code for this test, select 
              // "Generate Code" from the shortcut menu.      }
        }
    
    You can right-click in this method to add more recorded actions and verifications. You can also edit it manually to extend or modify the code. For example, you could enclose some of the code in a loop.
    You can also add new test methods and add code to them in the same way. Each test method must have the [TestMethod] attribute.
  • A method in UIMap.uitest
    This method includes the detail of the actions you recorded or the value that you verified. You can edit this code by opening UIMap.uitest. It opens in a specialized editor in which you can delete or refactor the recorded actions.
    You can also view the generated method in UIMap.Designer.cs. This method performs the actions that you recorded when you run the test.
    // File: UIMap.Designer.cs
    public partial class UIMap
    {
      /// <summary>
      /// Add two numbers
      /// </summary>
      public void AddTwoNumbers()
      { ...   }
    }
    
    Caution noteCaution
    You should not edit this file, because it will be regenerated when you create more tests.
    You can make adapted versions of these methods by copying them to UIMap.cs. For example, you could make a parameterized version that you could call from a test method:
    // File: UIMap.cs
    public partial class UIMap // Same partial class
    {
      /// <summary>
      /// Add two numbers – parameterized version
      /// </summary>
      public void AddTwoNumbers(int firstNumber, int secondNumber)
      { ...   // Code modified to use parameters.
      }
    }
    
  • Declarations in UIMap.uitest
    These declarations represent the UI controls of the application that are used by your test. They are used by the generated code to operate the controls and access their properties.
    You can also use them if you write your own code. For example, you can have your test method choose a hyperlink in a Web application, type a value in a text box, or branch off and take different testing actions based on a value in a field.
    You can add multiple coded UI tests and multiple UI map objects and files to facilitate testing a large application. 
To see next Coded UI post please click the 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.