Xcode UI Testing Error keyboard

假如想象 提交于 2021-01-31 07:27:09

问题


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


回答1:


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




回答2:


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)
    }
}


来源:https://stackoverflow.com/questions/34115375/xcode-ui-testing-error-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!