diff --git a/PrivateHeaders/XCTest/XCUIApplication.h b/PrivateHeaders/XCTest/XCUIApplication.h index 34bf69032..e092f26db 100644 --- a/PrivateHeaders/XCTest/XCUIApplication.h +++ b/PrivateHeaders/XCTest/XCUIApplication.h @@ -39,7 +39,6 @@ @property(readonly) id/*XCAccessibilityElement*/ accessibilityElement; + (instancetype)applicationWithPID:(pid_t)processID; -/*! DO NOT USE DIRECTLY! Please use fb_activate instead */ - (void)activate; - (void)dismissKeyboard; diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index b0c874c62..251fb7ad9 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -147,7 +147,7 @@ - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)err return NO; } [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:MAX(duration, .0)]]; - [self fb_activate]; + [self activate]; return YES; } diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index f6df67a80..f5abdc55a 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -143,21 +143,21 @@ + (NSArray *)routes if (nil != capabilities[FB_CAP_FORCE_APP_LAUNCH]) { forceAppLaunch = [capabilities[FB_CAP_FORCE_APP_LAUNCH] boolValue]; } - NSUInteger appState = app.state; + XCUIApplicationState appState = app.state; BOOL isAppRunning = appState >= XCUIApplicationStateRunningBackground; if (!isAppRunning || (isAppRunning && forceAppLaunch)) { app.fb_shouldWaitForQuiescence = nil == capabilities[FB_CAP_SHOULD_WAIT_FOR_QUIESCENCE] || [capabilities[FB_CAP_SHOULD_WAIT_FOR_QUIESCENCE] boolValue]; app.launchArguments = (NSArray *)capabilities[FB_CAP_ARGUMENTS] ?: @[]; app.launchEnvironment = (NSDictionary *)capabilities[FB_CAP_ENVIRNOMENT] ?: @{}; - [app fb_launch]; + [app launch]; if (![app running]) { NSString *errorMsg = [NSString stringWithFormat:@"Cannot launch %@ application. Make sure the correct bundle identifier has been provided in capabilities and check the device log for possible crash report occurrences", bundleID]; return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:errorMsg traceback:nil]); } - } else if (appState < XCUIApplicationStateRunningForeground && !forceAppLaunch) { - [app fb_activate]; + } else if (appState == XCUIApplicationStateRunningBackground && !forceAppLaunch) { + [app activate]; } } diff --git a/WebDriverAgentLib/Routing/FBSession.h b/WebDriverAgentLib/Routing/FBSession.h index eabdec9d1..9b73d4d16 100644 --- a/WebDriverAgentLib/Routing/FBSession.h +++ b/WebDriverAgentLib/Routing/FBSession.h @@ -83,7 +83,6 @@ NS_ASSUME_NONNULL_BEGIN @param arguments The optional array of application command line arguments. The arguments are going to be applied if the application was not running before. @param environment The optional dictionary of environment variables for the application, which is going to be executed. The environment variables are going to be applied if the application was not running before. @return The application instance - @throws FBApplicationMethodNotSupportedException if the method is not supported with the current XCTest SDK */ - (XCUIApplication *)launchApplicationWithBundleId:(NSString *)bundleIdentifier shouldWaitForQuiescence:(nullable NSNumber *)shouldWaitForQuiescence @@ -96,7 +95,6 @@ NS_ASSUME_NONNULL_BEGIN @param bundleIdentifier Valid bundle identifier of the application to be activated @return The application instance - @throws FBApplicationMethodNotSupportedException if the method is not supported with the current XCTest SDK */ - (XCUIApplication *)activateApplicationWithBundleId:(NSString *)bundleIdentifier; diff --git a/WebDriverAgentLib/Routing/FBSession.m b/WebDriverAgentLib/Routing/FBSession.m index af6b8b221..b0b50c6a2 100644 --- a/WebDriverAgentLib/Routing/FBSession.m +++ b/WebDriverAgentLib/Routing/FBSession.m @@ -185,11 +185,15 @@ - (XCUIApplication *)launchApplicationWithBundleId:(NSString *)bundleIdentifier if (!app.running) { app.launchArguments = arguments ?: @[]; app.launchEnvironment = environment ?: @{}; - [app fb_launch]; + [app launch]; } else { - [app fb_activate]; + [app activate]; } if ([app fb_isSameAppAs:self.testedApplication]) { + if (self.testedApplication.processID != app.processID) { + // The app under test has been restarted + self.testedApplication = app; + } self.isTestedApplicationExpectedToRun = YES; } return app; @@ -198,7 +202,7 @@ - (XCUIApplication *)launchApplicationWithBundleId:(NSString *)bundleIdentifier - (XCUIApplication *)activateApplicationWithBundleId:(NSString *)bundleIdentifier { XCUIApplication *app = [self makeApplicationWithBundleId:bundleIdentifier]; - [app fb_activate]; + [app activate]; return app; } @@ -209,7 +213,7 @@ - (BOOL)terminateApplicationWithBundleId:(NSString *)bundleIdentifier self.isTestedApplicationExpectedToRun = NO; } if (app.running) { - [app fb_terminate]; + [app terminate]; return YES; } return NO; diff --git a/WebDriverAgentLib/Utilities/FBXCodeCompatibility.h b/WebDriverAgentLib/Utilities/FBXCodeCompatibility.h index ae2bf7d93..0a7dd9a0c 100644 --- a/WebDriverAgentLib/Utilities/FBXCodeCompatibility.h +++ b/WebDriverAgentLib/Utilities/FBXCodeCompatibility.h @@ -28,35 +28,6 @@ NSInteger FBTestmanagerdVersion(void); NS_ASSUME_NONNULL_BEGIN -/** - The exception happends if one tries to call application method, - which is not supported in the current iOS version - */ -extern NSString *const FBApplicationMethodNotSupportedException; - -@interface XCUIApplication (FBCompatibility) - -/** - Activate the application by restoring it from the background. - Nothing will happen if the application is already in foreground. - This method is only supported since Xcode9. - - @throws FBTimeoutException if the app is still not active after the timeout - */ -- (void)fb_activate; - -/** - Terminate the application and wait until it disappears from the list of active apps - */ -- (void)fb_terminate; - -/** - Laucnhes the app and waits until it exists on the screen - */ -- (void)fb_launch; - -@end - @interface XCUIElementQuery (FBCompatibility) /* Performs short-circuit UI tree traversion in iOS 11+ to get the first element matched by the query. Equals to nil if no matching elements are found */ diff --git a/WebDriverAgentLib/Utilities/FBXCodeCompatibility.m b/WebDriverAgentLib/Utilities/FBXCodeCompatibility.m index e5725cd2d..b13a79e55 100644 --- a/WebDriverAgentLib/Utilities/FBXCodeCompatibility.m +++ b/WebDriverAgentLib/Utilities/FBXCodeCompatibility.m @@ -13,45 +13,11 @@ #import "FBConfiguration.h" #import "FBErrorBuilder.h" #import "FBLogger.h" -#import "XCUIApplication.h" #import "XCUIApplication+FBHelpers.h" #import "XCUIElementQuery.h" #import "FBXCTestDaemonsProxy.h" #import "XCTestManager_ManagerInterface-Protocol.h" -static const NSTimeInterval APP_STATE_CHANGE_TIMEOUT = 5.0; - -NSString *const FBApplicationMethodNotSupportedException = @"FBApplicationMethodNotSupportedException"; - -@implementation XCUIApplication (FBCompatibility) - -- (void)fb_activate -{ - [self activate]; - if (![self waitForState:XCUIApplicationStateRunningForeground timeout:APP_STATE_CHANGE_TIMEOUT / 2] || ![self fb_waitForAppElement:APP_STATE_CHANGE_TIMEOUT / 2]) { - [FBLogger logFmt:@"The application '%@' is not running in foreground after %.2f seconds", self.bundleID, APP_STATE_CHANGE_TIMEOUT]; - } -} - -- (void)fb_terminate -{ - [self terminate]; - if (![self waitForState:XCUIApplicationStateNotRunning timeout:APP_STATE_CHANGE_TIMEOUT]) { - [FBLogger logFmt:@"The active application is still '%@' after %.2f seconds timeout", self.bundleID, APP_STATE_CHANGE_TIMEOUT]; - } -} - -- (void)fb_launch -{ - [self launch]; - if (![self fb_waitForAppElement:APP_STATE_CHANGE_TIMEOUT]) { - [FBLogger logFmt:@"The application '%@' is not running in foreground after %.2f seconds", self.bundleID, APP_STATE_CHANGE_TIMEOUT]; - } -} - -@end - - @implementation XCUIElementQuery (FBCompatibility) - (XCElementSnapshot *)fb_uniqueSnapshotWithError:(NSError **)error