UI测试失败-找不到与菜单项匹配的内容

问题描述 投票:0回答:3

错误: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。

ios swift ios9 xcode-ui-testing
3个回答
3
投票
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()

0
投票
注意,如果您以双击非活动文本字段的速度双击,则不会出现粘贴板菜单,因此,请尝试将操作分为两个单独的部分。如果需要,请在每次点击之间添加一个睡眠命令。

0
投票
当isSecureTextEntry = true时,您应该使用app.secureTextFields而不是app.textFields,如下面的行所示>

let passwordField = app.secureTextFields["password"]

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.