问题描述
嗨.
我们希望使用编码的UI测试进行自动化测试,并且控件识别及其属性存在一些问题.
我们使用ComponentOne控件,例如,工具栏按钮由文本"属性识别.
由于这不是唯一的标识符,因此如果另一个控件具有相同的文本,则自动测试可能会失败.
更改控件的文本不是解决方案,我们的应用程序很大.
我的问题是,我们如何才能制作一个适配器或其他东西以正确获得控件名称,或另一个唯一的属性?
谢谢.
Hi.
We want to make automated tests using Coded UI Tests and we have some problems with control recognising and their properties.
We use ComponentOne controls, and for example, the toolbar buttons are recognised by "Text" property.
Since this is not a unique identificator, the automated tests could fail if another control has the same text.
Changing the text of the control is not a solution, our application is quite big.
My question is, how can we make a adapter or something to get the control name properly, or another unique property?
Thank you.
推荐答案
foreach (Control control in this.Controls)
{
MessageBox.Show(control.Name);
}
您可以使用标签
我更喜欢用这个:
You can use Tag
I prefer to use this:
public class ExTag
{
public ExTag()
{
}
public ExTag(object tag, Type type, string uniqueName)
{
this.MyType = type;
this.Tag = tag;
this.UniqueName = uniqueName;
}
public Type MyType { get; set; }
public string UniqueName { get; set; }
public object Tag { get; set; }
}
现在:
Now:
ExTag tag = MyTextBox.Tag = new ExTag(null, typeof(TextBox), "textbox121");
这是因为有时您需要Tag
进行其他操作.这将使您拥有一个额外的Tag
.
您也可以将GUID用于UniqueName
.
更改控件文本不是解决方案,我们的应用程序很大
我想您认为为所有控件设置Tag
也不是解决方案,但是您有更好的主意吗?编写程序以设置应用程序的所有控件Tag
.
It''s because sometimes you need Tag
for other things. It will enables you to have an extra Tag
.
You can use GUID for UniqueName
too.
Changing the text of the control is not a solution, our application is quite big
I guess you think setting Tag
s for all controls is not a solution too but do you have any better idea? Write a program to set all control Tag
s of the application.
这篇关于使用编码的UI测试进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!