如何为XCUIElement添加扩展名?

时间:2018-08-22 22:23:27

标签: ios swift xcuitest

一般来说,我是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)
    }
}

0 个答案:

没有答案