diff --git a/WebDriverAgentLib/Commands/FBCustomCommands.m b/WebDriverAgentLib/Commands/FBCustomCommands.m index bb64907502..c562f8e837 100644 --- a/WebDriverAgentLib/Commands/FBCustomCommands.m +++ b/WebDriverAgentLib/Commands/FBCustomCommands.m @@ -38,6 +38,8 @@ + (NSArray *)routes [[FBRoute POST:@"/wda/homescreen"].withoutSession respondWithTarget:self action:@selector(handleHomescreenCommand:)], [[FBRoute POST:@"/wda/deactivateApp"] respondWithTarget:self action:@selector(handleDeactivateAppCommand:)], [[FBRoute POST:@"/wda/keyboard/dismiss"] respondWithTarget:self action:@selector(handleDismissKeyboardCommand:)], + [[FBRoute GET:@"/wda/elementCache/size"] respondWithTarget:self action:@selector(handleGetElementCacheSizeCommand:)], + [[FBRoute POST:@"/wda/elementCache/clear"] respondWithTarget:self action:@selector(handleClearElementCacheCommand:)], ]; } @@ -93,4 +95,16 @@ + (NSArray *)routes return FBResponseWithOK(); } ++ (id)handleGetElementCacheSizeCommand:(FBRouteRequest *)request +{ + NSNumber *count = [NSNumber numberWithUnsignedInteger:[request.session.elementCache count]]; + return FBResponseWithObject(count); +} + ++ (id)handleClearElementCacheCommand:(FBRouteRequest *)request +{ + FBElementCache *elementCache = request.session.elementCache; + [elementCache clear]; + return FBResponseWithOK(); +} @end diff --git a/WebDriverAgentLib/Routing/FBElementCache.h b/WebDriverAgentLib/Routing/FBElementCache.h index bfc6e0986f..be3d3f69bc 100644 --- a/WebDriverAgentLib/Routing/FBElementCache.h +++ b/WebDriverAgentLib/Routing/FBElementCache.h @@ -31,6 +31,15 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable XCUIElement *)elementForUUID:(NSString *__nullable)uuid; +/** + Clears the cache + */ +- (void)clear; + +/** + Gets the number of elements in the cache + */ +@property (nonatomic, readonly) NSUInteger count; @end NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Routing/FBElementCache.m b/WebDriverAgentLib/Routing/FBElementCache.m index 745b519f53..54000ac3d8 100644 --- a/WebDriverAgentLib/Routing/FBElementCache.m +++ b/WebDriverAgentLib/Routing/FBElementCache.m @@ -47,4 +47,13 @@ - (XCUIElement *)elementForUUID:(NSString *)uuid return element; } +- (void)clear +{ + [self.elementCache removeAllObjects]; +} + +- (NSUInteger)count +{ + return [self.elementCache count]; +} @end