| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /**
- * 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
|