Uitesting Xcode 7: How to Tell If Xcuielement Is Visible

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



Leave a reply



Submit