某些Win控件存在此问题。我想访问一个Date DropDowns,但是开始日期和结束日期都是相同的(今天的日期),因此对于开始日期和结束日期组合框,每次都重播到第一个-开始日期-。
我的问题与此旧帖子有关,我看到此帖子中的问题仍未解决/已回答 CodedUI : PropertyNames.ControlName doesn't work
当我监视组合框时,我看到ControlName是唯一的,因此我尝试通过UIMap.uitest为控件使用控件名称。我将ControlName添加到SearchProperties集合并写入值,但是现在找不到了。
public WinControl UIItem17Ocak2019PerşemDropDown
{
get
{
if ((this.mUIItem17Ocak2019PerşemDropDown == null))
{
this.mUIItem17Ocak2019PerşemDropDown = new WinControl(this);
#region Search Criteria
this.mUIItem17Ocak2019PerşemDropDown.SearchProperties[UITestControl.PropertyNames.ControlType] = "DropDown";
this.mUIItem17Ocak2019PerşemDropDown.SearchProperties[UITestControl.PropertyNames.Name] = "17 Ocak 2019 Perşembe";
this.mUIItem17Ocak2019PerşemDropDown.SearchProperties["ControlName"] = "bBasT";
this.mUIItem17Ocak2019PerşemDropDown.WindowTitles.Add("Filtre");
#endregion
}
return this.mUIItem17Ocak2019PerşemDropDown;
}
}
这是我得到的例外情况
Message: Test method
CodedUITestProject2.KayitTablolari_HurdaListesi.HurdaListesiTabloKontrol threw exception: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details: TechnologyName: 'MSAA'ControlType: 'DropDown' Name: '17 Ocak 2019 Perşembe' ControlName: 'bBasT' ---System.Runtime.InteropServices.COMException: Bir COM bileşenine yapılan çağrıdan HRESULT E_FAIL hatası döndürüldü.
或者在窗口中是否有一种控制顺序的方法?例如“不要先单击,而是在窗口中单击第二个组合框。”
答案 0 :(得分:1)
我找到了一个解决方案,如下页所述,controlName不是用于单个控件,而是用于诸如WinWindow之类的窗口控件。
答案 1 :(得分:1)
下面是Rasim Avci的答案,下面的代码说明了从UIMap生成的代码。被测试的程序是一个Windows Forms项目,其中包含一个带有ComboBox的Form。
[GeneratedCode("Coded UITest Builder", "15.0.26208.0")]
public class UIForm1Window : WinWindow
{
public UIForm1Window()
{
#region Search Criteria
this.SearchProperties[WinWindow.PropertyNames.Name] = "Form1";
this.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains));
this.WindowTitles.Add("Form1");
#endregion
}
#region Properties
public UICbStartDateWindow UICbStartDateWindow
{
get
{
if ((this.mUICbStartDateWindow == null))
{
this.mUICbStartDateWindow = new UICbStartDateWindow(this);
}
return this.mUICbStartDateWindow;
}
}
public UICbEndDateWindow UICbEndDateWindow
{
get
{
if ((this.mUICbEndDateWindow == null))
{
this.mUICbEndDateWindow = new UICbEndDateWindow(this);
}
return this.mUICbEndDateWindow;
}
}
#endregion
#region Fields
private UICbStartDateWindow mUICbStartDateWindow;
private UICbEndDateWindow mUICbEndDateWindow;
#endregion
}
[GeneratedCode("Coded UITest Builder", "15.0.26208.0")]
public class UICbStartDateWindow : WinWindow
{
public UICbStartDateWindow(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WinWindow.PropertyNames.ControlName] = "cbStartDate";
this.WindowTitles.Add("Form1");
#endregion
}
#region Properties
public WinComboBox UICbStartDateComboBox
{
get
{
if ((this.mUICbStartDateComboBox == null))
{
this.mUICbStartDateComboBox = new WinComboBox(this);
#region Search Criteria
this.mUICbStartDateComboBox.SearchProperties[WinComboBox.PropertyNames.Name] = "cbStartDate";
this.mUICbStartDateComboBox.WindowTitles.Add("Form1");
#endregion
}
return this.mUICbStartDateComboBox;
}
}
#endregion
#region Fields
private WinComboBox mUICbStartDateComboBox;
#endregion
}
在下面的图像中,显示了控件层次结构。它清楚地显示了UICbStartDateWindow
作为ComboBox的父级。
如您所见,生成的代码应该遵循Rasim Avci的答案的链接中描述的内容。