XCUIElement+FBUtilities.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <XCTest/XCTest.h>
  10. #import <WebDriverAgentLib/FBElement.h>
  11. #import <WebDriverAgentLib/FBXCElementSnapshot.h>
  12. NS_ASSUME_NONNULL_BEGIN
  13. @interface XCUIElement (FBUtilities)
  14. /**
  15. Gets the most recent snapshot of the current element. The element will be
  16. automatically resolved if the snapshot is not available yet.
  17. Calls to this method mutate the `lastSnapshot` instance property.
  18. The snapshot is taken by the native API provided by XCTest.
  19. The maximum snapshot tree depth is set by `FBConfiguration.snapshotMaxDepth`
  20. Snapshot specifics:
  21. - Most performant
  22. - Memory-friedly
  23. - `children` property is set to `nil` if not taken from XCUIApplication
  24. - `value` property is cut off to max 512 bytes
  25. @return The recent snapshot of the element
  26. @throws FBStaleElementException if the element is not present in DOM and thus no snapshot could be made
  27. */
  28. - (id<FBXCElementSnapshot>)fb_standardSnapshot;
  29. /**
  30. Gets the most recent snapshot of the current element. The element will be
  31. automatically resolved if the snapshot is not available yet.
  32. Calls to this method mutate the `lastSnapshot` instance property.
  33. The maximum snapshot tree depth is set by `FBConfiguration.snapshotMaxDepth`
  34. Snapshot specifics:
  35. - Less performant in comparison to the standard one
  36. - `children` property is always defined
  37. - `value` property is not cut off
  38. @return The recent snapshot of the element
  39. @throws FBStaleElementException if the element is not present in DOM and thus no snapshot could be made
  40. */
  41. - (id<FBXCElementSnapshot>)fb_customSnapshot;
  42. /**
  43. Gets the most recent snapshot of the current element. The element will be
  44. automatically resolved if the snapshot is not available yet.
  45. Calls to this method mutate the `lastSnapshot` instance property.
  46. The maximum snapshot tree depth is set by `FBConfiguration.snapshotMaxDepth`
  47. Snapshot specifics:
  48. - Less performant in comparison to the standard one
  49. - The `hittable` property calculation is aligned with the native calculation logic
  50. @return The recent snapshot of the element
  51. @throws FBStaleElementException if the element is not present in DOM and thus no snapshot could be made
  52. */
  53. - (id<FBXCElementSnapshot>)fb_nativeSnapshot;
  54. /**
  55. Extracts the cached element snapshot from its query.
  56. No requests to the accessiblity framework is made.
  57. It is only safe to use this call right after element lookup query
  58. has been executed.
  59. @return Either the cached snapshot or nil
  60. */
  61. - (nullable id<FBXCElementSnapshot>)fb_cachedSnapshot;
  62. /**
  63. Filters elements by matching them to snapshots from the corresponding array
  64. @param snapshots Array of snapshots to be matched with
  65. @param onlyChildren Whether to only look for direct element children
  66. @return Array of filtered elements, which have matches in snapshots array
  67. */
  68. - (NSArray<XCUIElement *> *)fb_filterDescendantsWithSnapshots:(NSArray<id<FBXCElementSnapshot>> *)snapshots
  69. onlyChildren:(BOOL)onlyChildren;
  70. /**
  71. Waits until element snapshot is stable to avoid "Error copying attributes -25202 error".
  72. This error usually happens for testmanagerd if there is an active UI animation in progress and
  73. causes 15-seconds delay while getting hitpoint value of element's snapshot.
  74. */
  75. - (void)fb_waitUntilStable;
  76. /**
  77. Waits for receiver's snapshot to become stable with the given timeout
  78. @param timeout The max time to wait util the snapshot is stable
  79. */
  80. - (void)fb_waitUntilStableWithTimeout:(NSTimeInterval)timeout;
  81. @end
  82. NS_ASSUME_NONNULL_END