一般来说,我是UI测试和xcode / ios开发的新手。如何添加扩展来保存可在UI测试目标中调用的方法?
这是我要添加的SAMPLE扩展名:
extension XCUIElement {
/**
Removes any current text in the field before typing in the new
value
- Parameter text: the text to enter into the field
*/
func clearAndEnterText(text: String) {
guard let stringValue = self.value as? String else {
XCTFail("Tried to clear and enter text into a non string
value")
return
}
self.tap()
let deleteString = stringValue.characters.map { _ in
XCUIKeyboardKeyDelete }.joined(separator: "")
self.typeText(deleteString)
self.typeText(text)
}
}