2

I detected very strange behavior on Xamarin UI test. The issue is - frameworkcan not tap on some marked elements. This absolutely random problem. Issue may appear on Physical Device or Simulator, Android or iOS. Old or new OS Systems. My Test Scenario :

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 Log :

[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 ].

Ok, as you can see the element marked Filter was using -> Tapping coordinates [ 684, 96 ]. That's mean that element is exist on monitor. But first time this not worked. I use Nunit 3.10 and Xamarin UI Test 2.24. This issue can arises on random Device - iOS or Android, Emulator or Physical. Current test was on Samsung sm a310f. I don't know is this bug of Xamarin UI test or may be Calabash.

UPD :

Code -

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"));

Log -

[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] [
  {
Сергей
  • 780
  • 4
  • 13
  • 31

4 Answers4

0

It's normal practice with UITest tests to wait for some defined state after you perform a gesture - so I would advise adding a wait command after each tap.

For example I would code your example as:

app.WaitForElement(x => x.Marked("IDTransHistory"));
app.Tap(x => x.Marked("IDTransHistory"));
app.WaitForElement(x => x.Marked("Button.Home"));
app.Tap(x => x.Marked("Button.Home"));
app.WaitForElement(x => x.Marked("IDTransHistory"));
app.Tap(x => x.Marked("IDTransHistory"));

This way, you're waiting for the element to appear on screen before attempting to press it (with certain devices this is more important than others because screen transition animations can take some time) - also it may be that the element flags up as having co-ordinates when it's not yet ready to receive gestures - so if the above doesn't work you could try adding a Thread.Sleep before the Tap to give the UI time to be ready - this may help stabilise your test.

If that becomes necessary - you'll end up with test code something like this:

app.WaitForElement(x => x.Marked("IDTransHistory"));
Thread.Sleep(500);
app.Tap(x => x.Marked("IDTransHistory"));
app.WaitForElement(x => x.Marked("Button.Home"));
Thread.Sleep(500);
app.Tap(x => x.Marked("Button.Home"));
app.WaitForElement(x => x.Marked("IDTransHistory"));
Thread.Sleep(500);
app.Tap(x => x.Marked("IDTransHistory"));

I would advise starting with a Sleep of 500, raising it in increments of 500 until the test becomes stable.

If all else fails - I would investigate the issue using Repl - it may be that something is blocking the gesture.

It's also worth noting (although based on your description this isn't your issue) that in iOS 11 - Apple made some changes to the way elements are (or are not) Marked so some previously working tests may stop working because the UI is no longer recognising them as Marked in the same way. The best way to work this out is again to interrogate the app using Repl.

Owen Niblock
  • 426
  • 3
  • 11
  • I can wait all my elements, but problem is - elements already exist and tapped! look at log please : `Waiting for element matching Marked("Filter").` `Using element matching Marked("Filter").` `Tapping coordinates [ 684, 96 ].` not worked. – Сергей May 21 '18 at 07:50
  • Yes, but then you need to wait to ensure the next element you're tapping is ready. I don't see anything to say you're waiting for "Date.Start" so it may be that the tap occurs successfully but that the next element isn't ready to tap yet. Please try my suggestion, if that doesn't work, post your findings here and we can take another look :-) – Owen Niblock May 21 '18 at 07:54
  • "Date.Start" element could not be ready, because it exist on other view. Element "Filter" must open new view, but it's not worked. I can't wait "Date.Start" on old view, if it exist on new. anyway I'll try. – Сергей May 21 '18 at 07:59
  • not worked. element can not be tap, but it's exactly exist. – Сергей May 21 '18 at 08:12
  • Thanks for trying it, can you please share your updated test code and log? – Owen Niblock May 21 '18 at 08:13
  • Thanks, can you replicate this using Repl? If you create a test like this: app.ScrollDownTo(x => x.Marked("IDTransHistory")); app.Tap(x => x.Marked("IDTransHistory")); app.WaitForElement(x => x.Marked("Filter")); app.Repl(); And then call this command within the Repl console - what does it do? `app.Tap(x => x.Marked("Filter"));` – Owen Niblock May 21 '18 at 13:42
  • I found my error. the problem was here -> `app.WaitForElement(x => x.Marked("Filter"))`. I don't know why, but this command return true BEFORE `Filter` created on screen. Solution is - just `Thread.Sleep(10000)` – Сергей May 21 '18 at 15:02
  • It's probably because the screen has loaded and the Calabash Server can access the element (but it's not yet available to gesture operations). `10000` seems a bit high for the sleep - I'd usually recommend trying 500 or 1000 to see if that stabilises the test. The last thing we want is to make the test too slow! – Owen Niblock May 21 '18 at 16:31
  • I've added a bit of an extended section in my answer about the Sleep option. – Owen Niblock May 21 '18 at 16:44
  • maybe Calabash is more stable then Xamarin ui test? – Сергей May 21 '18 at 21:18
  • I had a similar issue, a button that appears in the screen but doesn't tap. The wait for the button works for me. In conclusion, if element appears on the screen it doesn't mean that element is ready. –  Jan 17 '20 at 12:19
0

Run app.Repl(); and enter tree . You will find the list of UI visible code try there once with your code. If it is working its fine or else use Class and the class name instead of the Marked with the text on the UI. For instance:- app.Tap( a => a.Class("classs-name")); // if you have same class name used use index for that as app.Tap( a => a.Class("classs-name").index(value));

Pavan N
  • 116
  • 3
0

From documentation: https://learn.microsoft.com/en-us/appcenter/test-cloud/uitest/

Xamarin.UITest requires NUnit 2.6.3 or 2.6.4 to run tests. Xamarin.UITest is not compatible with NUnit 3.x.

That might be your problem.

I would also check if:

  1. Tapping on "Filter" - doesn't cause any layout changes(animations for example) -> pause might help in this case.

  2. Changed the element ID from "Date.Start" to something without dot(.), like "StartDate"

inikityuk
  • 26
  • 4
0

I faced this issue when using ipod touch simulator, when i changed to iPhone simulator it is working as expected

Ajay Kopperla
  • 199
  • 2
  • 5