FBConfiguration.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 <Foundation/Foundation.h>
  10. #import "AXSettings.h"
  11. #import "UIKeyboardImpl.h"
  12. #import "TIPreferencesController.h"
  13. NS_ASSUME_NONNULL_BEGIN
  14. extern NSString *const FBSnapshotMaxDepthKey;
  15. /**
  16. Accessors for Global Constants.
  17. */
  18. @interface FBConfiguration : NSObject
  19. /*! If set to YES will ask TestManagerDaemon for element visibility */
  20. + (void)setShouldUseTestManagerForVisibilityDetection:(BOOL)value;
  21. + (BOOL)shouldUseTestManagerForVisibilityDetection;
  22. /*! If set to YES will use compact (standards-compliant) & faster responses */
  23. + (void)setShouldUseCompactResponses:(BOOL)value;
  24. + (BOOL)shouldUseCompactResponses;
  25. /*! If set to YES (which is the default), the app will be terminated at the end of the session, if a bundleId was specified */
  26. + (void)setShouldTerminateApp:(BOOL)value;
  27. + (BOOL)shouldTerminateApp;
  28. /*! If shouldUseCompactResponses == NO, is the comma-separated list of fields to return with each element. Defaults to "type,label". */
  29. + (void)setElementResponseAttributes:(NSString *)value;
  30. + (NSString *)elementResponseAttributes;
  31. /*! Disables remote query evaluation making Xcode 9.x tests behave same as Xcode 8.x test */
  32. + (void)disableRemoteQueryEvaluation;
  33. /*! Enables the extended XCTest debug logging. Useful for developemnt purposes */
  34. + (void)enableXcTestDebugLogs;
  35. /*! Disables attribute key path analysis, which will cause XCTest on Xcode 9.x to ignore some elements */
  36. + (void)disableAttributeKeyPathAnalysis;
  37. /*! Disables XCTest automated screenshots taking */
  38. + (void)disableScreenshots;
  39. /*! Enables XCTest automated screenshots taking */
  40. + (void)enableScreenshots;
  41. /*! Disables XCTest automated videos taking (iOS 17+) */
  42. + (void)disableScreenRecordings;
  43. /*! Enables XCTest automated videos taking (iOS 17+) */
  44. + (void)enableScreenRecordings;
  45. /* The maximum typing frequency for all typing activities */
  46. + (void)setMaxTypingFrequency:(NSUInteger)value;
  47. + (NSUInteger)maxTypingFrequency;
  48. + (NSUInteger)defaultTypingFrequency;
  49. /* Use singleton test manager proxy */
  50. + (void)setShouldUseSingletonTestManager:(BOOL)value;
  51. + (BOOL)shouldUseSingletonTestManager;
  52. /**
  53. * Extract switch value from arguments
  54. *
  55. * @param arguments Array of strings with the command-line arguments, e.g. @[@"--port", @"12345"].
  56. * @param key Switch to look up value for, e.g. @"--port".
  57. *
  58. * @return Switch value or nil if the switch is not present in arguments.
  59. */
  60. + (NSString* _Nullable)valueFromArguments: (NSArray<NSString *> *)arguments forKey: (NSString*)key;
  61. /**
  62. The quality of the screenshots generated by the screenshots broadcaster, expressed
  63. as a value from 0 to 100. The value 0 represents the maximum compression
  64. (or lowest quality) while the value 100 represents the least compression (or best
  65. quality). The default value is 25.
  66. */
  67. + (NSUInteger)mjpegServerScreenshotQuality;
  68. + (void)setMjpegServerScreenshotQuality:(NSUInteger)quality;
  69. /**
  70. Whether to apply orientation fixes to the streamed JPEG images.
  71. This is an expensive operation and it is disabled by default, so screenshots
  72. are returned in portrait, but their actual orientation value could still be found in the EXIF
  73. metadata.
  74. ! Enablement of this setting may lead to WDA process termination because of an excessive CPU usage.
  75. */
  76. + (BOOL)mjpegShouldFixOrientation;
  77. + (void)setMjpegShouldFixOrientation:(BOOL)enabled;
  78. /**
  79. The framerate at which the background screenshots broadcaster should broadcast
  80. screenshots in range 1..60. The default value is 10 (Frames Per Second).
  81. Setting zero value will cause the framerate to be at its maximum possible value.
  82. */
  83. + (NSUInteger)mjpegServerFramerate;
  84. + (void)setMjpegServerFramerate:(NSUInteger)framerate;
  85. /**
  86. The quality of display screenshots. The higher quality you set is the bigger screenshot size is.
  87. The highest quality value is 0 (lossless PNG) or 3 (lossless HEIC). The lowest quality is 2 (highly compressed JPEG).
  88. The default quality value is 3 (lossless HEIC).
  89. See https://developer.apple.com/documentation/xctest/xctimagequality?language=objc
  90. */
  91. + (NSUInteger)screenshotQuality;
  92. + (void)setScreenshotQuality:(NSUInteger)quality;
  93. /**
  94. The range of ports that the HTTP Server should attempt to bind on launch
  95. */
  96. + (NSRange)bindingPortRange;
  97. /**
  98. The port number where the background screenshots broadcaster is supposed to run
  99. */
  100. + (NSInteger)mjpegServerPort;
  101. /**
  102. The scaling factor for frames of the mjpeg stream. The default (and maximum) value is 100,
  103. which does not perform any scaling. The minimum value must be greater than zero.
  104. ! Setting this to a value less than 100, especially together with orientation fixing enabled
  105. ! may lead to WDA process termination because of an excessive CPU usage.
  106. */
  107. + (NSUInteger)mjpegScalingFactor;
  108. + (void)setMjpegScalingFactor:(NSUInteger)scalingFactor;
  109. /**
  110. YES if verbose logging is enabled. NO otherwise.
  111. */
  112. + (BOOL)verboseLoggingEnabled;
  113. /**
  114. Disables automatic handling of XCTest UI interruptions.
  115. */
  116. + (void)disableApplicationUIInterruptionsHandling;
  117. /**
  118. * Configure keyboards preference to make test running stable
  119. */
  120. + (void)configureDefaultKeyboardPreferences;
  121. /**
  122. * Turn on softwar keyboard forcefully for simulator.
  123. */
  124. + (void)forceSimulatorSoftwareKeyboardPresence;
  125. /**
  126. Defines keyboard preference enabled status
  127. */
  128. typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) {
  129. FBConfigurationKeyboardPreferenceDisabled = 0,
  130. FBConfigurationKeyboardPreferenceEnabled = 1,
  131. FBConfigurationKeyboardPreferenceNotSupported = 2,
  132. };
  133. /**
  134. * Modify keyboard configuration of 'auto-correction'.
  135. *
  136. * @param isEnabled Turn the configuration on if the value is YES
  137. */
  138. + (void)setKeyboardAutocorrection:(BOOL)isEnabled;
  139. + (FBConfigurationKeyboardPreference)keyboardAutocorrection;
  140. /**
  141. * Modify keyboard configuration of 'predictive'
  142. *
  143. * @param isEnabled Turn the configuration on if the value is YES
  144. */
  145. + (void)setKeyboardPrediction:(BOOL)isEnabled;
  146. + (FBConfigurationKeyboardPreference)keyboardPrediction;
  147. /**
  148. * The maximum time to wait until accessibility snapshot is taken
  149. *
  150. * @param timeout The number of float seconds to wait (15 seconds by default)
  151. */
  152. + (void)setCustomSnapshotTimeout:(NSTimeInterval)timeout;
  153. + (NSTimeInterval)customSnapshotTimeout;
  154. /**
  155. Sets maximum depth for traversing elements tree from parents to children while requesting XCElementSnapshot.
  156. Used to set maxDepth value in a dictionary provided by XCAXClient_iOS's method defaultParams.
  157. The original XCAXClient_iOS maxDepth value is set to INT_MAX, which is too big for some queries
  158. (for example: searching elements inside a WebView).
  159. Reasonable values are from 15 to 100 (larger numbers make queries slower).
  160. @param maxDepth The number of maximum depth for traversing elements tree
  161. */
  162. + (void)setSnapshotMaxDepth:(int)maxDepth;
  163. /**
  164. @return The number of maximum depth for traversing elements tree
  165. */
  166. + (int)snapshotMaxDepth;
  167. /**
  168. * Whether to use fast search result matching while searching for elements.
  169. * By default this is disabled due to https://github.com/appium/appium/issues/10101
  170. * but it still makes sense to enable it for views containing large counts of elements
  171. *
  172. * @param enabled Either YES or NO
  173. */
  174. + (void)setUseFirstMatch:(BOOL)enabled;
  175. + (BOOL)useFirstMatch;
  176. /**
  177. * Whether to bound the lookup results by index.
  178. * By default this is disabled and bounding by accessibility is used.
  179. * Read https://stackoverflow.com/questions/49307513/meaning-of-allelementsboundbyaccessibilityelement
  180. * for more details on these two bounding methods.
  181. *
  182. * @param enabled Either YES or NO
  183. */
  184. + (void)setBoundElementsByIndex:(BOOL)enabled;
  185. + (BOOL)boundElementsByIndex;
  186. /**
  187. * Modify reduce motion configuration in accessibility.
  188. * It works only for Simulator since Real device has security model which allows chnaging preferences
  189. * only from settings app.
  190. *
  191. * @param isEnabled Turn the configuration on if the value is YES
  192. */
  193. + (void)setReduceMotionEnabled:(BOOL)isEnabled;
  194. + (BOOL)reduceMotionEnabled;
  195. /**
  196. * Set the idling timeout. If the timeout expires then WDA
  197. * tries to interact with the application even if it is not idling.
  198. * Setting it to zero disables idling checks.
  199. * The default timeout is set to 10 seconds.
  200. *
  201. * @param timeout The actual timeout value in float seconds
  202. */
  203. + (void)setWaitForIdleTimeout:(NSTimeInterval)timeout;
  204. + (NSTimeInterval)waitForIdleTimeout;
  205. /**
  206. * Set the idling timeout for different actions, for example events synthesis, rotation change,
  207. * etc. If the timeout expires then WDA tries to interact with the application even if it is not idling.
  208. * Setting it to zero disables idling checks.
  209. * The default timeout is set to 2 seconds.
  210. *
  211. * @param timeout The actual timeout value in float seconds
  212. */
  213. + (void)setAnimationCoolOffTimeout:(NSTimeInterval)timeout;
  214. + (NSTimeInterval)animationCoolOffTimeout;
  215. /**
  216. Enforces the page hierarchy to include non modal elements,
  217. like Contacts. By default such elements are not present there.
  218. See https://github.com/appium/appium/issues/13227
  219. @param isEnabled Set to YES in order to enable non modal elements inclusion.
  220. Setting this value to YES will have no effect if the current iOS SDK does not support such feature.
  221. */
  222. + (void)setIncludeNonModalElements:(BOOL)isEnabled;
  223. + (BOOL)includeNonModalElements;
  224. /**
  225. Sets custom class chain locators for accept/dismiss alert buttons location.
  226. This might be useful if the default buttons detection algorithm fails to determine alert buttons properly
  227. when defaultAlertAction is set.
  228. @param classChainSelector Valid class chain locator, which determines accept/reject button
  229. on the alert. The search root is the alert element itself.
  230. Setting this value to nil or an empty string (the default
  231. value) will enforce WDA to apply the default algorithm for alert buttons location.
  232. If an invalid/non-parseable locator is set then the lookup will fallback to the default algorithm and print a
  233. warning into the log.
  234. Example: ** /XCUIElementTypeButton[`label CONTAINS[c] 'accept'`]
  235. */
  236. + (void)setAcceptAlertButtonSelector:(NSString *)classChainSelector;
  237. + (NSString *)acceptAlertButtonSelector;
  238. + (void)setDismissAlertButtonSelector:(NSString *)classChainSelector;
  239. + (NSString *)dismissAlertButtonSelector;
  240. #if !TARGET_OS_TV
  241. /**
  242. Set the screenshot orientation for iOS
  243. It helps to fix the screenshot orientation when the device under test's orientation changes.
  244. For example, when a device changes to the landscape, the screenshot orientation could be wrong.
  245. Then, this setting can force change the screenshot orientation.
  246. Xcode versions, OS versions or device models and simulator or real device could influence it.
  247. @param orientation Set the orientation to adjust the screenshot.
  248. Case insensitive "portrait", "portraitUpsideDown", "landscapeRight" and "landscapeLeft" are available
  249. to force the coodinate adjust. Other words are handled as "auto", which handles
  250. the adjustment automatically. Defaults to "auto".
  251. @param error If no availale orientation strategy was given, it returns an NSError object that describes the problem.
  252. */
  253. + (BOOL)setScreenshotOrientation:(NSString *)orientation error:(NSError **)error;
  254. /**
  255. @return The value of UIInterfaceOrientation
  256. */
  257. + (NSInteger)screenshotOrientation;
  258. /**
  259. @return The orientation as String for human read
  260. */
  261. + (NSString *)humanReadableScreenshotOrientation;
  262. #endif
  263. /**
  264. Resets all session-specific settings to their default values
  265. */
  266. + (void)resetSessionSettings;
  267. @end
  268. NS_ASSUME_NONNULL_END