Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions WebDriverAgent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
0E0413382DF1E15100AF007C /* XCUIElement+FBMinMax.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E0413372DF1E15100AF007C /* XCUIElement+FBMinMax.m */; };
0E0413392DF1E15100AF007C /* XCUIElement+FBMinMax.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E0413372DF1E15100AF007C /* XCUIElement+FBMinMax.m */; };
0E04133B2DF1E15900AF007C /* XCUIElement+FBMinMax.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E04133A2DF1E15900AF007C /* XCUIElement+FBMinMax.h */; };
0E04133C2DF1E15900AF007C /* XCUIElement+FBMinMax.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E04133A2DF1E15900AF007C /* XCUIElement+FBMinMax.h */; };
1357E296233D05240054BDB8 /* XCUIHitPointResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 1357E295233D05240054BDB8 /* XCUIHitPointResult.h */; };
1357E297233D05240054BDB8 /* XCUIHitPointResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 1357E295233D05240054BDB8 /* XCUIHitPointResult.h */; };
13815F6F2328D20400CDAB61 /* FBActiveAppDetectionPoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 13815F6D2328D20400CDAB61 /* FBActiveAppDetectionPoint.h */; };
Expand Down Expand Up @@ -918,6 +922,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0E0413372DF1E15100AF007C /* XCUIElement+FBMinMax.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "XCUIElement+FBMinMax.m"; sourceTree = "<group>"; };
0E04133A2DF1E15900AF007C /* XCUIElement+FBMinMax.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XCUIElement+FBMinMax.h"; sourceTree = "<group>"; };
1357E295233D05240054BDB8 /* XCUIHitPointResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XCUIHitPointResult.h; sourceTree = "<group>"; };
13815F6D2328D20400CDAB61 /* FBActiveAppDetectionPoint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBActiveAppDetectionPoint.h; sourceTree = "<group>"; };
13815F6E2328D20400CDAB61 /* FBActiveAppDetectionPoint.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBActiveAppDetectionPoint.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1785,6 +1791,8 @@
EE8DDD7C20C5733B004D4925 /* XCUIElement+FBForceTouch.m */,
EE9AB7471CAEDF0C008C271F /* XCUIElement+FBIsVisible.h */,
EE9AB7481CAEDF0C008C271F /* XCUIElement+FBIsVisible.m */,
0E04133A2DF1E15900AF007C /* XCUIElement+FBMinMax.h */,
0E0413372DF1E15100AF007C /* XCUIElement+FBMinMax.m */,
7136A4771E8918E60024FC3D /* XCUIElement+FBPickerWheel.h */,
7136A4781E8918E60024FC3D /* XCUIElement+FBPickerWheel.m */,
71D3B3D3267FC7260076473D /* XCUIElement+FBResolve.h */,
Expand Down Expand Up @@ -2377,6 +2385,7 @@
641EE6782240C5CA00173FCB /* XCTNSNotificationExpectation.h in Headers */,
641EE6792240C5CA00173FCB /* XCUIRecorderNodeFinder.h in Headers */,
641EE67A2240C5CA00173FCB /* XCUIElement+FBAccessibility.h in Headers */,
0E04133C2DF1E15900AF007C /* XCUIElement+FBMinMax.h in Headers */,
641EE67B2240C5CA00173FCB /* XCUIRecorderUtilities.h in Headers */,
6496A5DA230D6EB30087F8CB /* AXSettings.h in Headers */,
641EE67C2240C5CA00173FCB /* XCTestCaseRun.h in Headers */,
Expand Down Expand Up @@ -2701,6 +2710,7 @@
EEE9B4721CD02B88009D2030 /* FBRunLoopSpinner.h in Headers */,
EE3A18621CDE618F00DE4205 /* FBErrorBuilder.h in Headers */,
EE35AD261E3B77D600A02D78 /* XCApplicationMonitor_iOS.h in Headers */,
0E04133B2DF1E15900AF007C /* XCUIElement+FBMinMax.h in Headers */,
EE3A18661CDE734B00DE4205 /* FBKeyboard.h in Headers */,
AD6C269C1CF2494200F8B5FF /* XCUIApplication+FBHelpers.h in Headers */,
714D88CC2733FB970074A925 /* FBXMLGenerationOptions.h in Headers */,
Expand Down Expand Up @@ -3202,6 +3212,7 @@
71BB58F92B96531900CB9BFE /* FBScreenRecordingContainer.m in Sources */,
641EE6152240C5CA00173FCB /* XCUIElement+FBScrolling.m in Sources */,
641EE6162240C5CA00173FCB /* FBSessionCommands.m in Sources */,
0E0413392DF1E15100AF007C /* XCUIElement+FBMinMax.m in Sources */,
641EE6192240C5CA00173FCB /* FBConfiguration.m in Sources */,
641EE61A2240C5CA00173FCB /* FBElementCache.m in Sources */,
71F5BE26252E576C00EE9EBA /* XCUIElement+FBSwiping.m in Sources */,
Expand Down Expand Up @@ -3249,6 +3260,7 @@
13DE7A45287C2A8D003243C6 /* FBXCAccessibilityElement.m in Sources */,
641EE70E2240CE4800173FCB /* FBTVNavigationTracker.m in Sources */,
71BD20741F86116100B36EC2 /* XCUIApplication+FBTouchAction.m in Sources */,
0E0413382DF1E15100AF007C /* XCUIElement+FBMinMax.m in Sources */,
EE158AE71CBD456F00A3E3F0 /* FBWebServer.m in Sources */,
715557D4211DBCE700613B26 /* FBTCPSocket.m in Sources */,
EE3A18631CDE618F00DE4205 /* FBErrorBuilder.m in Sources */,
Expand Down
16 changes: 15 additions & 1 deletion WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
static NSString* const FBExclusionAttributePlaceholderValue = @"placeholderValue";
static NSString* const FBExclusionAttributeNativeFrame = @"nativeFrame";
static NSString* const FBExclusionAttributeTraits = @"traits";
static NSString* const FBExclusionAttributeMinValue = @"minValue";
static NSString* const FBExclusionAttributeMaxValue = @"maxValue";

_Nullable id extractIssueProperty(id issue, NSString *propertyName) {
SEL selector = NSSelectorFromString(propertyName);
Expand Down Expand Up @@ -211,6 +213,8 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
FBExclusionAttributePlaceholderValue,
FBExclusionAttributeNativeFrame,
FBExclusionAttributeTraits,
FBExclusionAttributeMinValue,
FBExclusionAttributeMaxValue,
nil];

for (NSString *key in attributeBlocks) {
Expand Down Expand Up @@ -248,7 +252,7 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot

{
// Base attributes common to every element
NSMutableDictionary<NSString *, NSString *(^)(void)> *blocks =
NSMutableDictionary<NSString *, id(^)(void)> *blocks =
[@{
FBExclusionAttributeFrame: ^{
return NSStringFromCGRect(wrappedSnapshot.wdFrame);
Expand Down Expand Up @@ -282,6 +286,16 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
};
}

// Only for elements that support min/max value
if (FBDoesElementSupportMinMaxValue(elementType)) {
blocks[FBExclusionAttributeMinValue] = ^{
return wrappedSnapshot.wdMinValue;
};
blocks[FBExclusionAttributeMaxValue] = ^{
return wrappedSnapshot.wdMaxValue;
};
}

return [blocks copy];
}

Expand Down
34 changes: 34 additions & 0 deletions WebDriverAgentLib/Categories/XCUIElement+FBMinMax.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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 <WebDriverAgentLib/FBXCElementSnapshotWrapper.h>

NS_ASSUME_NONNULL_BEGIN

@interface XCUIElement (FBMinMax)

/*! Minimum value (minValue) – may be nil if the element does not have this attribute */
@property (nonatomic, readonly, nullable) NSNumber *fb_minValue;

/*! Maximum value (maxValue) - may be nil if the element does not have this attribute */
@property (nonatomic, readonly, nullable) NSNumber *fb_maxValue;

@end

@interface FBXCElementSnapshotWrapper (FBMinMax)

/*! Minimum value (minValue) – may be nil if the element does not have this attribute */
@property (nonatomic, readonly, nullable) NSNumber *fb_minValue;

/*! Maximum value (maxValue) - may be nil if the element does not have this attribute */
@property (nonatomic, readonly, nullable) NSNumber *fb_maxValue;

@end

NS_ASSUME_NONNULL_END
76 changes: 76 additions & 0 deletions WebDriverAgentLib/Categories/XCUIElement+FBMinMax.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* 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 "FBLogger.h"
#import "XCUIElement+FBMinMax.h"
#import "FBXCElementSnapshotWrapper+Helpers.h"
#import "XCUIElement+FBUtilities.h"
#import "XCTestPrivateSymbols.h"

@interface FBXCElementSnapshotWrapper (FBMinMaxInternal)

- (NSNumber *)fb_numericAttribute:(NSString *)attributeName symbol:(NSNumber *)symbol;

@end

@implementation XCUIElement (FBMinMax)

- (NSNumber *)fb_minValue
{
@autoreleasepool {
id<FBXCElementSnapshot> snapshot = [self fb_standardSnapshot];
return [[FBXCElementSnapshotWrapper ensureWrapped:snapshot] fb_minValue];
}
}

- (NSNumber *)fb_maxValue
{
@autoreleasepool {
id<FBXCElementSnapshot> snapshot = [self fb_standardSnapshot];
return [[FBXCElementSnapshotWrapper ensureWrapped:snapshot] fb_maxValue];
}
}

@end

@implementation FBXCElementSnapshotWrapper (FBMinMax)

- (NSNumber *)fb_minValue
{
return [self fb_numericAttribute:FB_XCAXACustomMinValueAttributeName
symbol:FB_XCAXACustomMinValueAttribute];
}

- (NSNumber *)fb_maxValue
{
return [self fb_numericAttribute:FB_XCAXACustomMaxValueAttributeName
symbol:FB_XCAXACustomMaxValueAttribute];
}

- (NSNumber *)fb_numericAttribute:(NSString *)attributeName symbol:(NSNumber *)symbol
{
NSNumber *cached = (self.snapshot.additionalAttributes ?: @{})[symbol];
if (cached) {
return cached;
}

NSError *error = nil;
NSNumber *raw = [self fb_attributeValue:attributeName error:&error];
if (nil != raw) {
NSMutableDictionary *updated = [NSMutableDictionary dictionaryWithDictionary:self.additionalAttributes ?: @{}];
updated[symbol] = raw;
self.snapshot.additionalAttributes = updated.copy;
return raw;
}

[FBLogger logFmt:@"[FBMinMax] Cannot determine %@ for %@: %@", attributeName, self.fb_description, error.localizedDescription];
return nil;
}

@end
11 changes: 11 additions & 0 deletions WebDriverAgentLib/Categories/XCUIElement+FBWebDriverAttributes.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import "XCTestPrivateSymbols.h"
#import "XCUIHitPointResult.h"
#import "FBAccessibilityTraits.h"
#import "XCUIElement+FBMinMax.h"

#define BROKEN_RECT CGRectMake(-1, -1, 0, 0)

Expand Down Expand Up @@ -76,6 +77,16 @@ - (id)fb_valueForWDAttributeName:(NSString *)name
return [self valueForKey:[FBElementUtils wdAttributeNameForAttributeName:name]];
}

- (NSNumber *)wdMinValue
{
return self.fb_minValue;
}

- (NSNumber *)wdMaxValue
{
return self.fb_maxValue;
}

- (NSString *)wdValue
{
id value = self.value;
Expand Down
4 changes: 4 additions & 0 deletions WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ + (NSArray *)routes
FB_SETTING_USE_CLEAR_TEXT_SHORTCUT: @([FBConfiguration useClearTextShortcut]),
FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE: @([FBConfiguration includeHittableInPageSource]),
FB_SETTING_INCLUDE_NATIVE_FRAME_IN_PAGE_SOURCE: @([FBConfiguration includeNativeFrameInPageSource]),
FB_SETTING_INCLUDE_MIN_MAX_VALUE_IN_PAGE_SOURCE: @([FBConfiguration includeMinMaxValueInPageSource]),
FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE: @([FBConfiguration limitXpathContextScope]),
#if !TARGET_OS_TV
FB_SETTING_SCREENSHOT_ORIENTATION: [FBConfiguration humanReadableScreenshotOrientation],
Expand Down Expand Up @@ -463,6 +464,9 @@ + (NSArray *)routes
if (nil != [settings objectForKey:FB_SETTING_INCLUDE_NATIVE_FRAME_IN_PAGE_SOURCE]) {
[FBConfiguration setIncludeNativeFrameInPageSource:[[settings objectForKey:FB_SETTING_INCLUDE_NATIVE_FRAME_IN_PAGE_SOURCE] boolValue]];
}
if (nil != [settings objectForKey:FB_SETTING_INCLUDE_MIN_MAX_VALUE_IN_PAGE_SOURCE]) {
[FBConfiguration setIncludeMinMaxValueInPageSource:[[settings objectForKey:FB_SETTING_INCLUDE_MIN_MAX_VALUE_IN_PAGE_SOURCE] boolValue]];
}
if (nil != [settings objectForKey:FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE]) {
[FBConfiguration setLimitXpathContextScope:[[settings objectForKey:FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE] boolValue]];
}
Expand Down
6 changes: 6 additions & 0 deletions WebDriverAgentLib/Routing/FBElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ NS_ASSUME_NONNULL_BEGIN
/*! Element's placeholder value */
@property (nonatomic, readonly, copy, nullable) NSString *wdPlaceholderValue;

/*! Element's minimum value */
@property (nonatomic, readonly, strong, nullable) NSNumber *wdMinValue;

/*! Element's maximum value */
@property (nonatomic, readonly, strong, nullable) NSNumber *wdMaxValue;

/**
Returns value of given property specified in WebDriver Spec
Check the FBElement protocol to get list of supported attributes.
Expand Down
12 changes: 12 additions & 0 deletions WebDriverAgentLib/Utilities/FBConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,18 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) {
+ (void)setIncludeNativeFrameInPageSource:(BOOL)enabled;
+ (BOOL)includeNativeFrameInPageSource;

/**
* Whether to include `minValue`/`maxValue` attributes in the page source.
* These attributes are retrieved from native element snapshots and represent
* value boundaries for elements like sliders or progress indicators.
* This may affect performance if used on many elements.
* Disabled by default.
*
* @param enabled Either YES or NO
*/
+ (void)setIncludeMinMaxValueInPageSource:(BOOL)enabled;
+ (BOOL)includeMinMaxValueInPageSource;

@end

NS_ASSUME_NONNULL_END
11 changes: 11 additions & 0 deletions WebDriverAgentLib/Utilities/FBConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#endif
static BOOL FBShouldIncludeHittableInPageSource = NO;
static BOOL FBShouldIncludeNativeFrameInPageSource = NO;
static BOOL FBShouldIncludeMinMaxValueInPageSource = NO;

@implementation FBConfiguration

Expand Down Expand Up @@ -664,4 +665,14 @@ + (BOOL)includeNativeFrameInPageSource
return FBShouldIncludeNativeFrameInPageSource;
}

+ (void)setIncludeMinMaxValueInPageSource:(BOOL)enabled
{
FBShouldIncludeMinMaxValueInPageSource = enabled;
}

+ (BOOL)includeMinMaxValueInPageSource
{
return FBShouldIncludeMinMaxValueInPageSource;
}

@end
10 changes: 9 additions & 1 deletion WebDriverAgentLib/Utilities/FBElementHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ NS_ASSUME_NONNULL_BEGIN
Checks if the element is a text field

@param elementType XCTest element type
@return YES if the elemnt is a text field
@return YES if the element is a text field
*/
BOOL FBDoesElementSupportInnerText(XCUIElementType elementType);

/**
Checks if the element supports min/max value attributes

@param elementType XCTest element type
@return YES if the element type supports min/max value attributes
*/
BOOL FBDoesElementSupportMinMaxValue(XCUIElementType elementType);

NS_ASSUME_NONNULL_END
5 changes: 5 additions & 0 deletions WebDriverAgentLib/Utilities/FBElementHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ BOOL FBDoesElementSupportInnerText(XCUIElementType elementType) {
|| elementType == XCUIElementTypeSearchField
|| elementType == XCUIElementTypeSecureTextField;
}

BOOL FBDoesElementSupportMinMaxValue(XCUIElementType elementType) {
return elementType == XCUIElementTypeSlider
|| elementType == XCUIElementTypeStepper;
}
2 changes: 1 addition & 1 deletion WebDriverAgentLib/Utilities/FBSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ extern NSString* const FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE;
extern NSString* const FB_SETTING_AUTO_CLICK_ALERT_SELECTOR;
extern NSString *const FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE;
extern NSString *const FB_SETTING_INCLUDE_NATIVE_FRAME_IN_PAGE_SOURCE;

extern NSString *const FB_SETTING_INCLUDE_MIN_MAX_VALUE_IN_PAGE_SOURCE;

NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions WebDriverAgentLib/Utilities/FBSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@
NSString* const FB_SETTING_AUTO_CLICK_ALERT_SELECTOR = @"autoClickAlertSelector";
NSString* const FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE = @"includeHittableInPageSource";
NSString* const FB_SETTING_INCLUDE_NATIVE_FRAME_IN_PAGE_SOURCE = @"includeNativeFrameInPageSource";
NSString* const FB_SETTING_INCLUDE_MIN_MAX_VALUE_IN_PAGE_SOURCE = @"includeMinMaxValueInPageSource";
Loading