问题
Hello I'm learning UITests
now
I have a question
how can detect accessoryView's tap on the tableViewCell
?? in UITest
below is my tableViewCell
I want detect detail closure accesorry view's tap
like this
app.tables.cells.buttons["FTCellAccesoryIdentifier"].tap()
but accesorry is a subclass of UIView
so i allocate accisibility identifier key in cellForRows
function
cell.accessoryView?.accessibilityIdentifier ="FTCellAccesoryIdentifier"
and my test function is
i try
app.tables.cells.elementBoundByIndex(lastCellIndex).otherElements.elementMatchingType(.Any, identifier: "FTCellAccesoryIdentifier").tap()
but not work
is possible to tap cell's accesoryView in UITests?
回答1:
TL;DR
Regarding...
is possible to tap cell's accesoryView in UITests?
... Yes.
But you have to use the default accessibility identifier for that.
For example, for a cell like this one:
Tapping the Detail Disclosure button during a UI test ("More Info" is the key here):
XCUIApplication().tables.buttons["More Info, Title"].tap()
Tapping the cell itself during a UI test:
XCUIApplication().tables.staticTexts["Title"].tap()
Long story:
There is no way to change the default accessibility identifier of the Detail Disclosure. From Apple:
Note: If your table cells contain any of the standard table-view elements, such as the disclosure indicator, detail disclosure button, or delete control, you do not have to do anything to make these elements accessible. If, however, your table cells include other types of controls, such as a switch or a slider, you need to make sure that these elements are appropriately accessible.
At the time you try to set the accessibility identifier/label of the Detail Disclosure in cellForRow
, cell.accessoryView
is nil. Why? Again, from Apple:
accessoryView
Discussion
If the value of this property is not nil, the UITableViewCell class uses the given view for the accessory view in the table view’s normal (default) state; it ignores the value of the accessoryType property. The provided accessory view can be a framework-provided control or label or a custom view. The accessory view appears in the the right side of the cell.
The accessory view will be nil until you define them. :/
You would need to provide your "own" Detail Disclosure (e.g.: a customized UIView) if you really want to set a custom identifier for it. For example (to illustrate):
cell.accessoryView = UIView(frame: CGRectMake(0, 0, 20, 20))
cell.accessoryView?.backgroundColor = UIColor.blueColor()
cell.accessoryView?.accessibilityIdentifier = "FTCellAccesoryIdentifier"
回答2:
You should use accessoryButtonTappedForRowWithIndexPath
delegate method to handle click on accessoryView
.
Then by indexPath
parameter of method you can know which cell it is!
Hope this will help :)
来源:https://stackoverflow.com/questions/37322067/ios-uitest-how-to-find-uitableviewcells-accessoryview