Xcode UI Testing Error keyboard
Asked Answered
B

2

1
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.buttons[@"Committee"] tap];
[app.buttons[@"Login"] tap];
[app.buttons[@"Add Presenter"] tap];

XCUIElement *nameTextField = app/*@START_MENU_TOKEN@*/.textFields[@"Name"]/*[[".scrollViews.textFields[@\"Name\"]",".textFields[@\"Name\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/;
[nameTextField tap];
[nameTextField typeText:@"A"];

XCUIElement *topicTextField = app/*@START_MENU_TOKEN@*/.textFields[@"Topic"]/*[[".scrollViews.textFields[@\"Topic\"]",".textFields[@\"Topic\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/;
[topicTextField tap];
[topicTextField tap];

my error is when run the UI test I receive UI Testing Failure

Neither element nor any descendant has keyboard focus.

Attributes: TextField however the test above passed I have attached a screenshot of what exactly failing enter image description here

Building answered 6/12, 2015 at 8:12 Comment(1)
This might help: #32185337Decorate
S
2

I faced this same problem with Xcode 7.0.1 and was able to resolve it by turning off the connected hardware keyboard in the simulator settings. Hardware -> Keyboard -> Connect Hardware Keyboard (uncheck this). link

Spendthrift answered 4/2, 2016 at 13:16 Comment(1)
is there a way to disable it automatically? It will be enabled with every runBary
L
0

Works for me for native screens:

extension XCUIElement {
    func typeTextAlt(_ text: String) {
        // Solution for `Neither element nor any descendant has keyboard focus.`
        if !(self.value(forKey: "hasKeyboardFocus") as? Bool ?? false) {
            XCUIDevice.shared.press(XCUIDevice.Button.home)
            XCUIApplication().activate()
        }
        self.typeText(text)
    }
}
Locution answered 10/12, 2020 at 21:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.