我在编码UI测试中创建一个TestMethod,它将访问我的Windows Phone 8.1应用程序中的UI控件。我使用了异步方法执行多线程任务处理,但我得到了像这样我的代码异常:编码UI测试中的TestMethod
[TestMethod]
async public Task CodedUITestMethod1()
{
XamlWindow.Launch("{556EE9D4-5640-4120-9916-44B1CA27352F}:App:556ee9d4-5640-4120-9916-44b1ca27352f_tpza89sffjg1j!App");
await ExecuteOnUIThread(() =>
{
MainPage mainPage = new MainPage();
Microsoft.VisualStudio.TestTools.UITest.Input.Point point = new Microsoft.VisualStudio.TestTools.UITest.Input.Point(mainPage.getX(), mainPage.getY());
Gesture.Tap(point);
}
);
}
和
public static IAsyncAction ExecuteOnUIThread(Windows.UI.Core.DispatchedHandler action)
{
return Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, action);
}
,但我得到的异常消息是:测试名称:CodedUITestMethod1 测试真实姓名:CodedUITestProject2.CodedUITest1.CodedUITestMethod1 测试来源:C:\用户\青\桌面\计算器\ CodedUITestProject2 \ CodedUITest1.cs:行28 测试结果:失败 测试时间:0:00:02.3440269
结果消息: 测试方法CodedUITestProject2.CodedUITest1.CodedUITestMethod1抛出异常: System.InvalidOperationException:在意外的时间调用方法。
一个方法在意想不到的时间被调用。 结果堆栈跟踪:
在Windows.ApplicationModel.Core.CoreApplication.get_MainView() 在CodedUITestProject2.CodedUITest1.ExecuteOnUIThread(DispatchedHandler动作) 在CodedUITestProject2.CodedUITest1.d__2.MoveNext() ---从先前堆栈跟踪结束其中引发异常--- 在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务task) 在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)的位置
所以,我怎么能解决这个问题?请帮帮我。