【发布时间】:2026-02-03 10:20:05
【问题描述】:
我正在开发一个具有多个自定义控件的 WPF 应用程序。我正在使用编码的 UI 测试构建器为我的应用程序测试创建脚本。当我运行测试时,它给了我一个异常,异常发生在下面显示的行。
uIRadComboBoxComboBox.SelectedItem = this.SelectingWeddingParams.UIRadComboBoxComboBoxSelectedItem;
我尝试过使用鼠标单击和更改坐标,但效果不佳。
函数的代码是
区域变量声明
WpfCustom uIItemCustom = this.UIIntelliClientWindow.UIItemCustom;
WpfComboBox uIRadComboBoxComboBox = this.UIIntelliClientWindow.UIEventInfoRegionCustom1.UIPleasewaitProgressBar.UIRadComboBoxComboBox;
#endregion
// Click custom control
Mouse.Click(uIItemCustom, new Point(448, 307));
// Select 'Wedding' in 'RadComboBox' combo box
uIRadComboBoxComboBox.SelectedItem = this.SelectingWeddingParams.UIRadComboBoxComboBoxSelectedItem;
异常贴在下面。
结果堆栈跟踪:
在 Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.FindAllDescendants(字符串 bstrQueryId,对象和 pvarResKeys,Int32 cResKeys,Int32 nMaxDepth)
在 Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindAllScreenElement(字符串 queryId,Int32 深度,布尔 singleQueryId,布尔 throwException,布尔 resetSkipStep)
在 Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(字符串 queryId,Int32 深度,布尔 resetSkipStep)
在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(字符串 queryId、Int32 maxDepth、Int32&timeLeft)
--- 内部异常堆栈跟踪结束 ---
在 Microsoft.VisualStudio.TestTools.UITesting.Playback.MapControlNotFoundException(COMException ex,IPlaybackContext 上下文)
在 Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException(COMException innerException,IPlaybackContext 上下文)
在 Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(异常异常,IPlaybackContext 上下文)
在 Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(异常异常,字符串 queryId)
在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(字符串 queryId、Int32 maxDepth、Int32&timeLeft)
在 Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(布尔 useCache,ISearchArgument searchArg)
在 Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search(ISearchArgument searchArg)
在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindControlIfNecessary()
在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetPropertyPrivate(字符串属性名称,对象值)
在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.c__DisplayClass180_0.b__0()
在 Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 函数,UITestControl 控件,布尔型 firePlaybackErrorEvent,布尔型 logAsAction)
在 Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetProperty(字符串属性名称,对象值)
在 Microsoft.VisualStudio.TestTools.UITesting.WpfControls.WpfComboBox.set_SelectedItem(字符串值)
在 C:\Users\Dev2\source\repos\AddingEventUsingDataDrivenTesting\AddingEventUsingDataDrivenTesting\UIMap.Designer.cs:line 166 中添加EventUsingDataDrivenTesting.UIMap.SelectingWedding()
在 C:\Users\Dev2\source\repos\AddingEventUsingDataDrivenTesting\AddingEventUsingDataDrivenTesting\CodedUITest1.cs:line 30 中添加EventUsingDataDrivenTesting.CodedUITest1.CodedUITestMethod1()
结果消息:
测试方法AddingEventUsingDataDrivenTesting.CodedUITest1.CodedUITestMethod1 抛出异常:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException:播放未能找到具有给定搜索属性的控件。额外细节:
技术名称:'UIA'
框架 ID:'Wpf'
控件类型:'组合框'
帮助文本:'RadComboBox'
实例:'2'
搜索可能在“TabList”处失败,因为它可能已经虚拟化了子项。如果正在搜索的控件是 '' TabList 的后代,则将其包含为父容器可能会解决问题。 ---> System.Runtime.InteropServices.COMException: 对 COM 组件的调用已返回错误 HRESULT E_FAIL。
【问题讨论】:
-
需要编写自定义控件以支持编码 UI。也许您应该向自定义控件的作者或提供者询问他们为 Coded UI 提供的支持级别。
标签: coded-ui-tests