错误: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。
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()
let passwordField = app.secureTextFields["password"]