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
17 changes: 16 additions & 1 deletion WebDriverAgentLib/Categories/XCUIElement+FBUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
Gets the most recent snapshot of the current element. The element will be
automatically resolved if the snapshot is not available yet.
Calls to this method mutate the `lastSnapshot` instance property..
Calls to this method mutate the `lastSnapshot` instance property.
The maximum snapshot tree depth is set by `FBConfiguration.snapshotMaxDepth`

Snapshot specifics:
Expand All @@ -49,6 +49,21 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (id<FBXCElementSnapshot>)fb_customSnapshot;

/**
Gets the most recent snapshot of the current element. The element will be
automatically resolved if the snapshot is not available yet.
Calls to this method mutate the `lastSnapshot` instance property.
The maximum snapshot tree depth is set by `FBConfiguration.snapshotMaxDepth`

Snapshot specifics:
- Less performant in comparison to the standard one
- The `hittable` property calculation is aligned with the native calculation logic

@return The recent snapshot of the element
@throws FBStaleElementException if the element is not present in DOM and thus no snapshot could be made
*/
- (id<FBXCElementSnapshot>)fb_nativeSnapshot;

/**
Extracts the cached element snapshot from its query.
No requests to the accessiblity framework is made.
Expand Down
35 changes: 25 additions & 10 deletions WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,7 @@ @implementation XCUIElement (FBUtilities)
? [self.fb_query fb_uniqueSnapshotWithError:&error]
: (id<FBXCElementSnapshot>)[self snapshotWithError:&error];
if (nil == snapshot) {
NSString *hintText = @"Make sure the application UI has the expected state";
if (nil != error && [error.localizedDescription containsString:@"Identity Binding"]) {
hintText = [NSString stringWithFormat:@"%@. You could also try to switch the binding strategy using the 'boundElementsByIndex' setting for the element lookup", hintText];
}
NSString *reason = [NSString stringWithFormat:@"The previously found element \"%@\" is not present in the current view anymore. %@",
self.description, hintText];
if (nil != error) {
reason = [NSString stringWithFormat:@"%@. Original error: %@", reason, error.localizedDescription];
}
@throw [NSException exceptionWithName:FBStaleElementException reason:reason userInfo:@{}];
[self fb_raiseStaleElementExceptionWithError:error];
}
}
self.lastSnapshot = snapshot;
Expand All @@ -79,6 +70,16 @@ @implementation XCUIElement (FBUtilities)
return [self fb_takeSnapshot:YES];
}

- (id<FBXCElementSnapshot>)fb_nativeSnapshot
{
NSError *error = nil;
BOOL isSuccessful = [self resolveOrRaiseTestFailure:NO error:&error];
if (nil == self.lastSnapshot || !isSuccessful) {
[self fb_raiseStaleElementExceptionWithError:error];
}
return self.lastSnapshot;
}

- (id<FBXCElementSnapshot>)fb_cachedSnapshot
{
return [self.query fb_cachedSnapshot];
Expand Down Expand Up @@ -153,4 +154,18 @@ - (void)fb_waitUntilStableWithTimeout:(NSTimeInterval)timeout
FBConfiguration.waitForIdleTimeout = previousTimeout;
}

- (void)fb_raiseStaleElementExceptionWithError:(NSError *)error __attribute__((noreturn))
{
NSString *hintText = @"Make sure the application UI has the expected state";
if (nil != error && [error.localizedDescription containsString:@"Identity Binding"]) {
hintText = [NSString stringWithFormat:@"%@. You could also try to switch the binding strategy using the 'boundElementsByIndex' setting for the element lookup", hintText];
}
NSString *reason = [NSString stringWithFormat:@"The previously found element \"%@\" is not present in the current view anymore. %@",
self.description, hintText];
if (nil != error) {
reason = [NSString stringWithFormat:@"%@. Original error: %@", reason, error.localizedDescription];
}
@throw [NSException exceptionWithName:FBStaleElementException reason:reason userInfo:@{}];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ @implementation XCUIElement (WebDriverAttributesForwarding)

- (id<FBXCElementSnapshot>)fb_snapshotForAttributeName:(NSString *)name
{
// https://github.com/appium/appium-xcuitest-driver/pull/2565
if ([name isEqualToString:FBStringify(XCUIElement, isWDHittable)]) {
return [self fb_nativeSnapshot];
}
// https://github.com/appium/appium-xcuitest-driver/issues/2552
BOOL isValueRequest = [name isEqualToString:FBStringify(XCUIElement, wdValue)];
if ([self isKindOfClass:XCUIApplication.class] && !isValueRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#import "XCUIElement+FBAccessibility.h"
#import "XCUIElement+FBIsVisible.h"
#import "XCUIElement+FBWebDriverAttributes.h"
#import "FBXCodeCompatibility.h"

@interface FBElementAttributeTests : FBIntegrationTestCase
@end
Expand Down Expand Up @@ -157,7 +156,7 @@ - (void)testSwitchAttributes
XCTAssertNil(element.wdPlaceholderValue);
XCTAssertEqualObjects(element.wdValue, @"1");
XCTAssertFalse(element.wdSelected);
XCTAssertTrue(element.wdHittable);
XCTAssertEqual(element.wdHittable, element.hittable);
[element tap];
XCTAssertEqualObjects(element.wdValue, @"0");
XCTAssertFalse(element.wdSelected);
Expand Down
5 changes: 4 additions & 1 deletion WebDriverAgentTests/IntegrationTests/FBScrollingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#import "FBMacros.h"
#import "XCUIElement+FBIsVisible.h"
#import "XCUIElement+FBScrolling.h"

#import "XCUIElement+FBClassChain.h"
#import "FBXCodeCompatibility.h"

Expand Down Expand Up @@ -43,8 +42,12 @@ - (void)testCellVisibility
{
FBAssertVisibleCell(@"0");
FBAssertVisibleCell(@"10");
XCUIElement *cell10 = FBCellElementWithLabel(@"10");
XCTAssertEqual([cell10 isWDHittable], [cell10 isHittable]);
FBAssertInvisibleCell(@"30");
FBAssertInvisibleCell(@"50");
XCUIElement *cell50 = FBCellElementWithLabel(@"50");
XCTAssertEqual([cell50 isWDHittable], [cell50 isHittable]);
}

- (void)testSimpleScroll
Expand Down
Loading