Dynamically Created Controls Identification in VS 2010
While creating UI Coded test Visual Studio 2010 Beta 2, I have experienced an interesting situation on identifying dynamically created controls.
An application contains a form with three WPF combo boxes created dynamically with a blank Name property. In this case, UI Spy (and I assume Visual Studio 2010 Coded UI Test Recorder) should identify control with empty Name and AutomationID property, but recorder should generate NextTo or Instance properties.
|
Identification |
|
|
ClassName: |
ComboBox |
|
ControlType: |
ControlType.ComboBox |
|
Culture: |
(null) |
|
AutomationId: |
|
|
LocalizedControlType: |
combo box |
|
Name: |
Unfortunately, recorder didn’t record the instance property, so the result was only one combo box control in the UIMap.Designer.cs file.
public WpfComboBox ItemComboBox
{
get
{
if ((this.mItemComboBox == null))
{
this.mItemComboBox = new WpfComboBox(this);
#region Search Criteria
this.mItemComboBox.SearchConfigurations.Add(SearchConfiguration.NextSibling);
#endregion
}
return this.mItemComboBox;
}
}
The resolution is to create two new instances of the controls with different search criteria:
public WpfComboBox ItemComboBox2
{
get
{
if ((this.mItemComboBox2 == null))
{
this.mItemComboBox2 = new WpfComboBox(this);
#region Search Criteria
this.mItemComboBox2.SearchProperties["Instance"] = “2″;
this.mItemComboBox2.SearchConfigurations.Add(SearchConfiguration.NextSibling);
#endregion
}
return this.mItemComboBox2;
}
}
However, a suggestion is to assign a name to these controls because in that case, they have a much better search condition and will be resilient to position changes.
Tags: visual studio 2010