-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathFBDebugCommands.m
77 lines (66 loc) · 3.2 KB
/
FBDebugCommands.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "FBDebugCommands.h"
#import "FBRouteRequest.h"
#import "FBSession.h"
#import "FBXMLGenerationOptions.h"
#import "XCUIApplication+FBHelpers.h"
#import "XCUIElement+FBUtilities.h"
#import "FBXPath.h"
@implementation FBDebugCommands
#pragma mark - <FBCommandHandler>
+ (NSArray *)routes
{
return
@[
[[FBRoute GET:@"/source"] respondWithTarget:self action:@selector(handleGetSourceCommand:)],
[[FBRoute GET:@"/source"].withoutSession respondWithTarget:self action:@selector(handleGetSourceCommand:)],
[[FBRoute GET:@"/wda/accessibleSource"] respondWithTarget:self action:@selector(handleGetAccessibleSourceCommand:)],
[[FBRoute GET:@"/wda/accessibleSource"].withoutSession respondWithTarget:self action:@selector(handleGetAccessibleSourceCommand:)],
];
}
#pragma mark - Commands
static NSString *const SOURCE_FORMAT_XML = @"xml";
static NSString *const SOURCE_FORMAT_JSON = @"json";
static NSString *const SOURCE_FORMAT_DESCRIPTION = @"description";
+ (id<FBResponsePayload>)handleGetSourceCommand:(FBRouteRequest *)request
{
// This method might be called without session
XCUIApplication *application = request.session.activeApplication ?: XCUIApplication.fb_activeApplication;
NSString *sourceType = request.parameters[@"format"] ?: SOURCE_FORMAT_XML;
NSString *sourceScope = request.parameters[@"scope"];
id result;
if ([sourceType caseInsensitiveCompare:SOURCE_FORMAT_XML] == NSOrderedSame) {
NSArray<NSString *> *excludedAttributes = nil == request.parameters[@"excluded_attributes"]
? nil
: [request.parameters[@"excluded_attributes"] componentsSeparatedByString:@","];
result = [application fb_xmlRepresentationWithOptions:
[[[FBXMLGenerationOptions new]
withExcludedAttributes:excludedAttributes]
withScope:sourceScope]];
} else if ([sourceType caseInsensitiveCompare:SOURCE_FORMAT_JSON] == NSOrderedSame) {
result = application.fb_tree;
} else if ([sourceType caseInsensitiveCompare:SOURCE_FORMAT_DESCRIPTION] == NSOrderedSame) {
result = application.fb_descriptionRepresentation;
} else {
return FBResponseWithStatus([FBCommandStatus invalidArgumentErrorWithMessage:[NSString stringWithFormat:@"Unknown source format '%@'. Only %@ source formats are supported.",
sourceType, @[SOURCE_FORMAT_XML, SOURCE_FORMAT_JSON, SOURCE_FORMAT_DESCRIPTION]] traceback:nil]);
}
if (nil == result) {
return FBResponseWithUnknownErrorFormat(@"Cannot get '%@' source of the current application", sourceType);
}
return FBResponseWithObject(result);
}
+ (id<FBResponsePayload>)handleGetAccessibleSourceCommand:(FBRouteRequest *)request
{
// This method might be called without session
XCUIApplication *application = request.session.activeApplication ?: XCUIApplication.fb_activeApplication;
return FBResponseWithObject(application.fb_accessibilityTree ?: @{});
}
@end