本文介绍了VS 2010 - 生成UI测试代码(CodedUI)的简单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! · ;   我在计算器上记录了一些操作:5 * 2 = public void RecordedMethod1() { #region 变量声明 WinButton uIItem5Button = 这个 。UICalculatorWindow.UIItem5Window.UIItem5Button; WinButton uIItemButton = 这个 。UICalculatorWindow.UIItemWindow.UIItemButton; WinButton uIItem2Button = 这个 。UICalculatorWindow.UIItem2Window.UIItem2Button; WinButton uIItemButton1 = 这个 。UICalculatorWindow.UIItemWindow1.UIItemButton; #endregion //点击'5'按钮 鼠标 。点击(uIItem5Button, new Point (19,14)); //点击'*'按钮 鼠标 。点击(uIItemButton, new Point (23,12)); //点击'2'按钮 鼠标 。点击(uIItem2Button, new Point (23,12)); //点击'='按钮 鼠标 。点击(uIItemButton1, new Point (22,15)); } 第一个问题是为什么会创建一个中间UI控件,例如: WinButton uIItem5Button = 这个 。UICalculatorWindow.UIItem5Window.UIItem5Button; 为什么需要UIItem5Window - "5"按钮直接在主计算器窗口下面,我们可以只有: WinButton uIItem5Button = 这个 。UICalculatorWindow.UIItem5Button; 2添加顶级窗口标题有什么用,如: if (( this 。mUIItem5Button == null )) { 这个 。mUIItem5Button = new WinButton ( this ); #region 搜索标准 这个 。mUIItem5Button.SearchProperties [ WinButton 。 PropertyNames 。名称] = " 5" ; 这个 。mUIItem5Button.WindowTitles.Add( " Calculator" ); #endregion } 谢谢推荐答案 您好答案1 )我们生成一个高于5的中间窗口,因为按钮5顶部有一个窗口。当窗口之间没有窗口控件时,这个窗口有助于快速搜索按钮。还有更多的启发式和算法围绕代这样的元素Answer 1) We generate an intermmediate Window above 5 because button 5 has a window on top of it. This window helps make search for button fast in comparison when there was no Window control in between. There are many more heuristic and algorithm around generation of such elements答案2)控件中存在的窗口标题在与之交互时捕获顶层窗口的窗口标题(在录制期间)或使用Coded UITest Builder添加到UIMap时)The windowtitles present in the controls capture the windowtitle of the toplevel window when interacted with (during recording or when added to the UIMap using Coded UITest Builder)如果控制层次结构如下所示&   ; StartPageWindow(WindowTitles– {“ Start Page– Microsoft Visual Studio”,“ TestProject1– Microsoft Visual Studio”}                      StartPagePane(WindowTitles– {“ Start Page– Microsoft Visual Studio”})If the control hierarchy is as below StartPageWindow (WindowTitles – {“Start Page – Microsoft Visual Studio”, “TestProject1 – Microsoft Visual Studio”} StartPagePane (WindowTitles – {“Start Page – Microsoft Visual Studio”})它表示当StartPagePane与之交互时顶层窗口的标题是"ldquo;起始页– Microsoft Visual Studio”当搜索一个名为StartPagePane的控件时,总是检查父控件是否已经搜索了并绑定到有效控件。如果是这样,搜索将在其下方进行,否则将首先在其父级下搜索父级(这将继续递归直到顶级控件)。It indicates that the title of the toplevel window when StartPagePane was interacted with was “Start Page – Microsoft Visual Studio”. When searching for a control say StartPagePane, the parent is always checked to see if it has been already searched and is bound to a valid control. If so, the search would be done beneath it else the parent would be first searched beneath its parent (this continues recursively till the toplevel control).在搜索控件期间(StartPagePane)如果尚未找到/搜索顶层窗口(StartPageWindow),则控件(StartPagePane)中出现的窗口标题将用于搜索顶层窗口。在上面的例子中{“开始 Page–将使用Microsoft Visual Studio”而不是toplevelcontrol的窗口标题。During a search for a control(StartPagePane) if the toplevel window(StartPageWindow) hasn’t been yet found/searched then the windowtitles present at the control(StartPagePane) will be used to search for the toplevel window. In the above example {“Start Page – Microsoft Visual Studio”} would be used and not the windowtitles at the toplevelcontrol. WindowTitles也用于合并UIMap中的控件,这样我们就不会得到重复的控件了相同的顶层窗口。WindowTitles are also used in merging of controls in the UIMap so that we don’t end up with duplicate controls for the same toplevel window.谢谢 SiddharthaSiddhartha 这篇关于VS 2010 - 生成UI测试代码(CodedUI)的简单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-31 11:50