In my XCUITests I need to check content of floating title label in SkyFloatingLabelTextField after validation error.
I've set accessibilityIdentifier for SkyFloatingLabelTextField element, so I can tap and enter text into it without any issue, but how can I access its title (titleLabel?) using only XCUIElement?
I tried to set titleLabel as accessibilityElement with its own accessibilityIdentifier, but I wasn't able to access the text field in my tests after that.
You will need add extension SkyFloatingLabelTextField:
extension SkyFloatingLabelTextField {
override open var accessibilityIdentifier: String? {
didSet {
isAccessibilityElement = false
titleLabel.isAccessibilityElement = true
titleLabel.accessibilityIdentifier = (accessibilityIdentifier ?? "") + "Title"
}
}
}
In controller you need add accessibilityIdentifier:
@IBOutlet weak var textField: SkyFloatingLabelTextField!
textField.accessibilityIdentifier = "YourTextFieldIdentifier"
If you want get title from textfild in your XCTestCase:
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")
SkyFloatingLabelTextField
继承自UITextField
因此任何适用于UITextField
方法也应该适用于SkyFloatingLabelTextField
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.