错误:UI 测试失败 - 找不到 MenuItems 的匹配项
UIPasteboard.generalPasteboard().string = constant.password
enterPasswordTextField.doubleTap()
// Tap the Paste button to input the password
app.menuItems["Paste"].tap()
我已经在我的测试用例中编写了这段代码,我什至尝试过禁用模拟器的硬件键盘,但 doubletap() 函数仍然无法正常工作。
我正在使用 Xcode 7.3.1。
最佳答案
您需要为 menuItem 的出现添加预期。请注意,doubleTap()
只有在文本字段已获得焦点时才会起作用,因此您应该在双击之前添加一个额外的 tap()
let app = XCUIApplication()
UIPasteboard.generalPasteboard().string = "hello"
let enterPasswordTextField = app.textFields["textField"]
enterPasswordTextField.tap()
expectationForPredicate(NSPredicate(format: "count > 0"), evaluatedWithObject: app.menuItems, handler: nil)
enterPasswordTextField.doubleTap()
waitForExpectationsWithTimeout(10.0, handler: nil)
app.menuItems["Paste"].tap()
请记住,通过本地化测试访问菜单项可能不是最好的主意,因为它可能在非英语设备上失败。因此,您应该使用最复杂的逻辑来确定粘贴菜单项的位置。对于初学者,在文本字段为空的过于简单化的假设中,您可能需要替换
app.menuItems["Paste"].tap()
与
app.menuItems.elementsBoundByIndex(2).tap()
关于ios - UI 测试失败 - 未找到 MenuItems 的匹配项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38310256/