FBXCElementSnapshotWrapper+Helpers.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Copyright (c) 2018-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 "FBXCElementSnapshotWrapper.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. @interface FBXCElementSnapshotWrapper (Helpers)
  12. /**
  13. Returns an array of descendants matching given type
  14. @param type requested descendant type
  15. @return an array of descendants matching given type
  16. */
  17. - (NSArray<id<FBXCElementSnapshot>> *)fb_descendantsMatchingType:(XCUIElementType)type;
  18. /**
  19. Returns first (going up element tree) parent that matches given type. If non found returns nil.
  20. @param type requested parent type
  21. @return parent element matching given type
  22. */
  23. - (nullable id<FBXCElementSnapshot>)fb_parentMatchingType:(XCUIElementType)type;
  24. /**
  25. Returns first (going up element tree) parent that matches one of given types. If non found returns nil.
  26. @param types possible parent types
  27. @return parent element matching one of given types
  28. */
  29. - (nullable id<FBXCElementSnapshot>)fb_parentMatchingOneOfTypes:(NSArray<NSNumber *> *)types;
  30. /**
  31. Returns first (going up element tree) visible parent that matches one of given types and has more than one child. If non found returns nil.
  32. @param types possible parent types
  33. @param filter will filter results even further after matching one of given types
  34. @return parent element matching one of given types and satisfying filter condition
  35. */
  36. - (nullable id<FBXCElementSnapshot>)fb_parentMatchingOneOfTypes:(NSArray<NSNumber *> *)types filter:(BOOL(^)(id<FBXCElementSnapshot> snapshot))filter;
  37. /**
  38. Retrieves the list of all element ancestors in the snapshot hierarchy.
  39. @return the list of element ancestors or an empty list if the snapshot has no parent.
  40. */
  41. - (NSArray<id<FBXCElementSnapshot>> *)fb_ancestors;
  42. /**
  43. Returns value for given accessibility property identifier.
  44. @param attribute attribute's accessibility identifier. Can be one of
  45. `XC_kAXXCAttribute`-prefixed attribute names.
  46. @return value for given accessibility property identifier
  47. */
  48. - (nullable id)fb_attributeValue:(NSString *)attribute;
  49. /**
  50. Method used to determine whether given element matches receiver by comparing it's parameters except frame.
  51. @param snapshot element's snapshot to compare against
  52. @return YES, if they match otherwise NO
  53. */
  54. - (BOOL)fb_framelessFuzzyMatchesElement:(id<FBXCElementSnapshot>)snapshot;
  55. /**
  56. Returns an array of descendants cell snapshots
  57. @return an array of descendants cell snapshots
  58. */
  59. - (NSArray<id<FBXCElementSnapshot>> *)fb_descendantsCellSnapshots;
  60. /**
  61. Returns itself if it is either XCUIElementTypeIcon or XCUIElementTypeCell. Otherwise, returns first (going up element tree) parent that matches cell (XCUIElementTypeCell or XCUIElementTypeIcon). If non found returns nil.
  62. @return parent element matching either XCUIElementTypeIcon or XCUIElementTypeCell.
  63. */
  64. - (nullable id<FBXCElementSnapshot>)fb_parentCellSnapshot;
  65. /**! Human-readable snapshot description */
  66. - (NSString *)fb_description;
  67. /**
  68. Returns the snapshot visibleFrame with a fallback to direct attribute retrieval from FBXCAXClient in case of a snapshot fault (nil visibleFrame)
  69. @return the snapshot visibleFrame
  70. */
  71. - (CGRect)fb_visibleFrameWithFallback;
  72. /**
  73. Wrapper for Apple's hitpoint, thats resolves few known issues
  74. @return Element's hitpoint if exists nil otherwise
  75. */
  76. - (nullable NSValue *)fb_hitPoint;
  77. @end
  78. NS_ASSUME_NONNULL_END