iOS模拟器中出现强密码自动填充

k2arahey  于 2023-05-02  发布在  iOS
关注(0)|答案(7)|浏览(177)

我们的UI测试套件显示了一些意外的行为,其中我们的创建密码屏幕间歇性地自动完成用户名和密码-这导致测试失败。
该过程类似于:

  • 点击第一个创建密码字段
  • 输入密码
  • 点击确认密码字段
  • 输入相同的密码

最后一步失败,因为两个字段中的密码都已自动完成。

每十到二十次测试执行中就会有一次发生这种情况。
我们的理解是,密码自动填充不应该在任何模拟器中看到,所以看到这一点非常令人困惑。有没有什么我们可以做的 * 额外 * 禁用自动填充,或以其他方式防止这种情况发生?

toiithl6

toiithl61#

进入模拟器的设置-〉密码-〉打开,然后关闭自动填充密码。

键入任何密码

sf6xfgos

sf6xfgos2#

有同样的问题。对我有用的是去模拟器的设置-〉密码-〉打开,然后关闭自动填充密码。

dxxyhpgq

dxxyhpgq3#

不确定是否从一开始就是这样,但设置isSecureTextEntry = true也足以触发该bug(至少在Xcode 12中是这样。2)的情况。
因此,对我有效的变通方法是:

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"
wvyml7n5

wvyml7n54#

进入模拟器中的密码设置。关闭自动填充(如果它已经关闭,打开并关闭)。点击安全建议并关闭检测受损密码。你可以走了.

3zwjbxry

3zwjbxry5#

虽然你可以在模拟器中手动更改“自动填充密码”,但这对我在构建服务器上的自动UI测试不起作用,这些测试在每次运行时都会重置,因此是默认的。此外,我们的一个库没有x86_64切片,所以它不能在iOS 13上运行。x模拟器(arm 64-模拟器支持来自iOS 14)。
相反,我发现你可以控制 www.example.com 通过XCUITest,所以我的测试的第一部分禁用了“自动填充密码”,然后运行我自己的测试。
请注意使用两个 www.example.com 和Springboard,因为密码对话框属于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()

我确实尝试使用.isSelected测试switch是否打开,然后才更改它,但.isSelected似乎在用于switch的XCUIElement中损坏。

dxxyhpgq

dxxyhpgq6#

您可以使用以下命令在模拟器上禁用密码自动填充:
不确定是否需要所有三个文件,但这是设置应用程序中的开关所改变的。

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

您可以从xcrun simctl list获取SIMULATOR_ID
只在iOS 16上测试过。4

eulz3vhy

eulz3vhy7#

这是iOS 14的一个bug,只有在使用模拟器时才会出现。
修复它的方法是安装iOS 13。七:
打开Xcode,点击Preferences,然后点击Components。
选择、下载并安装iOS 13。7操作系统在你的模拟器上。
然后再次运行您的应用。您可以在模拟器的顶部标签处检查您的iOS版本。它应该显示正确的一个。

相关问题