FBElementCache.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import <Foundation/Foundation.h>
  10. @class XCUIElement;
  11. NS_ASSUME_NONNULL_BEGIN
  12. // This constant defines the size of the element cache, which puts an upper limit
  13. // on the amount of elements which can be stored in the cache.
  14. // Based on the data in https://github.com/facebook/WebDriverAgent/pull/896, each
  15. // element consumes about 100KB of memory; so 1024 elements would consume 100 MB of
  16. // memory.
  17. extern const int ELEMENT_CACHE_SIZE;
  18. @interface FBElementCache : NSObject
  19. /**
  20. Stores element in cache
  21. @param element element to store
  22. @return element's uuid or nil in case the element uid cannnot be extracted
  23. */
  24. - (nullable NSString *)storeElement:(XCUIElement *)element;
  25. /**
  26. Returns cached element resolved with default snapshot attributes
  27. @param uuid uuid of element to fetch
  28. @return element
  29. @throws FBInvalidArgumentException if uuid is nil
  30. */
  31. - (XCUIElement *)elementForUUID:(NSString *)uuid;
  32. /**
  33. Returns cached element resolved with default snapshot attributes
  34. @param uuid uuid of element to fetch
  35. @param checkStaleness Whether to throw FBStaleElementException if the found element is not present in DOM anymore
  36. @return element
  37. @throws FBStaleElementException if `checkStaleness` is enabled
  38. @throws FBInvalidArgumentException if uuid is nil
  39. */
  40. - (XCUIElement *)elementForUUID:(NSString *)uuid checkStaleness:(BOOL)checkStaleness;
  41. /**
  42. Checks element existence in the cache
  43. @returns YES if the element with the given UUID is present in cache
  44. */
  45. - (BOOL)hasElementWithUUID:(nullable NSString *)uuid;
  46. @end
  47. NS_ASSUME_NONNULL_END