Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jan 13, 2024
1 parent 6f69db1 commit 958e2f9
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 75 deletions.
1 change: 0 additions & 1 deletion PrivateHeaders/XCTest/XCUIApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *> *)capabilities[FB_CAP_ARGUMENTS] ?: @[];
app.launchEnvironment = (NSDictionary <NSString *, NSString *> *)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];
}
}

Expand Down
2 changes: 0 additions & 2 deletions WebDriverAgentLib/Routing/FBSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
12 changes: 8 additions & 4 deletions WebDriverAgentLib/Routing/FBSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -198,7 +202,7 @@ - (XCUIApplication *)launchApplicationWithBundleId:(NSString *)bundleIdentifier
- (XCUIApplication *)activateApplicationWithBundleId:(NSString *)bundleIdentifier
{
XCUIApplication *app = [self makeApplicationWithBundleId:bundleIdentifier];
[app fb_activate];
[app activate];
return app;
}

Expand All @@ -209,7 +213,7 @@ - (BOOL)terminateApplicationWithBundleId:(NSString *)bundleIdentifier
self.isTestedApplicationExpectedToRun = NO;
}
if (app.running) {
[app fb_terminate];
[app terminate];
return YES;
}
return NO;
Expand Down
29 changes: 0 additions & 29 deletions WebDriverAgentLib/Utilities/FBXCodeCompatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
34 changes: 0 additions & 34 deletions WebDriverAgentLib/Utilities/FBXCodeCompatibility.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 958e2f9

Please sign in to comment.