FBXCElementSnapshotWrapper+Helpers.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. @param error Error instance in case of a failure
  47. @return value for given accessibility property identifier or nil in case of failure
  48. */
  49. - (nullable id)fb_attributeValue:(NSString *)attribute
  50. error:(NSError **)error;
  51. /**
  52. Method used to determine whether given element matches receiver by comparing it's parameters except frame.
  53. @param snapshot element's snapshot to compare against
  54. @return YES, if they match otherwise NO
  55. */
  56. - (BOOL)fb_framelessFuzzyMatchesElement:(id<FBXCElementSnapshot>)snapshot;
  57. /**
  58. Returns an array of descendants cell snapshots
  59. @return an array of descendants cell snapshots
  60. */
  61. - (NSArray<id<FBXCElementSnapshot>> *)fb_descendantsCellSnapshots;
  62. /**
  63. 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.
  64. @return parent element matching either XCUIElementTypeIcon or XCUIElementTypeCell.
  65. */
  66. - (nullable id<FBXCElementSnapshot>)fb_parentCellSnapshot;
  67. /**! Human-readable snapshot description */
  68. - (NSString *)fb_description;
  69. /**
  70. Wrapper for Apple's hitpoint, thats resolves few known issues
  71. @return Element's hitpoint if exists nil otherwise
  72. */
  73. - (nullable NSValue *)fb_hitPoint;
  74. @end
  75. NS_ASSUME_NONNULL_END