我在編碼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(任務的任務)的位置
所以,我怎麼能解決這個問題?請幫幫我。