XCUITest fails when element is offscreen?

Is anyone else seeing XCUITest fail for tap()ing elements that happen to be offscreen?


The code is finding the element exists, but when calling tap(), nothing at all happens if the element is scrolled off-screen.


Thanks!

Answered by Engineer in 57944022

UI testing in Xcode works by sending events like a user would - this is per design, to ensure that your test results align with what your users would experience when using your app. If the keyboard is covering a control then a user couldn't interact with it, and neither can your test.

That sounds like a bug. Please file a bug report (using the Report Bugs link at the bottom of this page). Thanks!

Thanks! I did so earlier today radar://220502809

Running into the same problem (22584968). It's not fixed in the GM, unfortunately. 😟

This is unfortunate. Not being able to select any item that is scrolled off the view might be understandable, but it something hides an element (such as the keyboard covering a button) then you can't interact with it at all 😟

Accepted Answer

UI testing in Xcode works by sending events like a user would - this is per design, to ensure that your test results align with what your users would experience when using your app. If the keyboard is covering a control then a user couldn't interact with it, and neither can your test.

Then you need to have the ability to specify "scroll to element" in the test code. It blows my mind that Apple could put all this effort into the test functionality then leave it so fundamentally broken.

I'm using Xcode 9.2, Java TestNG and iOS 11.2.5 to test a native iOS app. If I use tap on an element that is not displayed / off screen the application will scroll to it and tap on it.


String dba = "My Account";
MobileElement el = driver.findElementByName(dba);
el.tap(1, 1000); // I tried click() which doesn't work b/c it's not a user action in iOS.
assertTrue(el.isDisplayed());
XCUITest fails when element is offscreen?
 
 
Q