我在 Xamarin UI 测试中检测到非常奇怪的行为。问题是 -framework
无法点击某些标记的元素。这绝对是随机的问题。问题可能出现在物理设备或模拟器、Android 或 iOS 上。旧的或新的操作系统系统。我的测试场景:
app.WaitForElement(x => x.Marked("IDTransHistory"));
app.Tap(x => x.Marked("IDTransHistory"));
try
{
app.WaitForElement(x => x.Marked("Filter"));
app.Tap(x => x.Marked("Filter"));
}
catch (Exception)
{
try
{
app.Tap(x => x.Marked("Button.Home"));
app.Tap(x => x.Marked("IDTransHistory"));
}
catch (Exception)
{
try
{
app.Tap(x => x.Marked("Button.Home"));
app.Tap(x => x.Marked("IDTransHistory"));
}
catch (Exception)
{
app.Tap(x => x.Marked("Button.Home"));
app.Tap(x => x.Marked("IDTransHistory"));
}
}
}
VS日志:
[5/18/2018 12:57:16 PM Informational] ------ Run test started ------
[5/18/2018 12:57:16 PM Informational] NUnit VS Adapter 2.0.0.0 executing tests is started
...
[5/18/2018 12:57:56 PM Informational] Waiting for element matching Marked("IDTransHistory").
[5/18/2018 12:58:03 PM Informational] Using element matching Marked("IDTransHistory").
[5/18/2018 12:58:04 PM Informational] Tapping coordinates [ 532, 1114 ].
[5/18/2018 12:58:05 PM Informational] Waiting for element matching Marked("Filter").
[5/18/2018 12:58:08 PM Informational] Using element matching Marked("Filter").
[5/18/2018 12:58:08 PM Informational] Tapping coordinates [ 684, 96 ].
[5/18/2018 12:58:24 PM Informational] Error while performing Tap(Marked("Date.Start"))
Exception: System.Exception: Unable to find element. Query for Marked("Date.Start") gave no results.
at Xamarin.UITest.SharedApp.FirstWithLog[T](T[] results, ITokenContainer tokenContainer)
at Xamarin.UITest.Android.AndroidApp.<Tap>c__AnonStoreyB.<>m__0()
at Xamarin.UITest.Utils.ErrorReporting.With(Action func, Object[] args, String memberName)
[5/18/2018 12:58:24 PM Informational] Waiting for element matching Marked("Filter").
[5/18/2018 12:58:28 PM Informational] Using element matching Marked("Filter").
[5/18/2018 12:58:28 PM Informational] Tapping coordinates [ 684, 96 ].
[5/18/2018 12:58:32 PM Informational] Using element matching Marked("Date.Start").
[5/18/2018 12:58:32 PM Informational] Tapping coordinates [ 71, 298 ].
[5/18/2018 12:58:35 PM Informational] Using element matching Text("2018").
[5/18/2018 12:58:35 PM Informational] Tapping coordinates [ 139, 228 ].
好的,您可以看到标记的元素Filter
使用 -> Tapping 坐标 [684, 96]。这意味着该元素存在于监视器上。但是第一次这不起作用。我使用 Nunit 3.10 和 Xamarin UI Test 2.24。此问题可能出现在随机设备 - iOS 或 Android、模拟器或物理设备上。当前测试是在三星 sm a310f 上进行的。我不知道这是 Xamarin UI 测试的错误还是可能是 Calabash。
更新:
代码 -
app.ScrollDownTo(x => x.Marked("IDTransHistory"));
app.Tap(x => x.Marked("IDTransHistory"));
app.WaitForElement(x => x.Marked("Filter"));
app.Tap(x => x.Marked("Filter"));
app.WaitForElement(x=>x.Marked("Date.Start"));
app.Tap(x => x.Marked("Date.Start"));
日志 -
[5/21/2018 3:05:00 PM Informational] Skipping installation: Already installed.
----
[5/21/2018 3:05:34 PM Informational] Scrolling down to Marked("IDTransHistory")
[5/21/2018 3:05:37 PM Informational] Using element matching Marked("IDTransHistory").
[5/21/2018 3:05:37 PM Informational] Tapping coordinates [ 533, 1114 ].
[5/21/2018 3:05:38 PM Informational] Waiting for element matching Marked("Filter").
[5/21/2018 3:05:40 PM Informational] Using element matching Marked("Filter").
[5/21/2018 3:05:40 PM Informational] Tapping coordinates [ 684, 96 ].
[5/21/2018 3:05:41 PM Informational] Waiting for element matching Marked("Date.Start").
[5/21/2018 3:05:56 PM Informational] Error while performing WaitForElement(Marked("Date.Start"), "Timed out waiting for element...", null, null, null)
Exception: System.TimeoutException: Timed out waiting for element...
at Xamarin.UITest.Shared.WaitForHelper.WaitForAny[T](Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout)
at Xamarin.UITest.Android.AndroidApp.<WaitForElement>c__AnonStorey31.<>m__0()
at Xamarin.UITest.Utils.ErrorReporting.With[T](Func`1 func, Object[] args, String memberName)
[5/21/2018 3:05:57 PM Informational] Query for * gave 46 results.
[5/21/2018 3:05:57 PM Informational] [
{