Coded UI Test Utilities Helper Methods

Some of the Microsoft team members have created a set of helper extension methods based on feedback given. The can be found here

Here are the details of the help. For usage check the help contained in the download.

Extension Method

Description

UITestControl

  

ControlStates GetState()

Gets the state of the control.

object GetValue()

Gets the value of the control.

bool TryFind()

Tries to find the control on the user interface. In case of failure, unlike the Find() method, this does not throw UITestControlNotFoundException but returns false.

UITestControlCollection

  

string[] GetNamesOfControls()

Gets the names of all the controls in the collection.

string[] GetValuesOfControls()

Gets the values of all the controls in the collection.

T[] GetPropertyValuesOfControls<T>(string propertyName)

Gets the values of the specified property of all the controls in the collection.

bool IsSortedOnProperty(string propertyName, SortOrder direction)

Checks if the controls in the collection are sorted based on the value of the specified property.

WinControl

  

string GetAccessibleDescription()

Gets the description of the underlying IAccessible of this WinControl.

string GetToolTipText()

Hovers on the control to show the tool tip and then gets the tool tip text.

WpfControl

  

AutomationElement GetAutomationElement()

Gets the underlying AutomationElement from the WpfControl.

string GetItemStatus()

Gets the item status of the WpfControl from the underlying AutomationElement.

string GetToolTipText()

Hovers on the control to show the tool tip and then gets the tool tip text.

HtmlControl

  

IHTMLCurrentStyle GetCurrentStyle()

Gets the current CSS style of the underlying HTML element

HtmlTable, WinTable, WpfTable

  

HtmlCell GetCell(int rowIndex, int columnIndex)

Gets the cell based on the row and column indices.

HtmlRow GetRow(int rowIndex)

Gets the row based on the row index.

HtmlCell FindFirstCellWithValue(string value)

Finds the first cell with the given value.

string[] GetColumnNames()

Gets the names of all the columns of the table.

string[] GetContent()

Gets the content of the table i.e. values of all the cells.

HtmlRow, WinRow, WpfRow

  

string[] GetContent()

Gets the content of the row i.e. values of all the cells.

HtmlComboBox, WinComboBox, WpfComboBox, HtmlList, WinList, WpfList

  

bool ItemExists(string itemText)

Checks if a list item with given text exists in this List or not.

string[] GetContent()

Gets the content of the control.

WinList (when acting as list view)

  

string[] GetColumnNames()

Gets the names of all the columns of the list view.

HtmlListItem, WinListItem, WpfListItem

  

void Select()

Selects the list item in the list.

WinListItem (when acting as list view item)

  

string[] GetColumnValues()

Gets the values of all the columns of the list view item.

WinTreeItem, WinCheckBoxTreeItem, WpfTreeItem, WpfTree

  

bool NodeExists(string nodeText)

Checks if a tree node with given text exists in this tree hierarchy.

WinMenuItem, WpfMenuItem, WpfMenu

  

bool ItemExists(string itemText)

Checks if a menu item with given text exists in this menu hierarchy.

Broken Link Related Extensions

  

bool HtmlControl.IsBrokenLink()
bool IsBrokenLink(string linkUri)
bool IsBrokenLink(Uri linkUri)
UITestControlCollection HtmlDocument.FindAllBrokenLinks()
UITestControlCollection FindAllBrokenLinks(UITestControlCollection)
For all, there is an overload that takes request timeout too.

Various methods to find out the broken links in the page.

UITestControlFactoryUtility

  

T FromName<T>(UITestControl container, string name)

Creates a control using name as the search properties.

T FromNamedHierarchy<T>(UITestControl ancestor, params string[] namesInHierarchy)

Creates a control using array of names specifying current and ancestor controls.

T FromId<T>(UITestControl container, string id)

Creates a HTML control using id as the search properties.

T FromControlName<T>(UITestControl container, string controlName)

Creates a Win32 or Windows Forms control using control name as the search properties.

T FromControlId<T>(UITestControl container, int controlId)

Creates a Win32 or Windows Forms control using control id as the search properties.

T FromAutomationId<T>(UITestControl container, string automationId)

Creates a WPF control using automation id as the search properties.

Advertisements
  1. #1 by Angel on November 14, 2011 - 6:53 pm

    Can you give me an example how I can use the HtmlDocument.FindAllBrokenLinks() method. I can’t seem to load this up correctly

    • #2 by RBurnham on November 15, 2011 - 4:29 am

      I haven’t actually tried it before but just playing around with it a bit you need a HtmlDocument object. This i think would normally represent the page. If you have a reference to the UITestingUtilities.dll you should be able to just call the FindAllBrokenLinks() Method on the HtmlDocument control.

      Here is a sample on how to create a new object but normally you would get the HtmlDocument object from your UIMap
      var doc = new Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument();
      doc.FindAllBrokenLinks();

      Note the reference, there is also a System.Windows.Forms.HtmlDocument class so if you have a using statement to System.Windows.Forms which i did by default then this might cause conflicts

      I did find this though which is probably the problem your having. The Coded UI Test Recorded is probably getting the wrong control.
      http://mswebtest.blogspot.com/2010/12/coded-ui-tests-ie8-validation-url-trick.html

      So in your Coded UI Test method i would expect it to be something like
      var brokenLinks = UIMap.PageControl.FindAllBrokenLinks()
      foreach(var link in brokenLinks)
      Assert.IsFalse(link.IsBrokenLink());

      Hope this helps

  2. #3 by Angel on June 26, 2012 - 6:41 pm

    Hi do you have a way to get the tooltip for the html control instead of the wpf and wincontrol.

  3. #5 by joinsaad on December 5, 2012 - 9:51 am

    thanks for this. It really helped me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: