50

Our UI test suites are showing some unexpected behaviour where our Create Password screen intermittently auto-completes both the username and password - this results in the test being failed.

The process is something like:

  • Tap in the first create password field
  • Enter a password
  • Tap in the confirm password field
  • Enter the same password

This last step fails because the passwords in both fields have been auto-completed.

enter image description here

This happens for about one in every ten to twenty test executions.

Our understanding is that the password auto-fill should never be seen in any simulator, so it's very confusing to see this at all. Is there something that we can do to extra disable autofill, or otherwise prevent this from happening?

Estel
  • 2,154
  • 2
  • 18
  • 25
  • This was filed as rdr://49643422 / Feedback FB5665786 – Estel Jun 12 '19 at 10:41
  • If anyone else is having the issue we mitigated it by modifying the UI test slightly to manually dismiss the keyboard before moving to the second input field. – Estel Jun 12 '19 at 12:01
  • 1
    This was only happening intermittently before, but in iOS 16 it now happens every time for me. – shim Oct 03 '22 at 21:04

9 Answers9

28

going to settings of the simulator -> Passwords -> Turn On and then Turn OFF AutoFill passwords.

enter image description here

type any password

enter image description here

enter image description here

shim
  • 9,289
  • 12
  • 69
  • 108
Same7Farouk
  • 837
  • 9
  • 19
21

Had the same problem. What was useful for me is going to settings of the simulator -> Passwords -> Turn On and then Turn OFF AutoFill passwords.

5

Not sure if it was like that since the beginning but setting isSecureTextEntry = true is enough to trigger that bug as well (at least in Xcode 12.2).

Therefore, the work-around which worked for me was:

let field = UITextField()
if #available(iOS 11.0, *) {
    #if targetEnvironment(simulator)
    // Do Not enable '.password' or '.newPassword' or 'isSecureTextEntry' text content type on simulator as it ends up with annoying behaviour:
    // 'Strong Password' yellow glitch preventing from editing field.
    print("Simulator! not setting password-like text content type")
    #else
    field.textContentType = .password
    field.isSecureTextEntry = true
    #endif
}
field.placeholder = "Password"
Lukasz
  • 19,816
  • 17
  • 83
  • 139
4

Go to password settings in your simulator. Close AutoFill (if it's already closed open and close). Tap the Security Recommendation and close Detect Compromised Passwords. You are good to go..

emrcftci
  • 3,355
  • 3
  • 21
  • 35
4

You can disable password autofill on the simulator using this:

Not sure if all three files are needed, but this is what the switch in the Settings app changes.

plutil -replace restrictedBool.allowPasswordAutoFill.value -bool NO ~/Library/Developer/CoreSimulator/Devices/$SIMULATOR_ID/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles/Library/ConfigurationProfiles/UserSettings.plist
plutil -replace restrictedBool.allowPasswordAutoFill.value -bool NO ~/Library/Developer/CoreSimulator/Devices/$SIMULATOR_ID/data/Library/UserConfigurationProfiles/EffectiveUserSettings.plist
plutil -replace restrictedBool.allowPasswordAutoFill.value -bool NO ~/Library/Developer/CoreSimulator/Devices/$SIMULATOR_ID/data/Library/UserConfigurationProfiles/PublicInfo/PublicEffectiveUserSettings.plist

You can get SIMULATOR_ID from xcrun simctl list

Only tested this on iOS 16.4

Jonathan.
  • 53,997
  • 54
  • 186
  • 290
3

Although you can change "Autofill Passwords" manually in the simulator, this didn't work for me with automated UI tests on the build server that are reset on every run and thus is default On. Also, one of our libraries doesn't have a x86_64 slice, so it can't run on the iOS13.x simulator (arm64-simulator support came in iOS14).

Instead I found out that you can control Settings.app through XCUITest, so the first part of my test disables the "Autofill Passwords" and then runs my own test.

Note the use of both Settings.app and Springboard, since the passcode dialogs belongs to Springboard.

let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
    
settingsApp.launch()
settingsApp.tables.staticTexts["PASSWORDS"].tap()
    
let passcodeInput = springboard.secureTextFields["Passcode field"]
passcodeInput.tap()
passcodeInput.typeText("abc\r") // it accepts anything in simulator
settingsApp.tables.cells["PasswordOptionsCell"].buttons["chevron"].tap()
settingsApp.switches["AutoFill Passwords"].tap()
    
// launch my own app and start UI test
let app = XCUIApplication()
app.launch()

I did try to test if switch is On using .isSelected and only change it then, but .isSelected seems broken in XCUIElement for switches.

SharkBait
  • 71
  • 1
1

I just improved @SharkBait code adding wait and supporting multiples calls. Thanks!

 private func disableAutoFillPasswords() throws {
        let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
        let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
            
        settingsApp.launch()
        
        let passRow = settingsApp.tables.staticTexts["PASSWORDS"]
        var exists = passRow.waitForExistence(timeout: TimeInterval(5))
        if exists {
            passRow.tap()
        }
        
        let passcodeInput = springboard.secureTextFields["Passcode field"]
        exists = passcodeInput.waitForExistence(timeout: TimeInterval(5))
        XCTAssertTrue(exists, "")
        passcodeInput.tap()
        passcodeInput.typeText("abc\r")
        let cell = settingsApp.tables.cells["PasswordOptionsCell"].buttons["chevron"]
        exists = cell.waitForExistence(timeout: TimeInterval(5))
        XCTAssertTrue(exists, "Switcher exists")
        cell.tap()
        let switche = settingsApp.switches["AutoFill Passwords"]
        exists = switche.waitForExistence(timeout: TimeInterval(5))
        XCTAssertTrue(exists, "Switcher exists")
        let enabledState = switche.value as? String
        if enabledState == "1" {
            settingsApp.switches["AutoFill Passwords"].tap()
        }
    }
Diego Renau
  • 109
  • 3
0

Thanks @SharkBait for your solution, it really helps setting "Autofill Passwords" programmatically before running my ui automation.

Hopefully I completed the last piece about the mentioning ".isSelected" part, which I assume the purpose was for knowing toggle status earlier before tapping the "Autofill Passwords" setting.

Here is what I did :

//      turn the toggle to OFF only when it's ON

        let value = settingsApp.switches["AutoFill Passwords"].value as? String
        if value == "1" {
            settingsApp.switches["AutoFill Passwords"].tap()
        }

yongq
  • 1
-2

It's an iOS 14 bug that appears only when using the simulator.

The way to fix it is to install iOS 13.7:
With Xcode open click Preferences then Components.
Pick, download and install the iOS 13.7 operating system on your simulator.

Then run your app again. You can check your iOS version at the top label on the simulator. It should show the correct one.

James Risner
  • 5,451
  • 11
  • 25
  • 47
  • 2
    The bug was originally raised against iOS12, so I don't think it's iOS14 only. It may have started happening more frequently since iOS14 though, given the increase in activity here. – Estel Dec 07 '20 at 19:09
  • It works for me in iOS 13.7 without any issue. – marcinbogiel Dec 08 '20 at 10:17
  • Not specifically iOS 14 as @Estel said, however it is working for me on iOS 13.7 so cheers for that! – LukeLucas Dec 18 '20 at 14:28