XCUIElement+FBUtilities.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "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. Calls to this method reset the `fb_isResolvedFromCache` property value to `NO`.
  19. @return The recent snapshot of the element
  20. @throws FBStaleElementException if the element is not present in DOM and thus no snapshot could be made
  21. */
  22. - (id<FBXCElementSnapshot>)fb_takeSnapshot;
  23. /**
  24. Extracts the cached element snapshot from its query.
  25. No requests to the accessiblity framework is made.
  26. It is only safe to use this call right after element lookup query
  27. has been executed.
  28. @return Either the cached snapshot or nil
  29. */
  30. - (nullable id<FBXCElementSnapshot>)fb_cachedSnapshot;
  31. /**
  32. Gets the most recent snapshot of the current element and already resolves the accessibility attributes
  33. needed for creating the page source of this element. No additional calls to the accessibility layer
  34. are required.
  35. Calls to this method mutate the `lastSnapshot` instance property.
  36. Calls to this method reset the `fb_isResolvedFromCache` property value to `NO`.
  37. @param maxDepth The maximum depth of the snapshot. nil value means to use the default depth.
  38. with custom attributes cannot be resolved
  39. @return The recent snapshot of the element with all attributes resolved or a snapshot with default
  40. attributes resolved if there was a failure while resolving additional attributes
  41. @throws FBStaleElementException if the element is not present in DOM and thus no snapshot could be made
  42. */
  43. - (nullable id<FBXCElementSnapshot>)fb_snapshotWithAllAttributesAndMaxDepth:(nullable NSNumber *)maxDepth;
  44. /**
  45. Gets the most recent snapshot of the current element with given attributes resolved.
  46. No additional calls to the accessibility layer are required.
  47. Calls to this method mutate the `lastSnapshot` instance property.
  48. Calls to this method reset the `fb_isResolvedFromCache` property value to `NO`.
  49. @param attributeNames The list of attribute names to resolve. Must be one of
  50. FB_...Name values exported by XCTestPrivateSymbols.h module.
  51. `nil` value means that only the default attributes must be extracted
  52. @param maxDepth The maximum depth of the snapshot. nil value means to use the default depth.
  53. @return The recent snapshot of the element with the given attributes resolved or a snapshot with default
  54. attributes resolved if there was a failure while resolving additional attributes
  55. @throws FBStaleElementException if the element is not present in DOM and thus no snapshot could be made
  56. */
  57. - (nullable id<FBXCElementSnapshot>)fb_snapshotWithAttributes:(nullable NSArray<NSString *> *)attributeNames
  58. maxDepth:(nullable NSNumber *)maxDepth;
  59. /**
  60. Filters elements by matching them to snapshots from the corresponding array
  61. @param snapshots Array of snapshots to be matched with
  62. @param selfUID Optionally the unique identifier of the current element.
  63. Providing it as an argument improves the performance of the method.
  64. @param onlyChildren Whether to only look for direct element children
  65. @return Array of filtered elements, which have matches in snapshots array
  66. */
  67. - (NSArray<XCUIElement *> *)fb_filterDescendantsWithSnapshots:(NSArray<id<FBXCElementSnapshot>> *)snapshots
  68. selfUID:(nullable NSString *)selfUID
  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