-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[UI Tests] Run disableAutoFillPasswords once before all the UI Tests. #21148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
6da5d28
937cae8
798de02
af49f74
fb8d77d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import XCTest | ||
|
|
||
| class TestObserver: NSObject, XCTestObservation { | ||
| override init() { | ||
| super.init() | ||
| XCTestObservationCenter.shared.addTestObserver(self) | ||
| } | ||
|
|
||
| func testBundleWillStart(_ testBundle: Bundle) { | ||
| // Code added here will run only once before all the tests | ||
| executeWithRetries(disableAutoFillPasswords) | ||
| } | ||
|
|
||
| func testBundleDidFinish(_ testBundle: Bundle) { | ||
| XCTestObservationCenter.shared.removeTestObserver(self) | ||
| } | ||
|
|
||
| func executeWithRetries(_ operation: () -> Bool) { | ||
| var retryCount = 3 | ||
|
|
||
| while !operation() && retryCount > 0 { | ||
| retryCount -= 1 | ||
| } | ||
| } | ||
|
|
||
| func disableAutoFillPasswords() -> Bool { | ||
| let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences") | ||
| // Terminating Settings in case of a retry. | ||
| settings.terminate() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed in a retry case if something goes wrong in the first execution and also to make our lives easier when running multiple times locally. =] I added a comment in |
||
| settings.activate() | ||
|
|
||
| let passwordsMenuItem = settings.staticTexts["Passwords"] | ||
| passwordsMenuItem.waitForIsHittable() | ||
| passwordsMenuItem.tap() | ||
|
|
||
| let enterPasscodeScreen = XCUIApplication(bundleIdentifier: "com.apple.springboard") | ||
| let passwordField = enterPasscodeScreen.secureTextFields["Passcode field"] | ||
| passwordField.waitForIsHittable() | ||
| passwordField.typeText(" \r") | ||
|
|
||
| let passwordOptions = settings.staticTexts["Password Options"] | ||
| passwordOptions.waitForIsHittable() | ||
| passwordOptions.tap() | ||
|
|
||
| let autoFillPasswordsSwitch = settings.switches["AutoFill Passwords"] | ||
| autoFillPasswordsSwitch.waitForIsHittable() | ||
|
|
||
| if autoFillPasswordsSwitch.value as? String == "1" { | ||
| autoFillPasswordsSwitch.tap() | ||
| } | ||
|
|
||
| settings.terminate() | ||
| return true | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retrying to be on the safer side as all the tests would fail in case this is not disabled. I have seen it happening a couple times in a week.
I tried to make it reusable as we might need to change other setting in the future.