Skip to main content

Coded UI control actions and properties

When you work with UI test controls in coded UI tests they are separated into two parts: actions and properties.
  • The first part consists of actions that you can perform on UI test controls. For example, coded UI tests can simulate mouse clicks on a UI test control, or simulate keys typed on the keyboard to affect a UI test control.
  • The second part consists of enabling you to get and set properties on a UI test control. For example, coded UI tests can get the count of items in a ListBox, or set a CheckBox to the selected state.
Accessing Actions of UI Test Control
To perform actions on UI test controls, such as mouse clicks or keyboard actions, use the methods in theMouse and Keyboard classes:
  • To perform a mouse-oriented action, such as a mouse click, on a UI test control, use Click.
    Mouse.Click(buttonCancel);
  • To perform a keyboard-oriented action, such as typing into an edit control, use SendKeys.
    Keyboard.SendKeys(textBoxDestination, @"C:\Temp\Output.txt");
Accessing Properties of UI Test Control
To get and set UI control specific property values, you can directly get or set the values the properties of a control, or you can use the UITestControl.GetProperty and UITestControl.SetProperty methods with the name of the specific property that you want you get or set.
GetProperty returns an object, which can then be cast to the appropriate Type. SetProperty accepts an object for the value of the property.

To get or set properties from UI test controls directly

  • With controls that derive from T:Microsoft.VisualStudio.TestTools.UITesting.UITestControl, such as T:Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlList or T:Microsoft.VisualStudio.TestTools.UITesting.WinControls.WinComboBox, you can get or set their property values directly, as follows:
    int i = myHtmlList.ItemCount;
    myWinCheckBox.Checked = true;
    

To get properties from UI test controls

  • To get a property value from a control, use GetProperty.
  • To specify the property of the control to get, use the appropriate string from the PropertyNames class in each control as the parameter to GetProperty.
  • GetProperty returns the appropriate data type, but this return value is cast as an Object. The returnObject must then be cast as the appropriate type.
    Example:
    int i = (int)GetProperty(myHtmlList.PropertyNames.ItemCount);

To set properties for UI test controls

  • To set a property in a control, use SetProperty.
  • To specify the property of the control to set, use the appropriate string from the PropertyNames class as the first parameter to SetProperty, with the property value as the second parameter.
    Example:
    SetProperty(myWinCheckBox.PropertyNames.Checked, true);

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.