1
我在等待一个控制这样启用:WaitForControlEnabled()抛出UITestControlNotFoundException
control.WaitForControlEnabled(60000); // timeout in 60 seconds
然而,有时这种方法大约十秒钟就会抛出一个UITestControlNotFoundException
:
Test method MyTest threw exception:
Automation Playback Engine was not able to find the button &Next > in - window &Next >. Additional Details: TechnologyName: 'MSAA' Name: 'Next >' ControlType: 'Button'
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException
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, Boolean expandUIElementWhileSearching, Int32 searchTime)
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.FindControlIfNecessary()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlReadyPrivate(Int32 millisecondsTimeout, Boolean doLogging)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlEnabledPrivate(Int32 millisecondsTimeout)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl+<>c__DisplayClass4a.<WaitForControlEnabled>b__49()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod(Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlEnabled(Int32 millisecondsTimeout)
Error HRESULT E_FAIL has been returned from a call to a COM component.
System.Runtime.InteropServices.COMException
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.UITesting.UITestControl.FindFirstDescendant(String queryId, Boolean expandUIElementWhileSearching, Int32 searchTime)
我问题是:
- 为什么
WaitForControlEnabled(60000)
等待整个60秒? - 即使MSDN doc中没有提及
UITestControlNotFoundException
,它为什么会丢掉?
编辑:我用WaitForControlExist()
直接WaitForControlEnabled()
之前,但WaitForControlEnabled()
仍然抛出同样的异常,这是没有意义的我:
control.WaitForControlExist(60000);
control.WaitForControlEnabled(60000);
如果WaitForControlExist()
回报,那么这意味着UI元素被找到。但那么怎么能不能立刻发现?