From dbe3796a9db643dff5065d6954e559c3be02d228 Mon Sep 17 00:00:00 2001 From: cloud9team <8thpharoahgold@gmail.com> Date: Mon, 9 Mar 2020 10:16:42 -0400 Subject: [PATCH 1/3] reworked startup, changed order of checks. Updated isStartup function to not clear caution sign before part8main. --- RealDeviceMap-UIControl/Misc.swift | 25 +-- .../RealDeviceMap_UIControlUITests.swift | 152 +++++++----------- 2 files changed, 78 insertions(+), 99 deletions(-) diff --git a/RealDeviceMap-UIControl/Misc.swift b/RealDeviceMap-UIControl/Misc.swift index 956d4c49..487adcbb 100644 --- a/RealDeviceMap-UIControl/Misc.swift +++ b/RealDeviceMap-UIControl/Misc.swift @@ -160,7 +160,7 @@ extension XCTestCase { } func checkHasWarning(screenshot: XCUIScreenshot?=nil) -> Bool { - Log.debug("Checking for the warning pop-up") + Log.debug("Checking for the red warning") let screenshotComp = screenshot ?? getScreenshot() if screenshotComp.rgbAtLocation( pos: deviceConfig.compareWarningL, @@ -170,6 +170,7 @@ extension XCTestCase { pos: deviceConfig.compareWarningR, min: (red: 0.03, green: 0.07, blue: 0.10), max: (red: 0.07, green: 0.11, blue: 0.14)) { + Log.debug("Look like you have been warned...") return true } else { return false @@ -299,8 +300,8 @@ extension XCTestCase { } - func isStartup(screenshot: XCUIScreenshot?=nil) -> Bool { - + func isStartup(click: Int = 0, screenshot: XCUIScreenshot?=nil) -> Bool { + let tapMe = click let screenshotComp = screenshot ?? XCUIScreen.main.screenshot() if screenshotComp.rgbAtLocation( @@ -312,8 +313,10 @@ extension XCTestCase { min: (red: 0.28, green: 0.79, blue: 0.62), max: (red: 0.33, green: 0.85, blue: 0.68) ) { - Log.startup("Should be clearing Caution Sign new startup prompt") - deviceConfig.startupNewButton.toXCUICoordinate(app: app).tap() + if tapMe == 1 { + Log.startup("Clearing Caution Sign prompt") + deviceConfig.startupNewButton.toXCUICoordinate(app: app).tap() + } return true } else if screenshotComp.rgbAtLocation( pos: deviceConfig.startupOldOkButton, @@ -324,8 +327,10 @@ extension XCTestCase { min: (red: 0.15, green: 0.41, blue: 0.45), max: (red: 0.19, green: 0.46, blue: 0.49) ) { - Log.startup("Should be Clearing the 2 line long, old style startup prompt") - deviceConfig.startupOldOkButton.toXCUICoordinate(app: app).tap() + if tapMe == 1 { + Log.startup("Clearing 2 line caution prompt") + deviceConfig.startupOldOkButton.toXCUICoordinate(app: app).tap() + } return true } else if screenshotComp.rgbAtLocation( pos: deviceConfig.startupOldOkButton, @@ -336,8 +341,10 @@ extension XCTestCase { min: (red: 0.99, green: 0.99, blue: 0.99), max: (red: 1.01, green: 1.01, blue: 1.01) ) { - Log.startup("Should be clearing the 3 line long, old school style prompt") - deviceConfig.startupOldOkButton.toXCUICoordinate(app: app).tap() + if tapMe == 1 { + Log.startup("Clearing 3 line prompt") + deviceConfig.startupOldOkButton.toXCUICoordinate(app: app).tap() + } return true } diff --git a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift index b3b48c62..bffc9477 100644 --- a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift +++ b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift @@ -328,7 +328,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { func part1LoginSetup() { - if shouldExit || !config.enableAccountManager { + if shouldExit { //<-- can still check for tos/startup state if no account manager return } @@ -341,21 +341,60 @@ class RealDeviceMap_UIControlUITests: XCTestCase { while !loaded { let screenshotComp = getScreenshot() if screenshotComp.rgbAtLocation( - pos: self.deviceConfig.startup, - min: (red: 0.0, green: 0.75, blue: 0.55), - max: (red: 1.0, green: 0.90, blue: 0.70)) { - Log.info("Tried to log in but already logged in.") - needsLogout = true - isLoggedIn = true - newLogIn = false - return - } else if screenshotComp.rgbAtLocation( + pos: self.deviceConfig.ageVerification, + min: (0.15, 0.33, 0.17), + max: (0.25, 0.43, 0.27)) { + Log.debug("App is in age verification.") + + print("[STATUS] Age verification") + //Open the year select + deviceConfig.ageVerificationYear.toXCUICoordinate(app: app).tap() + sleep(1 * config.delayMultiplier) + //Slide + deviceConfig.ageVerificationDragStart.toXCUICoordinate(app: app).press( + forDuration: 0.1, + thenDragTo: deviceConfig.ageVerificationDragEnd.toXCUICoordinate(app: app) + ) + sleep(1 * config.delayMultiplier) + //Tap to select + deviceConfig.ageVerificationDragStart.toXCUICoordinate(app: app).tap() + sleep(1 * config.delayMultiplier) + //Submit + deviceConfig.ageVerification.toXCUICoordinate(app: app).tap() + sleep(1 * config.delayMultiplier) + + + sleep(1 * config.delayMultiplier) + deviceConfig.loginNewPlayer.toXCUICoordinate(app: app).tap() + sleep(1 * config.delayMultiplier) + deviceConfig.loginPTC.toXCUICoordinate(app: app).tap() + } + + if screenshotComp.rgbAtLocation( pos: self.deviceConfig.startupLoggedOut, min: (0.95, 0.75, 0.0), max: (1.00, 0.85, 0.1)) { Log.debug("App Started in login screen.") loaded = true - } else if acceptTOS() { + return + } + sleep(2) + if unableAuth() { + Log.debug("Unable to authenticate.") + deviceConfig.unableAuthButton.toXCUICoordinate(app: app).tap() + sleep(2 * config.delayMultiplier) + shouldExit = true + return + } else if failedLogin() { + Log.error("Account \(username!) failed to log in. Getting a new account") + deviceConfig.loginBannedSwitchAccount.toXCUICoordinate(app: app).tap() + sleep(2 * config.delayMultiplier) + username = nil + shouldExit = true + return + } + sleep(5) + if acceptTOS() { Log.debug("Accepting Terms") deviceConfig.loginTerms.toXCUICoordinate(app: app).tap() sleep(2 * config.delayMultiplier) @@ -371,19 +410,6 @@ class RealDeviceMap_UIControlUITests: XCTestCase { Log.debug("Accepting Privacy Update.") deviceConfig.loginPrivacyUpdate.toXCUICoordinate(app: app).tap() sleep(2 * config.delayMultiplier) - } else if unableAuth() { - Log.debug("Unable to authenticate.") - deviceConfig.unableAuthButton.toXCUICoordinate(app: app).tap() - sleep(2 * config.delayMultiplier) - shouldExit = true - return - } else if failedLogin() { - Log.error("Account \(username!) failed to log in. Getting a new account") - deviceConfig.loginBannedSwitchAccount.toXCUICoordinate(app: app).tap() - sleep(2 * config.delayMultiplier) - username = nil - shouldExit = true - return } count += 1 if count == 60 && !loaded { @@ -394,35 +420,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { sleep(1 * config.delayMultiplier) } - let screenshotComp = getScreenshot() - if screenshotComp.rgbAtLocation( - pos: self.deviceConfig.ageVerification, - min: (0.15, 0.33, 0.17), - max: (0.25, 0.43, 0.27)) { - Log.debug("App is in age verification.") - - print("[STATUS] Age verification") - //Open the year select - deviceConfig.ageVerificationYear.toXCUICoordinate(app: app).tap() - sleep(1 * config.delayMultiplier) - //Slide - deviceConfig.ageVerificationDragStart.toXCUICoordinate(app: app).press( - forDuration: 0.1, - thenDragTo: deviceConfig.ageVerificationDragEnd.toXCUICoordinate(app: app) - ) - sleep(1 * config.delayMultiplier) - //Tap to select - deviceConfig.ageVerificationDragStart.toXCUICoordinate(app: app).tap() - sleep(1 * config.delayMultiplier) - //Submit - deviceConfig.ageVerification.toXCUICoordinate(app: app).tap() - sleep(1 * config.delayMultiplier) - } - - sleep(1 * config.delayMultiplier) - deviceConfig.loginNewPlayer.toXCUICoordinate(app: app).tap() - sleep(1 * config.delayMultiplier) - deviceConfig.loginPTC.toXCUICoordinate(app: app).tap() + } } @@ -495,7 +493,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { blocking: true) { (_) in } app.launch() sleep(10 * config.delayMultiplier) - } else if acceptTOS() { + } else if acceptTOS() { //<-- terms check if account manager == true Log.debug("Accepting Terms") deviceConfig.loginTerms.toXCUICoordinate(app: app).tap() sleep(2 * config.delayMultiplier) @@ -565,7 +563,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { blocking: true) { (_) in } shouldExit = true return - } else if isStartup() || isTutorial() { + } else if isStartup() || isTutorial() { //<-- dont click, needed to complete startup in part8main loggedIn = true isLoggedIn = true Log.info("Logged in as \(username!)") @@ -597,7 +595,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { sleep(4 * config.delayMultiplier) if !isTutorial() { - Log.info("Tutorial already done. Restarting...") + Log.info("Tutorial Completed...") self.postRequest( url: self.backendControlerURL, data: ["uuid": self.config.uuid, "username": self.username as Any, @@ -605,9 +603,6 @@ class RealDeviceMap_UIControlUITests: XCTestCase { blocking: true) { (_) in } newCreated = true newLogIn = false - app.launch() - sleep(1 * config.delayMultiplier) - return } @@ -1020,11 +1015,11 @@ class RealDeviceMap_UIControlUITests: XCTestCase { return } - isStarted = false + isStarted = false //<-- set to false at start of runloop // State vars var startupCount = 0 - var isStartupCompleted = false + var isStartupCompleted = false //<-- set to false var currentQuests = self.config.questFullCount var currentItems = self.config.itemFullCount @@ -1059,17 +1054,15 @@ class RealDeviceMap_UIControlUITests: XCTestCase { app.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0)).tap() } - if isStarted { + if isStarted { //<-- automatic kick to else at line 1833 if !isStartupCompleted { Log.debug("Performing Startup sequence") currentLocation = config.startupLocation - isStartup() - sleep(2 * config.delayMultiplier) - deviceConfig.closeNews.toXCUICoordinate(app: app).tap() + sleep(1 * config.delayMultiplier) hasWarning = self.checkHasWarning() - if hasWarning { + if hasWarning { //<-- rw happens before news on startup if self.firstWarningDate == nil && config.enableAccountManager { firstWarningDate = Date() postRequest(url: backendControlerURL, @@ -1081,28 +1074,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { deviceConfig.closeWarning.toXCUICoordinate(app: app).tap() sleep(1 * config.delayMultiplier) } - - if self.acceptTOS() { - Log.debug("Accepting Terms") - deviceConfig.loginTerms.toXCUICoordinate(app: app).tap() - sleep(2 * config.delayMultiplier) - } - if self.acceptTOSUpdate() { - Log.debug("Accepting Updated Terms.") - deviceConfig.loginTerms2.toXCUICoordinate(app: app).tap() - sleep(2 * config.delayMultiplier) - } - if self.acceptPrivacy() { - Log.debug("Accepting Privacy.") - deviceConfig.loginPrivacy.toXCUICoordinate(app: app).tap() - sleep(2 * config.delayMultiplier) - } - if self.acceptPrivacyUpdate() { - Log.debug("Accepting Privacy Update.") - deviceConfig.loginPrivacyUpdate.toXCUICoordinate(app: app).tap() - sleep(2 * config.delayMultiplier) - } - + deviceConfig.closeNews.toXCUICoordinate(app: app).tap() //<-- was closing rw self.freeScreen() deviceConfig.closeNews.toXCUICoordinate(app: app).tap() sleep(1 * config.delayMultiplier) @@ -1882,9 +1854,9 @@ class RealDeviceMap_UIControlUITests: XCTestCase { sleep(2 * config.delayMultiplier) shouldExit = true return - } else if isStartup() { + } else if isStartup(click: 1) { //<-- caution sign must be present here to complete startup Log.info("App Started") - isStarted = true + isStarted = true // <-- only place isStarted set to true sleep(1 * config.delayMultiplier) } else { Log.debug("App still in Startup") From 277a2dc4a12d4bbf706bca614e90cdadfa73dc13 Mon Sep 17 00:00:00 2001 From: cloud9team <8thpharoahgold@gmail.com> Date: Mon, 9 Mar 2020 14:22:33 -0400 Subject: [PATCH 2/3] Cleaner handling of variable inside of isStartup function. Changed to bool and removed redeclaration of variable inside function. Also lint fixes --- RealDeviceMap-UIControl/Misc.swift | 33 +++++++++---------- .../RealDeviceMap_UIControlUITests.swift | 9 ++--- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/RealDeviceMap-UIControl/Misc.swift b/RealDeviceMap-UIControl/Misc.swift index 487adcbb..7a1b11b6 100644 --- a/RealDeviceMap-UIControl/Misc.swift +++ b/RealDeviceMap-UIControl/Misc.swift @@ -300,8 +300,7 @@ extension XCTestCase { } - func isStartup(click: Int = 0, screenshot: XCUIScreenshot?=nil) -> Bool { - let tapMe = click + func isStartup(click: Bool=false, screenshot: XCUIScreenshot?=nil) -> Bool { let screenshotComp = screenshot ?? XCUIScreen.main.screenshot() if screenshotComp.rgbAtLocation( @@ -313,7 +312,7 @@ extension XCTestCase { min: (red: 0.28, green: 0.79, blue: 0.62), max: (red: 0.33, green: 0.85, blue: 0.68) ) { - if tapMe == 1 { + if click { Log.startup("Clearing Caution Sign prompt") deviceConfig.startupNewButton.toXCUICoordinate(app: app).tap() } @@ -327,7 +326,7 @@ extension XCTestCase { min: (red: 0.15, green: 0.41, blue: 0.45), max: (red: 0.19, green: 0.46, blue: 0.49) ) { - if tapMe == 1 { + if click { Log.startup("Clearing 2 line caution prompt") deviceConfig.startupOldOkButton.toXCUICoordinate(app: app).tap() } @@ -341,7 +340,7 @@ extension XCTestCase { min: (red: 0.99, green: 0.99, blue: 0.99), max: (red: 1.01, green: 1.01, blue: 1.01) ) { - if tapMe == 1 { + if click { Log.startup("Clearing 3 line prompt") deviceConfig.startupOldOkButton.toXCUICoordinate(app: app).tap() } @@ -353,9 +352,9 @@ extension XCTestCase { /* // Planned detection for partially completed reloads, but doesn't seem worth it now :shrug: func failedTutorialMethod1(screenshot: XCUIScreenshot?=nil) -> Bool { - + let screenshotComp = screenshot ?? getScreenshot() - + if screenshotComp.rgbAtLocation( pos: deviceConfig.compareTutorialL, min: (red: 0.3, green: 0.5, blue: 0.6), @@ -368,11 +367,11 @@ extension XCTestCase { } else { return false } - + } - + func failedTutorialMethod2(screenshot: XCUIScreenshot?=nil) -> Bool{ - + //let screenshotComp = screenshot ?? getScreenshot() /* if screenshotComp.rgbAtLocation( @@ -383,13 +382,13 @@ extension XCTestCase { } */ return true - + } - + func failedTutorialMethod3(screenshot: XCUIScreenshot?=nil) -> Bool{ - + //let screenshotComp = screenshot ?? getScreenshot() - + /*if screenshotComp.rgbAtLocation( pos: deviceConfig.tutorialProfessorCheck, min: (red: 0.85, green: 0.9, blue: 0.00), @@ -398,11 +397,11 @@ extension XCTestCase { }*/ return true } - + func failedTutorialMethod4(screenshot: XCUIScreenshot?=nil) -> Bool { - + //let screenshotComp = screenshot ?? getScreenshot() - + /*if screenshotComp.rgbAtLocation( pos: deviceConfig.tutorialProfessorCheck, min: (red: 0.85, green: 0.9, blue: 0.00), diff --git a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift index bffc9477..c12bfc6e 100644 --- a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift +++ b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift @@ -363,13 +363,12 @@ class RealDeviceMap_UIControlUITests: XCTestCase { deviceConfig.ageVerification.toXCUICoordinate(app: app).tap() sleep(1 * config.delayMultiplier) - sleep(1 * config.delayMultiplier) deviceConfig.loginNewPlayer.toXCUICoordinate(app: app).tap() sleep(1 * config.delayMultiplier) deviceConfig.loginPTC.toXCUICoordinate(app: app).tap() } - + if screenshotComp.rgbAtLocation( pos: self.deviceConfig.startupLoggedOut, min: (0.95, 0.75, 0.0), @@ -420,7 +419,6 @@ class RealDeviceMap_UIControlUITests: XCTestCase { sleep(1 * config.delayMultiplier) } - } } @@ -1058,7 +1056,6 @@ class RealDeviceMap_UIControlUITests: XCTestCase { if !isStartupCompleted { Log.debug("Performing Startup sequence") currentLocation = config.startupLocation - sleep(1 * config.delayMultiplier) hasWarning = self.checkHasWarning() @@ -1854,7 +1851,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { sleep(2 * config.delayMultiplier) shouldExit = true return - } else if isStartup(click: 1) { //<-- caution sign must be present here to complete startup + } else if isStartup(click: true) { //<-- caution sign must be present here to complete startup Log.info("App Started") isStarted = true // <-- only place isStarted set to true sleep(1 * config.delayMultiplier) @@ -1869,7 +1866,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { } } } - + } func zoom(out: Bool, app: XCUIApplication, coordStartup: XCUICoordinate) { From b0b3c74b746d3cfe52632b5bd8e21dbb1d7724e2 Mon Sep 17 00:00:00 2001 From: cloud9team <8thpharoahgold@gmail.com> Date: Mon, 9 Mar 2020 14:28:59 -0400 Subject: [PATCH 3/3] lint fixes --- .../RealDeviceMap_UIControlUITests.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift index c12bfc6e..1f0cce2d 100644 --- a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift +++ b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift @@ -345,7 +345,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { min: (0.15, 0.33, 0.17), max: (0.25, 0.43, 0.27)) { Log.debug("App is in age verification.") - + print("[STATUS] Age verification") //Open the year select deviceConfig.ageVerificationYear.toXCUICoordinate(app: app).tap() @@ -362,7 +362,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { //Submit deviceConfig.ageVerification.toXCUICoordinate(app: app).tap() sleep(1 * config.delayMultiplier) - + sleep(1 * config.delayMultiplier) deviceConfig.loginNewPlayer.toXCUICoordinate(app: app).tap() sleep(1 * config.delayMultiplier) @@ -1056,7 +1056,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { if !isStartupCompleted { Log.debug("Performing Startup sequence") currentLocation = config.startupLocation - + sleep(1 * config.delayMultiplier) hasWarning = self.checkHasWarning() if hasWarning { //<-- rw happens before news on startup @@ -1866,7 +1866,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { } } } - + } func zoom(out: Bool, app: XCUIApplication, coordStartup: XCUICoordinate) {