我正在用這個彈出我的頭髮。我在Visual Studio 2012中針對IE 11構建了一個簡單的編碼UI測試。我試圖執行的所有操作都是登錄,檢查UI是否顯示用戶已登錄,然後註銷。編碼的UI測試工作直到註銷。當我嘗試登錄時,我得到:Visual Studio編碼的UI測試播放無法找到控件
TechnologyName:「網頁」 ControlType:「自定義」標籤名:「形式」編號: 「logoutForm」
無法找到符合搜索任何控制條件 Id ='logoutForm'& & ControlType ='Custom'---> System.Runtime.InteropServices.COMException:錯誤HRESULT E_FAIL有 已從調用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中,我右鍵單擊超鏈接並單擊定位控件,並正確突出顯示控件。我很茫然。我很欣賞任何指導。
UPDATE: 下面是按鈕
[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));
嘗試最新的Update 4 RC:http://blogs.msdn.com/b/visualstudioalm/archive/2013/09/17/coded-ui-mtm-issues-on-internet-explorer-with-kb2870699。 aspx – magicandre1981
感謝您的建議。試過了。同樣的東西 –
您可以發佈試圖訪問該控件的代碼嗎?另外,您是否可以確認控件在運行的開始和結束時確實是相同的控件。有時看起來相同,但一些細節變化可能會打破測試。使用測試生成器中的十字線來與捕獲的控件進行比較。 – yonitdm