2015-01-12 107 views
0

所以,我已經走了,使用的代碼生成器在Visual Studio中生成編碼的UI測試。我們有一個TreeList的wpf應用程序。我將它記錄到第一個框中,輸入一個值,然後單擊第二個框,然後鍵入一個新值。沒什麼超級花式。錄製CodedUI找不到記錄控制

public void RecordedMethod1() 
{ 
    #region Variable Declarations 
    WpfCell uIItemCell = this.UIWindowWindow.UIEntityTesterControlCustom.UIEntityTesterTreeListTree.UIEntityTesterTreeListTreeItem.UIItemCell; 
    WpfEdit uIInvoice1InvoiceIDEdiEdit = this.UIWindowWindow.UIEntityTesterControlCustom.UIEntityTesterTreeListTree.UIEntityTesterTreeListTreeItem.UIItemCell.UIInvoice1InvoiceIDEdiEdit; 
    WpfCell uIItemCell1 = this.UIWindowWindow.UIEntityTesterControlCustom.UIEntityTesterTreeListTree.UIEntityTesterTreeListTreeItem.UIItemCell1; 
    WpfEdit uI_localTextBoxEdit = this.UIWindowWindow.UIEntityTesterControlCustom.UIEntityTesterTreeListTree.UIEntityTesterTreeListTreeItem.UIItemCell11.UI_localTextBoxEdit; 
    #endregion 

    // Click cell 
    Mouse.Click(uIItemCell, new Point(92, 18)); 

    // Type '1' in 'Invoice:1/InvoiceID|Editor' text box 
    uIInvoice1InvoiceIDEdiEdit.Text = this.RecordedMethod1Params.UIInvoice1InvoiceIDEdiEditText; 

    // Click cell 
    Mouse.Click(uIItemCell1, new Point(136, 9)); 

    // Type '2/1/2012' in '_localTextBox' text box 
    uI_localTextBoxEdit.Text = this.RecordedMethod1Params.UI_localTextBoxEditText; 
} 

#region Properties 
public virtual RecordedMethod1Params RecordedMethod1Params 
{ 
    get 
    { 
     if ((this.mRecordedMethod1Params == null)) 
     { 
      this.mRecordedMethod1Params = new RecordedMethod1Params(); 
     } 
     return this.mRecordedMethod1Params; 
    } 
} 

它與第一Mouse.Click()這個錯誤崩潰叫

Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException was unhandled by user code 
HResult=-268111872 
Message=The playback failed to find the control with the given search properties. Additional Details: 
TechnologyName: 'UIA' 
FrameworkId: 'Wpf' 
ControlType: 'Custom' 
ClassName: 'Uia.EntityTesterControl' 
AutomationId: 'EntityTesterControl' 
Search may have failed at 'Test Suite Tools' Custom as it may have virtualized children. If the control being searched is descendant of 'Test Suite Tools' Custom then including it as the parent container may solve the problem. 
Source=Microsoft.VisualStudio.TestTools.UITesting 
BasicMessage=The playback failed to find the control with the given search properties. 
RootElement="" 
StackTrace: 
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapControlNotFoundException(COMException ex, IPlaybackContext context) 
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException(COMException innerException, IPlaybackContext context) 
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(Exception exception, IPlaybackContext context) 
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(Exception exception, String queryId) 
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft) 
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft) 
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft) 
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft) 
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetUITestControlRecursive(Boolean useCache, Boolean alwaysSearch, ISearchArgument searchArg, IList`1 windowTitles, Int32& timeLeft) 
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean useCache, ISearchArgument searchArg) 
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search(ISearchArgument searchArg) 
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal() 
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindPrivate() 
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<Find>b__37() 
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction) 
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.Find() 
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyPrivate(String propertyName) 
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<>c__DisplayClass3b.<GetProperty>b__3a() 
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction) 
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetProperty(String propertyName) 
at Microsoft.VisualStudio.TestTools.UITesting.ALUtility.GetTechElementFromUITestControl(UITestControl uiTestControl) 
at Microsoft.VisualStudio.TestTools.UITesting.ActionExecutorManager.GetActionExecutor(UITestControl uiControl) 
at Microsoft.VisualStudio.TestTools.UITesting.Mouse.ClickImplementation(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate) 
at Microsoft.VisualStudio.TestTools.UITesting.Mouse.<>c__DisplayClass6.<Click>b__5() 
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction) 
at Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate) 
at Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(UITestControl control, Point relativeCoordinate) 
at RoadExercises.UIMap.RecordedMethod1() in c:\Users\dtan\Documents\Visual Studio 2013\Projects\CodedUITestProject1\CodedUITestProject1\UIMap.Designer.cs:line 46 
at RoadExercises.RoadExercises.IrVerifyFillInField(String p1, String p2) in c:\Users\dtan\Documents\Visual Studio 2013\Projects\CodedUITestProject1\CodedUITestProject1\RoadExercises.cs:line 169 
at RoadExercises.RoadExercises.RoadExercise1b() in c:\Users\dtan\Documents\Visual Studio 2013\Projects\CodedUITestProject1\CodedUITestProject1\RoadExercises.cs:line 139 
InnerException: System.Runtime.InteropServices.COMException 
HResult=-2147467259 
Message=Error HRESULT E_FAIL has been returned from a call to a COM component. 
Source=Microsoft.VisualStudio.TestTools.UITest.Playback 
ErrorCode=-2147467259 
StackTrace: 
at Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.FindAllDescendants(String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth) 
at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindAllScreenElement(String queryId, Int32 depth, Boolean singleQueryId, Boolean throwException, Boolean resetSkipStep) 
at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String queryId, Int32 depth, Boolean resetSkipStep) 
at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String queryId, Int32 depth) 
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft) 
InnerException: 

據我可以告訴(當我做了各種慢步驟/ null檢查)。無法找到UIEntityTesterTreeListTree的控件。它看起來不在被映射的路徑下。顯然,這個路徑並不是UIWindowWindow.UIEntityTesterControlCustom.UIEntityTesterTree的簡單例子,但是在此之前還有幾個子區域需要經歷。

我試過幾次重新映射,但沒有運氣。我寧願不用硬編碼,所以希望這裏有人能幫我找到解決這個問題的方法。

謝謝!

+0

Web搜索錯誤消息的一部分會提供很多匹配。我搜索「搜索可能失敗,因爲它可能有虛擬化的孩子」的第一個結果是Microsoft博客(由Tapas),並解釋了消息和解決方法。 ' 沒有骰子; – AdrianHHH

+0

通過加入這一行到代碼就會宣告該WpfCell/WpfEdit 'this.UIWindowWindow.UIEntityTesterControlCustom.Container = this.UIWindowWindow.UIPART_DockSitePane.UITabbedMdiContainer2fPane後嘗試他的溶液@AdrianHHH。它仍然墜毀喜歡它,因爲它是無法找到的元素以前那樣:( – DanTan

回答

0

你必須編輯WpfCell的搜索屬性,以確保他們使用正確的價值觀。編碼UI測試生成器通常太專用,無法一直工作,我發現將這些值編輯爲最小公分母是最佳實踐。 Here's一個好地方開始。

我沒有太多的經驗,修改搜索屬性的位置,以尋找在樹中的位置,因爲我發現它使代碼更復雜,並不總是在我的經驗,非常穩定。如果某些元素在開發中被添加或移動,它將會破壞您的所有代碼,您將不得不返回並更改所有映射的參數。我的建議是讓開發人員爲元素添加標識屬性(例如唯一的名稱標籤),以便您可以在搜索中指定該屬性。

如果您熟悉C#中,它可能會更容易,而不是你的代碼映射。如果你有一個元素的特定屬性,那當然會更容易。例如:

<wpfelement> 
    <subElement name='someElement'> 
     <button name='oneButton'>Click me.</button> 
    </subElement> 
</wpfelement> 
<wpfelement> 
    <subElement name='someOtherElement'> 
     <button name='secondButton'>Click me.</button> 
    </subElement> 
</wpfelement> 

會在地圖的發現:

public WpfButton UIItemCell 
{ 
    get 
    { 
     WfpButton target = new WpfButton(parentElement); 
     target.SearchProperties["name"] = "secondButton"; 
     return target; 
    } 
} 

這樣,無論身在何處的元素在你的樹,編碼的UI引擎輕鬆找到它。如果您想要的單元格沒有任何標識屬性,將它們添加到UI中會很有幫助,但是您還可以使用element.GetChildren()從最接近的具有標識符的父級進行導航,並從中進行過濾。

+0

你有沒有修改編碼的UI映射找到的東西在樹前深,垂直?它看起來像我的目標是在一個不同的層次的代碼正在,但也有一些分支。 所以它查找節點[1]中的項目。[3]當它想要的項目真的在節點[2]。[1]。[4]任何想法如何改變屬性來找到它?試圖避免讓代碼檢查整個樹。我知道它在節點[2] [1] [4]中,但我不知道如何從節點[1]移動搜索。[3]到節點[2]。[1]。[4] – DanTan

+0

我編輯了答案。如果不清楚,請告訴我。 –