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
6 changes: 2 additions & 4 deletions WebDriverAgentLib/Categories/XCUIElement+FBClassChain.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ - (XCUIElementQuery *)fb_queryWithChainItem:(FBClassChainItem *)item query:(null
- (NSArray<XCUIElement *> *)fb_snapshotDescendantsMatchingChainItems:(NSArray<FBClassChainItem *> *)chainItems shouldReturnAfterFirstMatch:(BOOL)shouldReturnAfterFirstMatch
{
NSMutableArray<FBClassChainItem *> *lookupChain = chainItems.mutableCopy;
// Reuse an already-taken snapshot of `self` if one is available (e.g. the
// caller just resolved/inspected this same element) instead of always
// paying for a fresh one.
NSArray<id<FBXCElementSnapshot>> *currentRoots = @[self.lastSnapshot ?: self.fb_cachedSnapshot ?: [self fb_customSnapshot]];
// self.lastSnapshot may be stale leftover from an unrelated earlier command.
NSArray<id<FBXCElementSnapshot>> *currentRoots = @[self.fb_cachedSnapshot ?: [self fb_customSnapshot]];
FBClassChainItem *chainItem = lookupChain.firstObject;
NSArray<id<FBXCElementSnapshot>> *candidates = [self.class fb_snapshotsMatchingItem:chainItem inRoots:currentRoots];
[lookupChain removeObjectAtIndex:0];
Expand Down
6 changes: 4 additions & 2 deletions WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ @implementation XCUIElement (FBUtilities)
}
}
NSMutableArray<XCUIElement *> *matchedElements = [NSMutableArray array];
NSString *uid = nil == self.lastSnapshot
// self.lastSnapshot may be stale leftover from an unrelated earlier command.
id<FBXCElementSnapshot> selfSnapshot = self.fb_cachedSnapshot;
NSString *uid = nil == selfSnapshot
? self.fb_uid
: [FBXCElementSnapshotWrapper wdUIDWithSnapshot:self.lastSnapshot];
: [FBXCElementSnapshotWrapper wdUIDWithSnapshot:selfSnapshot];
if (nil != uid && [matchedIds containsObject:uid]) {
XCUIElement *stableSelf = [self fb_stableInstanceWithUid:uid];
if (1 == snapshots.count) {
Expand Down
5 changes: 3 additions & 2 deletions WebDriverAgentLib/Utilities/FBXPath.m
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ + (nullable NSString *)xmlStringWithRootElement:(id<FBElement>)root
if ([root isKindOfClass:XCUIElement.class]) {
lookupScopeSnapshot = [self snapshotWithRoot:[(XCUIElement *)root application]
useNative:useNativeSnapshot];
// root.lastSnapshot may be stale leftover from an unrelated earlier command.
contextRootSnapshot = [root isKindOfClass:XCUIApplication.class]
? nil
: ([(XCUIElement *)root lastSnapshot] ?: [self snapshotWithRoot:(XCUIElement *)root
useNative:useNativeSnapshot]);
: ([(XCUIElement *)root fb_cachedSnapshot] ?: [self snapshotWithRoot:(XCUIElement *)root
useNative:useNativeSnapshot]);
} else {
lookupScopeSnapshot = (id<FBXCElementSnapshot>)root;
contextRootSnapshot = nil == lookupScopeSnapshot.parent ? nil : (id<FBXCElementSnapshot>)root;
Expand Down
22 changes: 22 additions & 0 deletions WebDriverAgentTests/IntegrationTests/XCUIElementFBFindTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "XCUIElement+FBResolve.h"
#import "FBXPath.h"
#import "FBXCodeCompatibility.h"
#import "XCUIElement+FBUtilities.h"

@interface XCUIElementFBFindTests : FBIntegrationTestCase
@property (nonatomic, strong) XCUIElement *testedView;
Expand Down Expand Up @@ -536,3 +537,24 @@ - (void)testPerformanceOfClassChainLookupOnDeepHierarchy
}

@end

@interface XCUIElementFBFindTests_StaleAppSnapshot : FBIntegrationTestCase
@end
@implementation XCUIElementFBFindTests_StaleAppSnapshot

// Regression test for https://github.com/appium/appium/issues/22672.
- (void)testClassChainWithIntermediatePositionAfterStaleAppSnapshot
{
[self launchApplication];
// Simulates a stale snapshot cached by an earlier, unrelated command (e.g. GET /source).
[self.testedApplication fb_customSnapshot];
[self goToDeepHierarchyPage];

NSString *query = @"**/XCUIElementTypeOther[`label == \"View 10\"`][1]/**/XCUIElementTypeOther[`label BEGINSWITH \"View 19\"`]";
NSArray<XCUIElement *> *matches = [self.testedApplication fb_descendantsMatchingClassChain:query
shouldReturnAfterFirstMatch:NO];
XCTAssertEqual(matches.count, 1);
XCTAssertEqualObjects(matches.firstObject.label, @"View 19");
}

@end
Loading