@@ -19,6 +19,14 @@ import XCTest
1919class DaysUntilBirthdayUITests_iOS : XCTestCase {
2020 private let signInStaticText =
2121 " “DaysUntilBirthday (iOS)” Wants to Use “google.com” to Sign In "
22+ private let passwordManagerPrompt =
23+ " Would you like to save this password to use with apps and websites? "
24+ private let signInDisclaimerHeaderText =
25+ " Sign in to Days Until Birthday "
26+ private let additionalAccessHeaderText = " Days Until Birthday wants additional access to your Google Account "
27+ private let appTrustWarningText = " Make sure you trust Days Until Birthday "
28+ private let chooseAnAccountHeaderText = " Choose an account "
29+ private let notNowText = " Not Now "
2230 private let timeout : TimeInterval = 5
2331
2432 private let sampleApp = XCUIApplication ( )
@@ -152,6 +160,22 @@ extension DaysUntilBirthdayUITests_iOS {
152160 . typeText ( Credential . password. rawValue)
153161 sampleApp. keyboards. element. buttons [ " return " ] . tap ( )
154162
163+ if sampleApp
164+ . staticTexts [ passwordManagerPrompt]
165+ . waitForExistence ( timeout: timeout) {
166+ guard sampleApp
167+ . buttons [ notNowText]
168+ . waitForExistence ( timeout: timeout) else {
169+ XCTFail ( " Failed to find \( notNowText) button " )
170+ return false
171+ }
172+ sampleApp. buttons [ notNowText] . tap ( )
173+ }
174+
175+ // Proceed through sign-in disclaimer and/or access request view(s) if needed
176+ handleSignInDisclaimerIfNeeded ( )
177+ handleAccessRequestIfNeeded ( )
178+
155179 return true
156180 }
157181
@@ -160,15 +184,13 @@ extension DaysUntilBirthdayUITests_iOS {
160184 /// This will check that there is a `Credential.email` in a list to select and
161185 /// sign in with.
162186 func useExistingSignIn( ) -> Bool {
163- guard sampleApp . staticTexts [ Credential . email . rawValue ] . exists else {
164- XCTFail ( " Email used for previous sign -in not in list " )
187+ guard findAndTapExistingSignedInEmail ( ) else {
188+ XCTFail ( " Failed to find signed -in account " )
165189 return false
166190 }
167- guard sampleApp. staticTexts [ Credential . email. rawValue] . isHittable else {
168- XCTFail ( " Email used for previous sign-in not tappable " )
169- return false
170- }
171- sampleApp. staticTexts [ Credential . email. rawValue] . tap ( )
191+
192+ handleSignInDisclaimerIfNeeded ( )
193+ handleAccessRequestIfNeeded ( )
172194
173195 return true
174196 }
@@ -196,17 +218,16 @@ extension DaysUntilBirthdayUITests_iOS {
196218 }
197219 springboardApp. buttons [ " Continue " ] . tap ( )
198220
199- guard sampleApp
200- . staticTexts [ " Days Until Birthday wants to access your Google Account " ]
201- . waitForExistence ( timeout: timeout) else {
202- XCTFail ( " Failed to find permission screen " )
203- return false
204- }
205- guard sampleApp. buttons [ " Allow " ] . waitForExistence ( timeout: timeout) else {
206- XCTFail ( " Failed to find 'Allow' button " )
207- return false
221+ if sampleApp
222+ . staticTexts [ chooseAnAccountHeaderText]
223+ . waitForExistence ( timeout: timeout) {
224+ guard findAndTapExistingSignedInEmail ( ) else {
225+ XCTFail ( " Failed to find signed-in account " )
226+ return false
227+ }
208228 }
209- sampleApp. buttons [ " Allow " ] . tap ( )
229+
230+ handleAccessRequestIfNeeded ( )
210231 }
211232
212233 guard sampleApp. staticTexts [ " Days Until Birthday " ]
@@ -240,4 +261,44 @@ extension DaysUntilBirthdayUITests_iOS {
240261
241262 return true
242263 }
264+
265+ /// Proceeds through the view with header "Days Until Birthday wants additional access to your Google Account" if needed.
266+ func handleAccessRequestIfNeeded( ) {
267+ let currentlyShowingAdditionalAccessRequest = sampleApp. staticTexts [ additionalAccessHeaderText]
268+ . waitForExistence ( timeout: timeout) && sampleApp. staticTexts [ appTrustWarningText]
269+ . waitForExistence ( timeout: timeout) &&
270+ sampleApp. buttons [ " Continue " ]
271+ . waitForExistence ( timeout: timeout)
272+
273+ if currentlyShowingAdditionalAccessRequest {
274+ sampleApp. buttons [ " Continue " ] . tap ( )
275+ }
276+ }
277+
278+ /// Proceeds through the sign-in disclaimer view if needed.
279+ func handleSignInDisclaimerIfNeeded( ) {
280+ let currentlyShowingSignInDisclaimer = sampleApp. staticTexts [ signInDisclaimerHeaderText]
281+ . waitForExistence ( timeout: timeout) &&
282+ sampleApp. buttons [ " Continue " ]
283+ . waitForExistence ( timeout: timeout)
284+
285+ if currentlyShowingSignInDisclaimer {
286+ sampleApp. buttons [ " Continue " ] . tap ( )
287+ }
288+ }
289+
290+ /// This method looks for an account in the current view that reflects an already-signed-in state, and taps it.
291+ /// - returns: true if the signed-in account was found and tapped, otherwise returns false.
292+ func findAndTapExistingSignedInEmail( ) -> Bool {
293+ guard sampleApp. staticTexts [ Credential . email. rawValue] . exists else {
294+ XCTFail ( " Email used for previous sign-in was not found. " )
295+ return false
296+ }
297+ guard sampleApp. staticTexts [ Credential . email. rawValue] . isHittable else {
298+ XCTFail ( " Email used for previous sign-in not tappable. " )
299+ return false
300+ }
301+ sampleApp. staticTexts [ Credential . email. rawValue] . tap ( )
302+ return true
303+ }
243304}
0 commit comments