您将需要添加扩展 SkyFloatingLabelTextField:
extension SkyFloatingLabelTextField {
override open var accessibilityIdentifier: String? {
didSet {
isAccessibilityElement = false
titleLabel.isAccessibilityElement = true
titleLabel.accessibilityIdentifier = (accessibilityIdentifier ?? "") + "Title"
}
}
}
在控制器中,您需要添加accessibilityIdentifier:
@IBOutlet weak var textField: SkyFloatingLabelTextField!
textField.accessibilityIdentifier = "YourTextFieldIdentifier"
如果您想从 XCTestCase 中的 textfild 获取标题:
let app = XCUIApplication()
app.launch()
let elementsQuery = app.scrollViews.otherElements
let getTitle = elementsQuery.textFields["YourTextFieldIdentifier"].staticTexts["YourTextFieldIdentifierTitle"]
XCTAssertEqual(getTitle.label, "Your set title text")
elementsQuery.textFields["YourTextFieldIdentifier"].tap()
elementsQuery.textFields["YourTextFieldIdentifier"].typeText("Type text")