编码 UI 发现控件
我在 Visual Studio 2010 中有一个 ui 编码的 ui 测试。 我想编写一个代码,它将:
- 发现窗口和子窗口上的所有控件(按钮、网格、标签)
- 编写一个 uimap,其 id 是代码中控件的名称。
为了启动它,我编写了以下内容:
public void CodedUITestMethod1()
{
string uiTestFileName = @"D:\dev11\ConsoleApplication1\TestProject1\UIMap.uitest";
UITest uiTest = UITest.Create(uiTestFileName);
Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap newMap = new Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap();
newMap.Id = "UIMap";
uiTest.Maps.Add(newMap);
GetAllChildren(BrowserWindow.Launch(new Uri("http://bing.com")), uiTest.Maps[0];);
uiTest.Save(uiTestFileName);
}
private void GetAllChildren(UITestControl uiTestControl, Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap map)
{
foreach (UITestControl child in uiTestControl.GetChildren())
{
map.AddUIObject((IUITechnologyElement)child.GetProperty(UITestControl.PropertyNames.UITechnologyElement));
GetAllChildren(child, map);
}
}
但它插入到递归循环中并且不会结束它。
谁能帮助我吗?
I have a ui coded ui test in visual studio 2010.
I want to write a code which will:
- Discover all the controls on a window and child windows which are button, grid, label
- write a uimap with the id which is the name of the control in the code.
For starting it, I've write the following:
public void CodedUITestMethod1()
{
string uiTestFileName = @"D:\dev11\ConsoleApplication1\TestProject1\UIMap.uitest";
UITest uiTest = UITest.Create(uiTestFileName);
Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap newMap = new Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap();
newMap.Id = "UIMap";
uiTest.Maps.Add(newMap);
GetAllChildren(BrowserWindow.Launch(new Uri("http://bing.com")), uiTest.Maps[0];);
uiTest.Save(uiTestFileName);
}
private void GetAllChildren(UITestControl uiTestControl, Microsoft.VisualStudio.TestTools.UITest.Common.UIMap.UIMap map)
{
foreach (UITestControl child in uiTestControl.GetChildren())
{
map.AddUIObject((IUITechnologyElement)child.GetProperty(UITestControl.PropertyNames.UITechnologyElement));
GetAllChildren(child, map);
}
}
But it insert into the recursive loop and doesn't end it.
Can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为为了避免可能的无限递归,您必须添加以下代码:
这样您就可以避免多次考虑同一对象并远离可能的视觉树循环。
I think that to avoid possible infinite recursion you have to add this code:
This way you avoid to consider the same object multiple times and keep away from possible visual tree cycle.
在 foreach 循环中调用 map.AddUIObject 和 GetAllChildren 之前,请检查以确保地图集合中尚不存在该对象。
Before you call map.AddUIObject and GetAllChildren in the foreach loop, check to make sure the object doesn't already exist in the map collection.
在调用 GetAllChildren(child, map) 之前检查孩子是否有孩子
Check that the child has children before calling GetAllChildren(child, map)