Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add an endpoint to list active app candidates #941

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 24 additions & 36 deletions WebDriverAgentLib/Commands/FBCustomCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ + (NSArray *)routes
[[FBRoute GET:@"/wda/screen"].withoutSession respondWithTarget:self action:@selector(handleGetScreen:)],
[[FBRoute GET:@"/wda/activeAppInfo"] respondWithTarget:self action:@selector(handleActiveAppInfo:)],
[[FBRoute GET:@"/wda/activeAppInfo"].withoutSession respondWithTarget:self action:@selector(handleActiveAppInfo:)],
[[FBRoute GET:@"/wda/activeAppCandidatesInfo"] respondWithTarget:self action:@selector(handleActiveAppCandidatesInfo:)],
[[FBRoute GET:@"/wda/activeAppCandidatesInfo"].withoutSession respondWithTarget:self action:@selector(handleActiveAppCandidatesInfo:)],
#if !TARGET_OS_TV // tvOS does not provide relevant APIs
[[FBRoute POST:@"/wda/setPasteboard"] respondWithTarget:self action:@selector(handleSetPasteboard:)],
[[FBRoute POST:@"/wda/setPasteboard"].withoutSession respondWithTarget:self action:@selector(handleSetPasteboard:)],
Expand Down Expand Up @@ -186,47 +188,33 @@ + (NSArray *)routes
+ (id<FBResponsePayload>)handleActiveAppInfo:(FBRouteRequest *)request
{
XCUIApplication *app = request.session.activeApplication ?: XCUIApplication.fb_activeApplication;
return FBResponseWithObject(@{
@"pid": @(app.processID),
@"bundleId": app.bundleID,
@"name": app.identifier,
@"processArguments": [self processArguments:app],
});
return FBResponseWithObject([self appInfoWithApp:app]);
}

/**
* Returns current active app and its arguments of active session
*
* @return The dictionary of current active bundleId and its process/environment argumens
*
* @example
*
* [self currentActiveApplication]
* //=> {
* // "processArguments" : {
* // "env" : {
* // "HAPPY" : "testing"
* // },
* // "args" : [
* // "happy",
* // "tseting"
* // ]
* // }
*
* [self currentActiveApplication]
* //=> {}
*/
+ (NSDictionary *)processArguments:(XCUIApplication *)app
+ (id<FBResponsePayload>)handleActiveAppCandidatesInfo:(FBRouteRequest *)request
{
// Can be nil if no active activation is defined by XCTest
if (app == nil) {
return @{};
NSArray<XCUIApplication *> *apps = XCUIApplication.fb_activeApplications;
XCUIApplication *activeApp = request.session.activeApplication ?: XCUIApplication.fb_activeApplication;
pid_t activeAppPid = nil == activeApp ? 0 : activeApp.processID;
NSMutableArray<NSDictionary *> *result = [NSMutableArray array];
for (XCUIApplication *app in apps) {
NSMutableDictionary *info = [self appInfoWithApp:app].mutableCopy;
info[@"isActive"] = @(app.processID == activeAppPid);
[result addObject:info.copy];
}
return FBResponseWithObject(result.copy);
}

return
@{
@"args": app.launchArguments,
@"env": app.launchEnvironment
+ (NSDictionary *)appInfoWithApp:(XCUIApplication *)app
{
return (nil == app) ? @{} : @{
@"pid": @(app.processID),
@"bundleId": app.bundleID,
@"state": @(app.state),
@"processArguments": @{
@"args": app.launchArguments ?: @[],
@"env": app.launchEnvironment ?: @{}
}
};
}

Expand Down
Loading