Skip to content
Closed
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
7 changes: 6 additions & 1 deletion WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
static NSString* const FBExclusionAttributeFocused = @"focused";
static NSString* const FBExclusionAttributePlaceholderValue = @"placeholderValue";
static NSString* const FBExclusionAttributeNativeFrame = @"nativeFrame";
static NSString* const FBExclusionAttributeHittable = @"hittable";

_Nullable id extractIssueProperty(id issue, NSString *propertyName) {
SEL selector = NSSelectorFromString(propertyName);
Expand Down Expand Up @@ -205,6 +206,7 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot

NSDictionary<NSString *, NSString *(^)(void)> *attributeBlocks = [self fb_attributeBlockMapForWrappedSnapshot:wrappedSnapshot];


NSSet *nonPrefixedKeys = [NSSet setWithObjects:
FBExclusionAttributeFrame,
FBExclusionAttributePlaceholderValue,
Expand Down Expand Up @@ -243,7 +245,6 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
// Helper used by `dictionaryForElement:` to assemble attribute value blocks,
// including both common attributes and conditionally included ones like placeholderValue.
+ (NSDictionary<NSString *, NSString *(^)(void)> *)fb_attributeBlockMapForWrappedSnapshot:(FBXCElementSnapshotWrapper *)wrappedSnapshot

{
// Base attributes common to every element
NSMutableDictionary<NSString *, NSString *(^)(void)> *blocks =
Expand Down Expand Up @@ -277,6 +278,10 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
};
}

blocks[FBExclusionAttributeHittable] = ^{
return [@([wrappedSnapshot isWDResolvedHittable]) stringValue];
};

return [blocks copy];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "FBElementUtils.h"
#import "XCTestPrivateSymbols.h"
#import "XCUIHitPointResult.h"
#import "XCUIApplication+FBHelpers.h"

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

Expand Down Expand Up @@ -242,6 +243,14 @@ - (BOOL)isWDHittable
return nil == result ? NO : result.hittable;
}

- (BOOL)isWDResolvedHittable
{
// Snapshot-based estimation of XCUIElement.hittable using accessibility, visibility, and hit point.
// Does not rely on live XCUIElement resolution.
// See discussion: https://github.com/appium/WebDriverAgent/pull/1021
return self.isWDAccessible && self.isWDHittable && self.isWDVisible;
}

- (NSDictionary *)wdRect
{
CGRect frame = self.wdFrame;
Expand Down
8 changes: 7 additions & 1 deletion WebDriverAgentLib/Routing/FBElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ NS_ASSUME_NONNULL_BEGIN
/*! Whether element is focused */
@property (nonatomic, readonly, getter = isWDFocused) BOOL wdFocused;

/*! Whether element is hittable */
/*! Whether the element is considered hittable based on snapshot hit point */
@property (nonatomic, readonly, getter = isWDHittable) BOOL wdHittable;

/*!
* Returns a snapshot-based estimation of hittability
* using accessibility, visibility, and hit point heuristics.
*/
@property (nonatomic, readonly, getter = isWDResolvedHittable) BOOL wdResolvedHittable;

/*! Element's index relatively to its parent. Starts from zero */
@property (nonatomic, readonly) NSUInteger wdIndex;

Expand Down
11 changes: 11 additions & 0 deletions WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,15 @@ - (void)testTextViewAttributes
XCTAssertEqualObjects(element.wdValue, @"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901");
}

- (void)testNativeHittableAttribute
{
XCUIElement *button = self.testedApplication.buttons[@"Button"];
XCTAssertTrue(button.exists);

id<FBXCElementSnapshot> snapshot = [button fb_standardSnapshot];
FBXCElementSnapshotWrapper *wrapped = [FBXCElementSnapshotWrapper ensureWrapped:snapshot];

XCTAssertEqual([wrapped isWDResolvedHittable], button.hittable);
}

@end
Loading