Xamarin.forms: [Xamarin.UITest] WaitForElement does not find rotated elements

Created on 18 Apr 2018  路  5Comments  路  Source: xamarin/Xamarin.Forms

Description

When we have a XAML layout with a -90藲 rotated ListView and 90藲 rotated list items the Xamarin.UITest packaged is unable to locate the elements as expected. e.g. app.WaitForElement(...)

Steps to Reproduce

  1. Create a ListView rotated -90藲
  2. Include items rotated 90藲 with any marker
  3. Write a Xamarin.UITest where you call app.WaitForElement for the markers

Expected Behavior

To the WaitForElement method find the marked rotated element within the timeout.

Actual Behavior

No element is ever found even if they are cleary visible in the running application.

Basic Information

When running the REPL tree command in this scenario is obvious that the element tree is not complete, somehow empty.

  • Version with issue: 2.2.4
  • Last known good version: ?
  • IDE: Visual Studio Community 2017 for Mac Version 7.4.2
  • Platform Target Frameworks: Android

    • Android: 8.2.0.16

    • SDK Tools Version: 26.1.1

    • SDK Platform Tools Version: 27.0.1

    • SDK Build Tools Version: 27.0.3

  • Android Support Library Version: 25.4.0.2
  • Nuget Packages:

    • Xamarin.Forms 2.5.1

    • Xamarin.UITest 2.2.4

  • Affected Devices: Any

Reproduction Link

With the linked project:

  1. Restore nuget packages on build/rebuild
  2. Select Release build configuration for the Android project
  3. Build the test project
  4. Run the two included tests in the test pad, one should work for the non rotated ListView and the second one should fail for the rotated ListView.

https://www.dropbox.com/s/279qlu5ki3p5j82/Xamarin_UITest_Rotated_Bug.zip?dl=0

uitest help wanted inactive unverified bug up-for-grabs

All 5 comments

Is there any fix expected soon?

waiting for a fix. My ui tests are failing because of this bug

Any updates?

The App Center Test team has determined the underlying cause of this issue as well as a workaround.

The cause of the issue is that when the image is rotated, Xamarin.UITest incorrectly determines it as being offscreen, so it can be found by appending .All() to an otherwise valid query for the element:

app.Tap(x=>x.All().Marked(STRING));

Because .All() returns "all" matching elements, not just those currently visible in the UI, it's recommended that you check that the element you're searching for is either the 1st returned with this query at index zero (app.Tap() activates the 1st element found), and/or you add additional methods to make sure you're actually targeting the right element.

The rotation may also offset the elements coordinates. If the logging reports that the element is tapped but the element is not actually activated, it may be because the miscalculation is enough to move the detected center of the element off of the element itself.

If you are blocked by that aspect, you should be able to use the REPL tool and app.Query(x=>x.All().Marked(STRING)); to gather more data on where the element actually is showing up & use that two write a correction; for example app.TapCoordinates(updated coordinates).

The tricky thing is that the precise coordinates of an element can vary by screen resolution, so you might have to write a helper method that dynamically checks the location, applies a correction and then finally taps that location. I have some examples of general helper method implementations with Xamarin.UITest, but not currently an example of this exact scenario: https://github.com/King-of-Spades/AppCenter-Test-Samples/blob/master/Xamarin.UITest/FormsGallery/FormsGallery.UITest/HelperMethods.cs

Unfortunately a fix is _not_ expected to be available soon, which is why I've prioritized giving this workaround information. I haven't fully QA'd the workaround but the details here cover what's known and been observed on the issue, please let me know if the workaround is ineffective.

@arctouch-fabriciomiranda If you continue to experience this issue, please report it via App Center. Thanks!

Was this page helpful?
0 / 5 - 0 ratings