Strong password autofill appears in iOS simulator
Asked Answered
L

10

52

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?

Lefthand answered 27/3, 2019 at 13:39 Comment(4)
This was filed as rdr://49643422 / Feedback FB5665786Lefthand
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.Lefthand
This was only happening intermittently before, but in iOS 16 it now happens every time for me.Hardball
In iOS 16 it's become a full production issue for end users. If AutoFill is turned off as a solution the users lose password manager functionality. No viable work around I can see.Shedevil
G
33

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

Gaselier answered 18/12, 2020 at 21:18 Comment(0)
S
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.

Story answered 8/12, 2020 at 18:15 Comment(0)
D
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"
Drain answered 17/11, 2020 at 9:22 Comment(1)
This doesn't work for me. Using simulator 14.2 - iPhone 12 Pro MaxFreeness
T
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..

Trainer answered 5/7, 2022 at 22:47 Comment(0)
G
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

Gangue answered 25/4, 2023 at 21:24 Comment(1)
This destroyed my simulator. Make sure you don't run this while the simulator is running.Prostitution
C
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.

Churchlike answered 29/9, 2022 at 8:5 Comment(0)
H
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()
        }
    }
Hunter answered 10/7, 2023 at 18:16 Comment(0)
S
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()
        }

Senlac answered 2/7, 2023 at 22:31 Comment(0)
T
0

Managed to fix it with the following commands:

script {

// retrieve the iOS simulator id the tests will be run on
def SIMULATOR_ID = sh (script: "xctrace list devices | grep 'iPhone 14' | grep '17.0.1' | awk -F '[()]' '{print \$4}'", returnStdout: true).trim()

// disable AutoFillPasswords
sh "plutil -replace AutoFillPasswords -bool false '../Library/Developer/CoreSimulator/Devices/$SIMULATOR_ID/data/Library/Preferences/com.apple.WebUI.plist'"

// restart (shutdown if needed and boot) the iOS simulator for the changes to take action
try {
    sh "xcrun simctl shutdown $SIMULATOR_ID"
} catch (err) {
    echo "Unable to shutdown device as it is already shutdown. Error: ${err.getMessage()}"
}
sh "xcrun simctl boot $SIMULATOR_ID"
}
Thirsty answered 8/12, 2023 at 0:55 Comment(0)
D
-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.

Drape answered 7/12, 2020 at 15:42 Comment(4)
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.Lefthand
It works for me in iOS 13.7 without any issue.Drape
Not specifically iOS 14 as @Lefthand said, however it is working for me on iOS 13.7 so cheers for that!Jumpy
Happening for me with iOS 16.4 on an iPhone 14 Pro simNahamas

© 2022 - 2024 — McMap. All rights reserved.