Dam*_*ard 6 xcode uitableview swift xcode-ui-testing
使用Xcode UI测试,我无法查询UITableView中的单元格
UITableView包含3个单元格:
import UIKit
@objc class DumpTable: UITableViewController {
var objects: [NSDate] = [NSDate]()
override func viewDidLoad() {
super.viewDidLoad()
objects.append(NSDate())
objects.append(NSDate())
objects.append(NSDate())
tableView.isAccessibilityElement = true
tableView.accessibilityLabel = "Thetable"
tableView.accessibilityIdentifier = "Thetable"
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return objects.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let object = objects[indexPath.row]
cell.textLabel!.text = object.description
cell.isAccessibilityElement = true
cell.accessibilityLabel = "Thecell"
cell.accessibilityIdentifier = "Thecell"
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
测试非常简单.
给定一个带有3个单元的UITableView,我试图断言有任何单元可用:
XCTAssertTrue(XCUIApplication().tables["Thetable"].exists)
XCTAssertTrue(XCUIApplication().tables["Thetable"].cells.count > 0)
Run Code Online (Sandbox Code Playgroud)
然后它会在2个断言上失败:
Assertion Failure: XCTAssertTrue failed -
/Users/damiengavard/Desktop/Table/TableUITests/TableUITests.swift:33: error: -[TableUITests.TableUITests testExample] : XCTAssertTrue failed -
Run Code Online (Sandbox Code Playgroud)
https://github.com/dagio/TableCellAccessibility
只需执行Cmd + U.
我在这里找到了答案.为了使UITableViewCell可访问性,包含UITableView本身不可访问.
所以,你只需要删除这些行:
tableView.isAccessibilityElement = true
tableView.accessibilityLabel = "Thetable"
tableView.accessibilityIdentifier = "Thetable"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1156 次 |
| 最近记录: |