RyanJM
RyanJM

Reputation: 7068

XCode 7 UI Testing - Actions Available

One thing Apple talked about when introducing Xcode 7's UI testing on iOS 9 was that everything came from accessibility. I'm wondering if anyone knows how to find out if an element has "Actions Available" on it.

I have a UITableView where some cells can be deleted by swiping from right to left revealing the delete button. When VoiceOver is turned on and you tap on the cell it describes the cell as a button and then says "Actions Available".

I'd like to find that out from within my test so I can use to validate that some things are enabled and some things aren't.

Any ideas?

Upvotes: 2

Views: 783

Answers (2)

Mark Tyers
Mark Tyers

Reputation: 3269

The syntax has changed in Swift 3.

let app = XCUIApplication()
let cells = app.tables.cells
cells.element(boundBy: 0).swipeLeft()
cells.element(boundBy: 0).buttons["Delete"].tap()

Upvotes: 1

Daniel Hall
Daniel Hall

Reputation: 13689

I don't know of a way to find out from XCUITesting whether there are any accessibility actions available, and if so, what they are.

But if you are specifically trying to detect if the "Delete" button is available after swiping right-to-left on a cell, you can use something like

yourCellXCUIElement.buttons.count  //How many buttons are visible inside your cell.  In a standard UITableViewCell, this will be 0 unless you have exposed the "Delete" button.

You can also get the label on the button like this:

yourCellXCUIElement.buttons.elementAtIndex(0).label //In a standard UITableViewCell that has been swiped left to expose the Delete button, this will return "Delete"

Is this what you are trying to get at, or are there different things that you are trying to validate are enabled or not?

Upvotes: 0

Related Questions