FBBaseActionsSynthesizer.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "FBElementCache.h"
  10. #import "FBXCElementSnapshot.h"
  11. #import "XCUIApplication.h"
  12. #import "XCSynthesizedEventRecord.h"
  13. NS_ASSUME_NONNULL_BEGIN
  14. #if !TARGET_OS_TV
  15. @interface FBBaseActionItem : NSObject
  16. /*! Raw JSON representation of the corresponding action item */
  17. @property (nonatomic) NSDictionary<NSString *, id> *actionItem;
  18. /*! Current application instance */
  19. @property (nonatomic) XCUIApplication *application;
  20. /*! Action offset in the chain in milliseconds */
  21. @property (nonatomic) double offset;
  22. /**
  23. Get the name of the corresponding raw action item. This method is expected to be overriden in subclasses.
  24. @return The corresponding action item key in object's raw JSON reprsentation
  25. */
  26. + (NSString *)actionName;
  27. /**
  28. Add the current gesture to XCPointerEventPath instance. This method is expected to be overriden in subclasses.
  29. @param eventPath The destination XCPointerEventPath instance. If nil value is passed then a new XCPointerEventPath instance is going to be created
  30. @param allItems The existing actions chain to be transformed into event path
  31. @param currentItemIndex The index of the current item in allItems array
  32. @param error If there is an error, upon return contains an NSError object that describes the problem
  33. @return the constructed XCPointerEventPath instance or nil in case of failure
  34. */
  35. - (nullable NSArray<XCPointerEventPath *> *)addToEventPath:(nullable XCPointerEventPath *)eventPath
  36. allItems:(NSArray *)allItems
  37. currentItemIndex:(NSUInteger)currentItemIndex
  38. error:(NSError **)error;
  39. @end
  40. @interface FBBaseGestureItem : FBBaseActionItem
  41. /*! Absolute position on the screen where the gesure should be performed */
  42. @property (nonatomic) XCUICoordinate *atPosition;
  43. /*! Gesture duration in milliseconds */
  44. @property (nonatomic) double duration;
  45. /**
  46. Calculate absolute gesture position on the screen based on provided element and positionOffset values.
  47. @param element The element instance to perform the gesture on. If element equals to nil then positionOffset is considered as absolute coordinates
  48. @param positionOffset The actual coordinate offset. If this calue equals to nil then element's hitpoint is taken as gesture position. If element is not nil then this offset is calculated relatively to the top-left cordner of the element's position
  49. @param error If there is an error, upon return contains an NSError object that describes the problem
  50. @return Adbsolute gesture position on the screen or nil if the calculation fails (for example, the element is invisible)
  51. */
  52. - (nullable XCUICoordinate *)hitpointWithElement:(nullable XCUIElement *)element
  53. positionOffset:(nullable NSValue *)positionOffset
  54. error:(NSError **)error;
  55. @end
  56. @interface FBBaseActionItemsChain : NSObject
  57. /*! All gesture items collected in the chain */
  58. @property (readonly, nonatomic) NSMutableArray *items;
  59. /*! Total length of all the gestures in the chain in milliseconds */
  60. @property (nonatomic) double durationOffset;
  61. /**
  62. Add a new gesture item to the current chain. The method is expected to be overriden in subclasses.
  63. @param item The actual gesture instance to be added
  64. */
  65. - (void)addItem:(FBBaseActionItem *)item;
  66. /**
  67. Represents the chain as XCPointerEventPath instance.
  68. @param error If there is an error, upon return contains an NSError object that describes the problem
  69. @return The constructed array of XCPointerEventPath instances or nil if there was a failure
  70. */
  71. - (nullable NSArray<XCPointerEventPath *> *)asEventPathsWithError:(NSError **)error;
  72. @end
  73. @interface FBBaseActionsSynthesizer : NSObject
  74. /*! Raw actions chain received from request's JSON */
  75. @property (readonly, nonatomic) NSArray *actions;
  76. /*! Current application instance */
  77. @property (readonly, nonatomic) XCUIApplication *application;
  78. /*! Current elements cache */
  79. @property (readonly, nonatomic, nullable) FBElementCache *elementCache;
  80. /**
  81. Initializes actions synthesizer. This initializer should be used only by subclasses.
  82. @param actions The raw actions chain received from request's JSON. The format of this chain is defined by the standard, implemented in the correspoding subclass.
  83. @param application Current application instance
  84. @param elementCache Elements cache, which is used to replace elements references in the chain with their instances. We assume the chain already contains element instances if this parameter is set to nil
  85. @param error If there is an error, upon return contains an NSError object that describes the problem
  86. @return The corresponding synthesizer instance or nil in case of failure (for example if `actions` is nil or empty)
  87. */
  88. - (nullable instancetype)initWithActions:(NSArray *)actions
  89. forApplication:(XCUIApplication *)application
  90. elementCache:(nullable FBElementCache *)elementCache
  91. error:(NSError **)error;
  92. /**
  93. Synthesizes XCTest-compatible event record to be performed in the UI. This method is supposed to be overriden by subclasses.
  94. @param error If there is an error, upon return contains an NSError object that describes the problem
  95. @return The generated event record or nil in case of failure
  96. */
  97. - (nullable XCSynthesizedEventRecord *)synthesizeWithError:(NSError **)error;
  98. @end
  99. #endif
  100. NS_ASSUME_NONNULL_END