Skip to content

Commit

Permalink
Filter out system app when there are multiple active apps
Browse files Browse the repository at this point in the history
  • Loading branch information
fr0l committed Aug 26, 2019
1 parent 26e8790 commit b9caf24
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion WebDriverAgentLib/FBApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ + (instancetype)fb_activeApplication
return [FBXCAXClientProxy.sharedClient activeApplications].count == 1;
}];

XCAccessibilityElement *activeApplicationElement = [[FBXCAXClientProxy.sharedClient activeApplications] firstObject];
NSArray<XCAccessibilityElement *> *activeApplicationElements = [FBXCAXClientProxy.sharedClient activeApplications];
XCAccessibilityElement *activeApplicationElement;

if (activeApplicationElements.count > 1) {
XCAccessibilityElement *systemApplicationElement = [FBXCAXClientProxy.sharedClient systemApplication];
NSPredicate *nonSystemApplicationPredicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary<NSString *,id> *bindings) {
return systemApplicationElement.processIdentifier != ((XCAccessibilityElement *)evaluatedObject).processIdentifier;
}];
activeApplicationElement = [[activeApplicationElements filteredArrayUsingPredicate:nonSystemApplicationPredicate] firstObject];
} else {
activeApplicationElement = [activeApplicationElements firstObject];
}

if (!activeApplicationElement) {
return nil;
}
Expand Down

0 comments on commit b9caf24

Please sign in to comment.