UI Testing Failure - Neither element nor any descendant has keyboard focus on secureTextField

后端 未结 24 1530
难免孤独
难免孤独 2020-12-12 10:41

This is my case:

let passwordSecureTextField = app.secureTextFields[\"password\"]
passwordSecureTextField.tap()
passwordSecureTextField.typeText(\"wrong_pass         


        
24条回答
  •  Happy的楠姐
    2020-12-12 10:59

    I have written a small extension (Swift) which works perfect for me. Here is the code:

    extension XCTestCase {
    
        func tapElementAndWaitForKeyboardToAppear(element: XCUIElement) {
            let keyboard = XCUIApplication().keyboards.element
            while (true) {
                element.tap()
                if keyboard.exists {
                    break;
                }
                NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 0.5))
            }
        }
    }
    

    The main idea is to keep tapping an element (text field) before the keyboard is presented.

提交回复
热议问题