Skip to content

Commit

Permalink
chore: Handle app startup errors as session creation exceptions (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Mar 3, 2024
1 parent 6f4b640 commit 0ec5398
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
22 changes: 14 additions & 8 deletions WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#import "FBCapabilities.h"
#import "FBConfiguration.h"
#import "FBExceptions.h"
#import "FBLogger.h"
#import "FBProtocolHelpers.h"
#import "FBRouteRequest.h"
Expand Down Expand Up @@ -91,7 +92,7 @@ + (NSArray *)routes
traceback:nil]);
}
if (nil == (capabilities = FBParseCapabilities((NSDictionary *)request.arguments[@"capabilities"], &error))) {
return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:error.description traceback:nil]);
return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:error.localizedDescription traceback:nil]);
}

[FBConfiguration resetSessionSettings];
Expand Down Expand Up @@ -159,12 +160,16 @@ + (NSArray *)routes
if (![XCUIDevice.sharedDevice fb_openUrl:initialUrl
withApplication:bundleID
error:&openError]) {
NSString *errorMsg = [NSString stringWithFormat:@"Cannot open the URL %@ wuth the %@ application. Original error: %@",
initialUrl, bundleID, openError.description];
NSString *errorMsg = [NSString stringWithFormat:@"Cannot open the URL %@ with the %@ application. Original error: %@",
initialUrl, bundleID, openError.localizedDescription];
return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:errorMsg traceback:nil]);
}
} else {
[app launch];
@try {
[app launch];
} @catch (NSException *e) {
return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:e.reason traceback:nil]);
}
}
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];
Expand All @@ -178,7 +183,7 @@ + (NSArray *)routes
withApplication:bundleID
error:&openError]) {
NSString *errorMsg = [NSString stringWithFormat:@"Cannot open the URL %@ with the %@ application. Original error: %@",
initialUrl, bundleID, openError.description];
initialUrl, bundleID, openError.localizedDescription];
return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:errorMsg traceback:nil]);
}
} else {
Expand All @@ -191,7 +196,7 @@ + (NSArray *)routes
NSError *openError;
if (![XCUIDevice.sharedDevice fb_openUrl:initialUrl error:&openError]) {
NSString *errorMsg = [NSString stringWithFormat:@"Cannot open the URL %@. Original error: %@",
initialUrl, openError.description];
initialUrl, openError.localizedDescription];
return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:errorMsg traceback:nil]);
}
}
Expand Down Expand Up @@ -396,7 +401,8 @@ + (NSArray *)routes
NSError *error;
if (![FBActiveAppDetectionPoint.sharedInstance setCoordinatesWithString:(NSString *)[settings objectForKey:FB_SETTING_ACTIVE_APP_DETECTION_POINT]
error:&error]) {
return FBResponseWithStatus([FBCommandStatus invalidArgumentErrorWithMessage:error.description traceback:nil]);
return FBResponseWithStatus([FBCommandStatus invalidArgumentErrorWithMessage:error.localizedDescription
traceback:nil]);
}
}
if (nil != [settings objectForKey:FB_SETTING_INCLUDE_NON_MODAL_ELEMENTS]) {
Expand Down Expand Up @@ -427,7 +433,7 @@ + (NSArray *)routes
NSError *error;
if (![FBConfiguration setScreenshotOrientation:(NSString *)[settings objectForKey:FB_SETTING_SCREENSHOT_ORIENTATION]
error:&error]) {
return FBResponseWithStatus([FBCommandStatus invalidArgumentErrorWithMessage:error.description
return FBResponseWithStatus([FBCommandStatus invalidArgumentErrorWithMessage:error.localizedDescription
traceback:nil]);
}
}
Expand Down
3 changes: 3 additions & 0 deletions WebDriverAgentLib/Routing/FBExceptionHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ - (void)handleException:(NSException *)exception forResponse:(RouteResponse *)re
} else if ([exception.name isEqualToString:FBTimeoutException]) {
commandStatus = [FBCommandStatus timeoutErrorWithMessage:exception.reason
traceback:traceback];
} else if ([exception.name isEqualToString:FBSessionCreationException]) {
commandStatus = [FBCommandStatus sessionNotCreatedError:exception.reason
traceback:traceback];
} else {
commandStatus = [FBCommandStatus unknownErrorWithMessage:exception.reason
traceback:traceback];
Expand Down
3 changes: 3 additions & 0 deletions WebDriverAgentLib/Routing/FBExceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ NS_ASSUME_NONNULL_BEGIN
/*! Exception used to notify about missing session */
extern NSString *const FBSessionDoesNotExistException;

/*! Exception used to notify about session creation issues */
extern NSString *const FBSessionCreationException;

/*! Exception used to notify about application deadlock */
extern NSString *const FBApplicationDeadlockDetectedException;

Expand Down
1 change: 1 addition & 0 deletions WebDriverAgentLib/Routing/FBExceptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "FBExceptions.h"

NSString *const FBInvalidArgumentException = @"FBInvalidArgumentException";
NSString *const FBSessionCreationException = @"FBSessionCreationException";
NSString *const FBSessionDoesNotExistException = @"FBSessionDoesNotExistException";
NSString *const FBApplicationDeadlockDetectedException = @"FBApplicationDeadlockDetectedException";
NSString *const FBElementAttributeUnknownException = @"FBElementAttributeUnknownException";
Expand Down

0 comments on commit 0ec5398

Please sign in to comment.