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

Asp.Net Web API

What is ASP.NET Web API? ASP.NET Web API is a framework provided by the Microsoft with which we can easily build HTTP services that can reach a broad of clients, including browsers, mobile, IoT devices, etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET Framework.   Difference between ASP.NET Web API and WCF Web AP I is a Framework to build HTTP Services that can reach a board of clients, including browsers, mobile, IoT Devices, etc. and provided an ideal platform for building RESTful applications. It is limited to HTTP based services. ASP.NET framework ships out with the .NET framework and is Open Source. WCF i.e. Windows Communication Foundation is a framework used for building Service Oriented applications (SOA) and supports multiple transport protocol like HTTP, TCP, MSMQ, etc. It supports multiple protocols like HTTP, TCP, Named Pipes, MSMQ, etc. WCF ships out with the .NET Framework. Both Web API and WCF can be self-hosted or can be...

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.