UITesting Xcode 7: How to tell if XCUIElement is visible?
Looks like this is a known bug :-(
https://forums.developer.apple.com/thread/9934
Testing if an element is visible with Xcode 7 UITest
As of Xcode 7.1 Beta 3, UI Testing does not currently support validating the visibility of an element. I suggest filing a radar to bring the necessary attention to Apple.
Xcode 7.1 has fixed this issue. hittable
now checks to see if the element is correct.
Check the position of the XCUIElement on screen while testing iOS Application using XCTest
XCUIElement
has a property frame
which you can use to find the coordinates of the element in question.
let button = XCUIApplication().buttons["someButton"]
let frame = button.frame
let xPosition = frame.origin.x
let yPosition = frame.origin.y
There are other ways of retrieving different points relative to the frame, which is a CGRect
, such as midX
and midY
, depending on how you want to assert the position of the element.
You should be aware that XCTest is a functional UI testing framework, and if you are using it for asserting the position of an element, the position will probably be different per device/simulator which may make your tests brittle.
iOS UITests - Detect if any XCUIElement have ever been tapped on current run
XCUIElement.isEnabled
, XCUIElement.isSelected
and XCUIElement.value
can give you state information about the element.
If you expect the button to be toggled on/off, use the enabled or selected state on UIControl (UIButton inherits from UIControl) to set those properties and access them from your tests via XCUIElement.
If you want the button to count how many times it has been tapped, increment the value in your app each time it is tapped and access the value
property in your test.
How can I verify a cell is visible in my UI Test
As far as checking whether something is visible goes, you want to use isHittable in conjunction with exists. See also here.
Like so:
element.exists && element.isHittable
You have said isHittable does not work for you, can you explain what it does not do?
Accessing nested UIElements in Xcode 7 UI Testing
I didn't know this at the time, but what I was looking for was basically debugDescription:
Set a breakpoint when you hit the area you're trying to debug. Then
po print(app.debugDescription)
in the debug console. You will see the hierarchy then.
Related Topics
Swift Extension for Selected Class Instance
Self.Image.Frame.Width = 20 Give Get Only Property Error
Nsundomanager Casting Nsundomanagerproxy Crash in Swift Code
How to Disambiguate a Type and a Module With the Same Name
Using Swift Library in Xamarin
Common Equatable Class on Swift
Swift Codable Decode Manually Optional Variable
How to Enumerate a Slice Using the Original Indices
Error When Using Generic as Property Type in Swift
How Use and Run Swift 2.3 on Command Line
Sending a Parameter Argument to Function Through Uitapgesturerecognizer Selector
Clipped Image Calls Tapaction Outside Frame
Iterating with for .. in on a Changing Collection
Scene Created in Sprite Kit Level Editor Is Not Working
Nsfetchedresultscontollerdelegate For Collectionview
How to Read and Write Data to a Text File in Swift Using Playground
Swiftui: Navigation Bar Title in Reusable Cross-Platform (iOS & MACos) View