Skip to content

Commit

Permalink
chore: Make sure the app under test is restarted if opened from a dee…
Browse files Browse the repository at this point in the history
…p link (#846)
  • Loading branch information
mykola-mokhnach authored Feb 11, 2024
1 parent ed06d2f commit 88b0a5b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ + (NSArray *)routes
NSString *bundleID = capabilities[FB_CAP_BUNDLE_ID];
NSString *initialUrl = capabilities[FB_CAP_INITIAL_URL];
XCUIApplication *app = nil;
BOOL didOpenInitialUrl = NO;
if (bundleID != nil) {
app = [[XCUIApplication alloc] initWithBundleIdentifier:bundleID];
BOOL forceAppLaunch = YES;
Expand All @@ -153,31 +152,32 @@ + (NSArray *)routes
app.launchArguments = (NSArray<NSString *> *)capabilities[FB_CAP_ARGUMENTS] ?: @[];
app.launchEnvironment = (NSDictionary <NSString *, NSString *> *)capabilities[FB_CAP_ENVIRNOMENT] ?: @{};
if (nil != initialUrl) {
if (app.running) {
[app terminate];
}
NSError *openError;
didOpenInitialUrl = [XCUIDevice.sharedDevice fb_openUrl:initialUrl
withApplication:bundleID
error:&openError];
if (!didOpenInitialUrl) {
NSString *errorMsg = [NSString stringWithFormat:@"Cannot open the URL %@ in %@ application. Original error: %@",
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];
return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:errorMsg traceback:nil]);
}
} else {
[app launch];
}
if (![app running]) {
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 == XCUIApplicationStateRunningBackground && !forceAppLaunch) {
if (nil != initialUrl) {
NSError *openError;
didOpenInitialUrl = [XCUIDevice.sharedDevice fb_openUrl:initialUrl
withApplication:bundleID
error:&openError];
if (!didOpenInitialUrl) {
NSString *errorMsg = [NSString stringWithFormat:@"Cannot open the URL %@ in %@ application. Original error: %@",
if (![XCUIDevice.sharedDevice fb_openUrl:initialUrl
withApplication:bundleID
error:&openError]) {
NSString *errorMsg = [NSString stringWithFormat:@"Cannot open the URL %@ with the %@ application. Original error: %@",
initialUrl, bundleID, openError.description];
return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:errorMsg traceback:nil]);
}
Expand Down

0 comments on commit 88b0a5b

Please sign in to comment.