我用这个把头发扯掉了。我在 Visual Studio 2012 中针对 IE 11 构建了一个简单的编码 UI 测试。我要做的就是登录,检查 UI 是否显示用户已登录,然后注销。编码的 UI 测试一直有效,直到注销。当我尝试注销时,我得到:
TechnologyName:'Web' ControlType:'Custom' TagName:'form' Id:'logoutForm'
未能找到任何与搜索条件匹配的控件 Id='logoutForm' && ControlType='Custom' ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM 组件。
过滤器/搜索条件显示正确。我不确定为什么它不起作用。注销按钮的html如下
<form action="/Account/LogOff" class="navbar-form " id="logoutForm" method="post"> <input name="__RequestVerificationToken" type="hidden" value=""><a class="btn btn-primary btn-sm" href="javascript:document.getElementById('logoutForm').submit()"><i class="icon-remove"></i> Log off</a>
</form>
我只是不确定问题是什么以及为什么会失败。我尝试删除空白字段或添加显式 ID,但均无济于事。我也尝试过使用搜索配置,但似乎没有帮助。在 VS 中,我右键单击超链接并单击定位控件,它会正确突出显示控件。我不知所措。我很感激任何指导。
更新:这是按钮的生成代码
[GeneratedCode("Coded UITest Builder", "11.0.60315.1")]
public class UILogoutFormCustom : HtmlCustom
{
public UILogoutFormCustom(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties["TagName"] = "form";
this.SearchProperties["Id"] = "logoutForm";
this.FilterProperties["Class"] = "navbar-form ";
this.SearchConfigurations.Add(SearchConfiguration.DisambiguateChild);
this.WindowTitles.Add("someTitle");
#endregion
}
#region Properties
public HtmlHyperlink UILogoffHyperlink
{
get
{
if ((this.mUILogoffHyperlink == null))
{
this.mUILogoffHyperlink = new HtmlHyperlink(this);
#region Search Criteria
this.mUILogoffHyperlink.SearchProperties[HtmlHyperlink.PropertyNames.Id] = "logOffButton";
this.mUILogoffHyperlink.SearchProperties.Add(new PropertyExpression(HtmlHyperlink.PropertyNames.InnerText, "Log off", PropertyExpressionOperator.Contains));
this.mUILogoffHyperlink.FilterProperties[HtmlHyperlink.PropertyNames.AbsolutePath] = "document.getElementById(\'logoutForm\').submit()";
this.mUILogoffHyperlink.FilterProperties[HtmlHyperlink.PropertyNames.Title] = null;
this.mUILogoffHyperlink.FilterProperties[HtmlHyperlink.PropertyNames.Href] = "javascript:document.getElementById(\'logoutForm\').submit()";
this.mUILogoffHyperlink.FilterProperties[HtmlHyperlink.PropertyNames.Class] = "btn btn-primary btn-sm";
this.mUILogoffHyperlink.FilterProperties[HtmlHyperlink.PropertyNames.ControlDefinition] = "class=\"btn btn-primary btn-sm\" href=\"jav";
this.mUILogoffHyperlink.FilterProperties[HtmlHyperlink.PropertyNames.TagInstance] = "1";
this.mUILogoffHyperlink.WindowTitles.Add("some title");
#endregion
}
return this.mUILogoffHyperlink;
}
}
请注意,搜索配置是我正在尝试的,但通常没有设置。
#region Variable Declarations
HtmlHyperlink uILogoffHyperlink = this.UIPrefereWindow.UIPrefereDocument.UILogoutFormCustom.UILogoffHyperlink;
#endregion
// Click 'Log off' link
Mouse.Click(uILogoffHyperlink, new Point(26, 23));