C# CodedUI搜索孙子控制?
我有一张有多行的桌子。我想验证表中是否有特定的字符串C# CodedUI搜索孙子控制?,c#,coded-ui-tests,C#,Coded Ui Tests,我有一张有多行的桌子。我想验证表中是否有特定的字符串StringName。我使用CodedUI查找控件,UI映射如下: public class UIItemTable : WpfTable { #region Fields private UIItemRow mUIItemRow; #endregion } public class UIItemRow : WpfRow { #region Fields private UIBlahBlahBlahCe
StringName
。我使用CodedUI查找控件,UI映射如下:
public class UIItemTable : WpfTable
{
#region Fields
private UIItemRow mUIItemRow;
#endregion
}
public class UIItemRow : WpfRow
{
#region Fields
private UIBlahBlahBlahCell mUIBlahBlahBlahCell;
#endregion
}
public class UIBlahBlahBlahCell : WpfCell
{
#region Fields
private WpfText mUIBlahBlahBlahText;
#endregion
}
我想找到一个与我的StringName
匹配的WpfText
。因此,我在UIItemTable
中添加了一个函数:
public class UIItemTable : WpfTable
{
public WpfText Find(string StringName)
{
WpfText StringNameWpfText = new WpfText(this);
StringNameWpfText.SearchProperties[WpfText.PropertyNames.Name] = StringName;
return StringNameWpfText;
}
#region Fields
private UIItemRow mUIItemRow;
#endregion
}
但是CodedUI找不到WpfText
控件。我收到的错误是:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException。
播放找不到具有给定搜索的控件
财产。其他详细信息:技术名称:“UIA”控制类型:
“文本”名称:
我认为这个错误可能是因为我要搜索的WpfCell实际上是表的孙子。但我认为CodedUI处理树遍历对吗?我如何寻找孙子
public UIControl FindText(UIControl ui)
{
UIControl returnControl = null;
IEnumerator<UITestControl> UIItemTableChildEnumerator =
ui.GetChildren().GetEnumerator();
while(uiChildEnumerator.MoveNext())
{
if(uiChildEnumerator.Current.DisplayText.equals(StringName))
{
returnControl = uiChildEnumerator.Current
break;
}
else
{
returnControl = this.FindText(uiChildEnumerator.Current)
if(returnControl != null)
{
break;
}
}
}
return returnControl;
}
公共UIControl查找文本(UIControl ui)
{
UIControl返回控件=空;
IEnumerator UIItemTableChildEnumerator=
ui.GetChildren().GetEnumerator();
while(uiChildEnumerator.MoveNext())
{
if(uiChildEnumerator.Current.DisplayText.equals(StringName))
{
returnControl=uiChildEnumerator.Current
打破
}
其他的
{
returnControl=this.FindText(uiChildEnumerator.Current)
if(returnControl!=null)
{
打破
}
}
}
返回控制;
}
WpfText StringNameWpfText = new WpfText(this);
IEnumerator<UITestControl> textItems = StringNameWpfText .FindMatchingControls().GetEnumerator();
while (textItems.MoveNext())
{
//search
}
WpfText StringNameWpfText=新的WpfText(此);
IEnumerator textItems=StringNameWpfText.FindMatchingControls().GetEnumerator();
while(textItems.MoveNext())
{
//搜寻
}
希望这有帮助,我通常先找到细胞。我相信表格中的任何内容都会在单元格中。所以我们可以先搜索细胞,然后潜入其中 查找其值与给定字符串匹配的单元格的一种方法
WpfCell cell = myWpfTable.FindFirstCellWithValue(string StringName);
if(cell != null)
return cell.Value // returns WpfControl;
else
return null;
获取包含特定字符串的单元格值的另一种方法
WpfCell myCell = myWpfTable.Cells
.FirstOrDefault(c => c.Value.Contains("StringName"));
var myTextControl = myCell != null ? myCell.Value : null;
如果文本嵌套在单元格的深处,则可以执行此操作。就像你在桌子上做的一样
// Find cell which contains the particular string, let say it "myCell"
WpfText mytext = new WpfText(myCell);
mytext.SearchProperties.Add(WpfText.PropertyNames.Name, "StringName", PropertyExpressionOperator.Contains);
if(mytext.Exist)
return myText;
else
retrun null;
第(1)项不清楚。uimap.cs
和uimap.designer.cs
文件的顶部附近都有partial class
。这一点最好是这样说:将代码移出uimap.designer.cs
文件,因为它将在下次录制控件/assert/etc时被覆盖。将代码移到uimap.cs
文件中,因为这两个文件都属于同一类。其他几点看起来不错。