From 4a83184e812175b147e99e14acba24cd5544b6c6 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 29 May 2023 14:48:48 +1000 Subject: [PATCH] Cover more user paths where UI tests ask to save password --- .../Login/LoginUsernamePasswordScreen.swift | 2 ++ .../Screens/Login/Unified/PasswordScreen.swift | 9 +++------ .../Screens/Login/Unified/PrologueScreen.swift | 2 ++ .../XCUIApplication+SavePassword.swift | 16 ++++++++++++++++ WordPress/WordPress.xcodeproj/project.pbxproj | 4 ++++ 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 WordPress/UITestsFoundation/XCUIApplication+SavePassword.swift diff --git a/WordPress/UITestsFoundation/Screens/Login/LoginUsernamePasswordScreen.swift b/WordPress/UITestsFoundation/Screens/Login/LoginUsernamePasswordScreen.swift index 76155c39e87d..cf09c4119dbb 100644 --- a/WordPress/UITestsFoundation/Screens/Login/LoginUsernamePasswordScreen.swift +++ b/WordPress/UITestsFoundation/Screens/Login/LoginUsernamePasswordScreen.swift @@ -87,6 +87,8 @@ public class LoginUsernamePasswordScreen: ScreenObject { passwordTextField.typeText(password) } nextButton.tap() + + app.dismissSavePasswordPrompt() } private func dismissQuickStartPromptIfNeeded() throws { diff --git a/WordPress/UITestsFoundation/Screens/Login/Unified/PasswordScreen.swift b/WordPress/UITestsFoundation/Screens/Login/Unified/PasswordScreen.swift index ee20a2589ac2..a33b6f1a4f8b 100644 --- a/WordPress/UITestsFoundation/Screens/Login/Unified/PasswordScreen.swift +++ b/WordPress/UITestsFoundation/Screens/Login/Unified/PasswordScreen.swift @@ -15,6 +15,8 @@ public class PasswordScreen: ScreenObject { public func proceedWithValidPassword() throws -> LoginEpilogueScreen { try tryProceed(password: "pw") + app.dismissSavePasswordPrompt() + return try LoginEpilogueScreen() } @@ -48,12 +50,7 @@ public class PasswordScreen: ScreenObject { let continueButton = app.buttons["Continue Button"] continueButton.tap() - // The Simulator might ask to save the password which, of course, we don't want to do - if app.buttons["Save Password"].waitForExistence(timeout: 5) { - // There should be no need to wait for this button to exist since it's part of the same - // alert where "Save Password" is. - app.buttons["Not Now"].tap() - } + app.dismissSavePasswordPrompt() } public func verifyLoginError() -> PasswordScreen { diff --git a/WordPress/UITestsFoundation/Screens/Login/Unified/PrologueScreen.swift b/WordPress/UITestsFoundation/Screens/Login/Unified/PrologueScreen.swift index 81bfe6f284f4..09aaa5754d66 100644 --- a/WordPress/UITestsFoundation/Screens/Login/Unified/PrologueScreen.swift +++ b/WordPress/UITestsFoundation/Screens/Login/Unified/PrologueScreen.swift @@ -25,6 +25,8 @@ public class PrologueScreen: ScreenObject { public func selectContinue() throws -> GetStartedScreen { continueButton.tap() + app.dismissSavePasswordPrompt() + return try GetStartedScreen() } diff --git a/WordPress/UITestsFoundation/XCUIApplication+SavePassword.swift b/WordPress/UITestsFoundation/XCUIApplication+SavePassword.swift new file mode 100644 index 000000000000..8edf6e440b7b --- /dev/null +++ b/WordPress/UITestsFoundation/XCUIApplication+SavePassword.swift @@ -0,0 +1,16 @@ +import XCTest + +extension XCUIApplication { + + // Starting with iOS 16.4, the Simulator might ask to save the password with a modal sheet. + // This method encapsulates the logic to dimiss the prompt. + func dismissSavePasswordPrompt() { + XCTContext.runActivity(named: "Dismiss save password prompt if needed.") { _ in + guard buttons["Save Password"].waitForExistence(timeout: 5) else { return } + + // There should be no need to wait for this button to exist since it's part of the same + // alert where "Save Password" is. + buttons["Not Now"].tap() + } + } +} diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index e5aa4fe86688..97fb4d1dbb1d 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -806,6 +806,7 @@ 3F685B6A26D431FA001C6808 /* DomainSuggestionViewControllerWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FAF9CC426D03C7400268EA2 /* DomainSuggestionViewControllerWrapper.swift */; }; 3F6975FF242D941E001F1807 /* ReaderTabViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F6975FE242D941E001F1807 /* ReaderTabViewModel.swift */; }; 3F6A7E92251BC1DC005B6A61 /* RootViewCoordinator+WhatIsNew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F6A7E91251BC1DC005B6A61 /* RootViewCoordinator+WhatIsNew.swift */; }; + 3F6A8CE02A246357009DBC2B /* XCUIApplication+SavePassword.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F6A8CDF2A246357009DBC2B /* XCUIApplication+SavePassword.swift */; }; 3F6AD0562502A91400080F3B /* AnnouncementsCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F6AD0552502A91400080F3B /* AnnouncementsCache.swift */; }; 3F6BC04B25B2474C007369D3 /* FeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1D690151F828FF000200E30 /* FeatureFlag.swift */; }; 3F6BC05C25B24773007369D3 /* FeatureFlagOverrideStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A09B98238FE13B0022AE0D /* FeatureFlagOverrideStore.swift */; }; @@ -6472,6 +6473,7 @@ 3F662C4924DC9FAC00CAEA95 /* WhatIsNewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhatIsNewViewController.swift; sourceTree = ""; }; 3F6975FE242D941E001F1807 /* ReaderTabViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderTabViewModel.swift; sourceTree = ""; }; 3F6A7E91251BC1DC005B6A61 /* RootViewCoordinator+WhatIsNew.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RootViewCoordinator+WhatIsNew.swift"; sourceTree = ""; }; + 3F6A8CDF2A246357009DBC2B /* XCUIApplication+SavePassword.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIApplication+SavePassword.swift"; sourceTree = ""; }; 3F6AD0552502A91400080F3B /* AnnouncementsCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnnouncementsCache.swift; sourceTree = ""; }; 3F6DA04025646F96002AB88F /* HomeWidgetData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeWidgetData.swift; sourceTree = ""; }; 3F720C2028899DD900519938 /* JetpackBrandingVisibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackBrandingVisibility.swift; sourceTree = ""; }; @@ -11468,6 +11470,7 @@ 3FA640592670CCD40064401E /* UITestsFoundation.h */, 3F762E9426784B540088CD45 /* WireMock.swift */, 3F107B1829B6F7E0009B3658 /* XCTestCase+Utils.swift */, + 3F6A8CDF2A246357009DBC2B /* XCUIApplication+SavePassword.swift */, 3FB5C2B227059AC8007D0ECE /* XCUIElement+Scroll.swift */, 3F762E9A26784D2A0088CD45 /* XCUIElement+Utils.swift */, 3F762E9826784CC90088CD45 /* XCUIElementQuery+Utils.swift */, @@ -22626,6 +22629,7 @@ 3F2F855D26FAF227000FCDA5 /* LoginCheckMagicLinkScreen.swift in Sources */, EA78189427596B2F00554DFA /* ContactUsScreen.swift in Sources */, D82E087829EEB7AF0098F500 /* DomainsScreen.swift in Sources */, + 3F6A8CE02A246357009DBC2B /* XCUIApplication+SavePassword.swift in Sources */, 3F2F855626FAF227000FCDA5 /* LoginEmailScreen.swift in Sources */, FA9276AF2888557500C323BB /* SiteIntentScreen.swift in Sources */, 3FE39A3926F837E1006E2B3A /* ActivityLogScreen.swift in Sources */,