Reputation: 376
Error:UI Testing Failure - No matches found for MenuItems
UIPasteboard.generalPasteboard().string = constant.password
enterPasswordTextField.doubleTap()
// Tap the Paste button to input the password
app.menuItems["Paste"].tap()
I have written this code in my test case , i have even tried disabling hardware keyboard for the simulator but still the doubletap() function is not working.
I am using Xcode 7.3.1.
Upvotes: 1
Views: 2743
Reputation: 475
https://stackoverflow.com/a/58246279/9109530
when isSecureTextEntry = true you should use app.secureTextFields instead app.textFields like as below line
let passwordField = app.secureTextFields["password"]
Upvotes: 0
Reputation: 7649
Do two taps separately - one to give focus to the text field and then one to bring up the menu items.
Observe that if you do a double tap with the speed of a double click on an inactive text field, the pasteboard menu does not appear, so just try separating the action into two separate parts. If you need to, add a sleep command between each tap.
Upvotes: 0
Reputation: 10086
You will need to add an expectation for the menuItem to appear. Note that doubleTap()
will work only if the textfield already has focus, so you should add an additional tap()
before double tapping
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()
Bear in mind that it might not be the best idea to use access the menuitem with the localised test, as it may fail on a device on non-english devices. Therefore you should use a most sophisticated logic to determine the location of the paste menu item. For starters, in the oversimplified hypothesis that the textfield is empty, you may want to replace
app.menuItems["Paste"].tap()
with
app.menuItems.elementsBoundByIndex(2).tap()
Upvotes: 3