UI Testing Failure - Neither element nor any desce

2019-01-21 01:06发布

This is my case:

let passwordSecureTextField = app.secureTextFields["password"]
passwordSecureTextField.tap()
passwordSecureTextField.typeText("wrong_password") //here is an error

UI Testing Failure - Neither element nor any descendant has keyboard focus. Element:

What is wrong? This is working nice for normal textFields, but problem arise only with secureTextFields. Any workarounds?

18条回答
The star\"
2楼-- · 2019-01-21 01:08

We encountered the same error when setting the accessibilityIdentifier value for a custom view (UIStackView subclass) containing UIControl subviews. In that case XCTest was unable to get the keyboard focus for the descendent elements.

Our solution was simply to remove the accessibilityIdentifier from our parent view and set the accessibilityIdentifier for the subviews through dedicated properties.

查看更多
萌系小妹纸
3楼-- · 2019-01-21 01:09

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.

查看更多
The star\"
4楼-- · 2019-01-21 01:12

It occurred with me for many times. You have to disable Keyboard Hardware and Same Layout as OSX in your Simulator

Hardware/Keyboard (disable all)

After that keyboard software won't dismiss and your tests can type text

Disable Hardware

查看更多
干净又极端
5楼-- · 2019-01-21 01:12

Use a sleep between launching the app and typing in data in textfields like this:

sleep(2)

In my case I was keeping getting this error every time and only this solution helped my out.

查看更多
相关推荐>>
6楼-- · 2019-01-21 01:14
func pasteTextFieldText(app:XCUIApplication, element:XCUIElement, value:String, clearText:Bool) {
    // Get the password into the pasteboard buffer
    UIPasteboard.generalPasteboard().string = value

    // Bring up the popup menu on the password field
    element.tap()

    if clearText {
        element.buttons["Clear text"].tap()
    }

    element.doubleTap()

    // Tap the Paste button to input the password
    app.menuItems["Paste"].tap()
}
查看更多
Summer. ? 凉城
7楼-- · 2019-01-21 01:15

Don't messed up, There problem caught the reason is you are recorded your testing time your app will connection hardware keyboard while your automatic testing time simulator takes only software keyboard. so for how to fix this issues. Just use software keyboard on your recording time. you can see the magic.

查看更多
登录 后发表回答