Skip to content

Commit 0e8adcb

Browse files
Make it possible to start a session without starting an app (#195)
1 parent e5d6c6d commit 0e8adcb

File tree

6 files changed

+26
-25
lines changed

6 files changed

+26
-25
lines changed

WebDriverAgentLib/Commands/FBSessionCommands.m

+16-15
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ + (NSArray *)routes
7878
+ (id<FBResponsePayload>)handleCreateSession:(FBRouteRequest *)request
7979
{
8080
NSDictionary *requirements = request.arguments[@"desiredCapabilities"];
81-
NSString *bundleID = requirements[@"bundleId"];
82-
NSString *appPath = requirements[@"app"];
83-
if (!bundleID) {
84-
return FBResponseWithErrorFormat(@"'bundleId' desired capability not provided");
85-
}
8681
[FBConfiguration setShouldUseTestManagerForVisibilityDetection:[requirements[@"shouldUseTestManagerForVisibilityDetection"] boolValue]];
8782
if (requirements[@"shouldUseCompactResponses"]) {
8883
[FBConfiguration setShouldUseCompactResponses:[requirements[@"shouldUseCompactResponses"] boolValue]];
@@ -106,19 +101,25 @@ + (NSArray *)routes
106101

107102
[FBConfiguration setShouldWaitForQuiescence:[requirements[@"shouldWaitForQuiescence"] boolValue]];
108103

109-
FBApplication *app = [[FBApplication alloc] initPrivateWithPath:appPath bundleID:bundleID];
110-
app.fb_shouldWaitForQuiescence = FBConfiguration.shouldWaitForQuiescence;
111-
app.launchArguments = (NSArray<NSString *> *)requirements[@"arguments"] ?: @[];
112-
app.launchEnvironment = (NSDictionary <NSString *, NSString *> *)requirements[@"environment"] ?: @{};
113-
[app launch];
114-
115-
if (app.processID == 0) {
116-
return FBResponseWithErrorFormat(@"Failed to launch %@ application", bundleID);
104+
NSString *bundleID = requirements[@"bundleId"];
105+
FBApplication *app = nil;
106+
if (bundleID != nil) {
107+
app = [[FBApplication alloc] initPrivateWithPath:requirements[@"app"]
108+
bundleID:bundleID];
109+
app.fb_shouldWaitForQuiescence = FBConfiguration.shouldWaitForQuiescence;
110+
app.launchArguments = (NSArray<NSString *> *)requirements[@"arguments"] ?: @[];
111+
app.launchEnvironment = (NSDictionary <NSString *, NSString *> *)requirements[@"environment"] ?: @{};
112+
[app launch];
113+
if (app.processID == 0) {
114+
return FBResponseWithErrorFormat(@"Failed to launch %@ application", bundleID);
115+
}
117116
}
117+
118118
if (requirements[@"defaultAlertAction"]) {
119-
[FBSession sessionWithApplication:app defaultAlertAction:(id)requirements[@"defaultAlertAction"]];
119+
[FBSession initWithApplication:app
120+
defaultAlertAction:(id)requirements[@"defaultAlertAction"]];
120121
} else {
121-
[FBSession sessionWithApplication:app];
122+
[FBSession initWithApplication:app];
122123
}
123124

124125
return FBResponseWithObject(FBSessionCommands.sessionInformation);

WebDriverAgentLib/Routing/FBSession.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern NSString *const FBApplicationCrashedException;
4848
@param application The application that we want to create session for
4949
@return new session
5050
*/
51-
+ (instancetype)sessionWithApplication:(nullable FBApplication *)application;
51+
+ (instancetype)initWithApplication:(nullable FBApplication *)application;
5252

5353
/**
5454
Creates and saves new session for application with default alert handling behaviour
@@ -57,7 +57,7 @@ extern NSString *const FBApplicationCrashedException;
5757
@param defaultAlertAction The default reaction to on-screen alert. Either 'accept' or 'dismiss'
5858
@return new session
5959
*/
60-
+ (instancetype)sessionWithApplication:(nullable FBApplication *)application defaultAlertAction:(NSString *)defaultAlertAction;
60+
+ (instancetype)initWithApplication:(nullable FBApplication *)application defaultAlertAction:(NSString *)defaultAlertAction;
6161

6262
/**
6363
Kills application associated with that session and removes session

WebDriverAgentLib/Routing/FBSession.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ @implementation FBSession
6767
static FBSession *_activeSession;
6868
+ (instancetype)activeSession
6969
{
70-
return _activeSession ?: [FBSession sessionWithApplication:nil];
70+
return _activeSession ?: [FBSession initWithApplication:nil];
7171
}
7272

7373
+ (void)markSessionActive:(FBSession *)session
@@ -89,7 +89,7 @@ + (instancetype)sessionWithIdentifier:(NSString *)identifier
8989
return _activeSession;
9090
}
9191

92-
+ (instancetype)sessionWithApplication:(FBApplication *)application
92+
+ (instancetype)initWithApplication:(FBApplication *)application
9393
{
9494
FBSession *session = [FBSession new];
9595
session.alertsMonitor = nil;
@@ -107,9 +107,9 @@ + (instancetype)sessionWithApplication:(FBApplication *)application
107107
return session;
108108
}
109109

110-
+ (instancetype)sessionWithApplication:(nullable FBApplication *)application defaultAlertAction:(NSString *)defaultAlertAction
110+
+ (instancetype)initWithApplication:(nullable FBApplication *)application defaultAlertAction:(NSString *)defaultAlertAction
111111
{
112-
FBSession *session = [self.class sessionWithApplication:application];
112+
FBSession *session = [self.class initWithApplication:application];
113113
session.alertsMonitor = [[FBAlertsMonitor alloc] init];
114114
session.alertsMonitor.delegate = (id<FBAlertsMonitorDelegate>)session;
115115
session.alertsMonitor.application = FBApplication.fb_activeApplication;

WebDriverAgentTests/IntegrationTests/FBAutoAlertsHandlerTests.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ - (void)disabled_testAutoAcceptingOfAlerts
5454
}
5555

5656
self.session = [FBSession
57-
sessionWithApplication:FBApplication.fb_activeApplication
57+
initWithApplication:FBApplication.fb_activeApplication
5858
defaultAlertAction:@"accept"];
5959
for (int i = 0; i < 2; i++) {
6060
[self.testedApplication.buttons[FBShowAlertButtonName] fb_tapWithError:nil];
@@ -71,7 +71,7 @@ - (void)disabled_testAutoDismissingOfAlerts
7171
}
7272

7373
self.session = [FBSession
74-
sessionWithApplication:FBApplication.fb_activeApplication
74+
initWithApplication:FBApplication.fb_activeApplication
7575
defaultAlertAction:@"dismiss"];
7676
for (int i = 0; i < 2; i++) {
7777
[self.testedApplication.buttons[FBShowAlertButtonName] fb_tapWithError:nil];

WebDriverAgentTests/IntegrationTests/FBSessionIntegrationTests.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ - (void)setUp
3737
{
3838
[super setUp];
3939
[self launchApplication];
40-
self.session = [FBSession sessionWithApplication:FBApplication.fb_activeApplication];
40+
self.session = [FBSession initWithApplication:FBApplication.fb_activeApplication];
4141
}
4242

4343
- (void)testSettingsAppCanBeOpenedInScopeOfTheCurrentSession

WebDriverAgentTests/UnitTests/FBSessionTests.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ - (void)setUp
2323
{
2424
[super setUp];
2525
self.testedApplication = (id)FBApplicationDouble.new;
26-
self.session = [FBSession sessionWithApplication:self.testedApplication];
26+
self.session = [FBSession initWithApplication:self.testedApplication];
2727
}
2828

2929
- (void)testSessionFetching

0 commit comments

Comments
 (0)