Required ability to determine if an element/view is hidden or not in XCUITests
| Originator: | spectrumanalysis | ||
| Number: | rdar://23127074 | Date Originated: | 15-Oct-2015 |
| Status: | Duplicate/23511424 | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode Version 7.0 (7A220) |
| Classification: | Enhancement | Reproducible: |
My application hides or shows the login/logout button after checking whether the user is logged in or not. In the app code the hidden attribute of the Views are updated as such self.logInView.hidden = HCIUserInstance.isLoggedIn; self.logOutButton.hidden = !HCIUserInstance.isLoggedIn; The current APIs for XCTest do not provide a way to verify if an element is visible on the screen. XCUIElement.exist always returns true irrespective of visibility. Steps to Reproduce: Expected Results: What is required is an API (for eg) XCUIElement.hidden which returns true/false based on the hidden property of the UIElement Actual Results: No API to find hidden status Version: Xcode Version 7.0 (7A220) OSX 10.11 (15A284) Notes: Configuration: Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Reply to above comment
The hittable property results true for both the buttons irrespective of visibility. I tried the following.
1) When the user is not logged in (i.e Login button is shown and logout button is not shown)
let logOutButton = XCUIApplication().scrollViews.buttons["LOG OUT"] print(logOutButton.debugDescription) print(logOutButton.hittable)
let logInButton = XCUIApplication().scrollViews.buttons["LoginButtonProfile"] print(logInButton.debugDescription) print(logInButton.hittable)
The output for the hittable property was true for both
Hittable Logout:true t = 4.97s Find the "LoginButtonProfile" Button t = 4.97s Snapshot accessibility hierarchy for
t = 5.03s Find: Descendants matching type ScrollView
t = 5.04s Find: Descendants matching type Button
t = 5.04s Find: Elements matching predicate '"LoginButtonProfile" IN identifiers'
HittableLogin:true
2) When user is logged in (Logout button is shown and loginButton is hidden)
Hittable Logout:true t = 7.45s Find the "LoginButtonProfile" Button t = 7.45s Snapshot accessibility hierarchy for
t = 7.51s Find: Descendants matching type ScrollView
t = 7.52s Find: Descendants matching type Button
t = 7.52s Find: Elements matching predicate '"LoginButtonProfile" IN identifiers'
HittableLogin:true
Also to add, if I run loginButton.tap() when the loginButton is hidden it simulates a tap at the location the Login Button is supposed to be and taps the element that is now in that position
P.S. Masked the package name on this radar.
Reply from Apple Developer Relations
This issue behaves as intended.
Try the “hittable” property:
/! Whether or not a hit point can be computed for the element for the purpose of synthesizing events. / @property (readonly, getter = isHittable) BOOL hittable;
Please update your bug report to let us know if this is still an issue for you.