C# 如何修复UI控件映射控件丢失映射的问题?
通过创建所有映射并手动编写测试,我正在我的计算机(Windows 8.1)上创建一个编码的UI测试。(我不使用操作录制)当它们在夜间机器(服务器2012R2)上运行时,选择我的组查找窗口的操作实际上会在测试运行期间选择我的客户代码查找窗口 在我的机器上重新映射控件并不能解决此问题,并且无法在Server2012R2机器上重新映射控件,因为这只是为了运行测试,而不是为了运行Visual Studio 控件上的可用搜索属性不足以区分控件。相反,我尝试修改控件上的Friendly Name属性,并使用以下代码:C# 如何修复UI控件映射控件丢失映射的问题?,c#,visual-studio-2015,coded-ui-tests,C#,Visual Studio 2015,Coded Ui Tests,通过创建所有映射并手动编写测试,我正在我的计算机(Windows 8.1)上创建一个编码的UI测试。(我不使用操作录制)当它们在夜间机器(服务器2012R2)上运行时,选择我的组查找窗口的操作实际上会在测试运行期间选择我的客户代码查找窗口 在我的机器上重新映射控件并不能解决此问题,并且无法在Server2012R2机器上重新映射控件,因为这只是为了运行测试,而不是为了运行Visual Studio 控件上的可用搜索属性不足以区分控件。相反,我尝试修改控件上的Friendly Name属性,并使用
public void ClickControl(WinControl mycontrol, string resultId)
{
UITestControlCollection controls = mycontrol.FindMatchingControls();
foreach (UITestControl allControls in controls)
{
if (allControls.FriendlyName == resultId)
{
Mouse.Click(allControls);
}
}
}
但是当我运行代码时,它似乎没有在程序运行时使用友好名称的修改值
是否有方法确保在发送鼠标之前选择了正确的控件。单击事件 我通过创建以下方法找到了解决方法。它没有我想要的那么干净,我必须使用UIMap工具来查找ControlName,但是当我调用它时,代码正在使我的测试通过
public static UITestControl FindControl(WinControl myControl, string controlName)
{
try
{
UITestControlCollection controls = myControl.FindMatchingControls();
foreach (UITestControl currentControl in controls)
{
if (currentControl.ControlType == ControlType.Button)
{
WinButton mycont = (WinButton)currentControl;
if (mycont.ControlName == controlName)
{
return mycont;
}
}
if (currentControl.ControlType == ControlType.Edit)
{
WinEdit mycont = (WinEdit)currentControl;
if (mycont.ControlName == controlName)
{
return mycont;
}
}
}
return myControl;
}
catch
{
return myControl;
}
}
您确定
客户代码查找窗口
的FriendlyName
正确吗?客户代码查找的友好名称是“…”,组码查找的友好名称也是。我把它们分别改为“CustCodeLookup”和“groupcodelokup”。当我在组码查找上运行上述函数时,当我调用allControls.FriendlyName时,它仍然传入“…”。请尝试类似于someDebugOutputStream.Writeline(“FriendlyName'{0}',allControls.FriendlyName)的内容代码>就在if…
之前。注意输出中的”
字符,因此显示前导空格/训练空格等。我已经知道我正在访问的控件的friendlyname是什么,但friendlyname目前没有帮助,因为它与其他12个控件相同。使用FriendlyName只有在我能够成功更改它时才有用,而我似乎无法管理它。