初始化提交
This commit is contained in:
81
WebDriverAgentLib/Commands/FBDebugCommands.m
Normal file
81
WebDriverAgentLib/Commands/FBDebugCommands.m
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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) {
|
||||
NSString *excludedAttributesString = request.parameters[@"excluded_attributes"];
|
||||
NSSet<NSString *> *excludedAttributes = (excludedAttributesString == nil)
|
||||
? nil
|
||||
: [NSSet setWithArray:[excludedAttributesString componentsSeparatedByString:@","]];
|
||||
|
||||
result = [application fb_tree:excludedAttributes];
|
||||
} 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
|
||||
Reference in New Issue
Block a user