FBConfiguration.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. NS_ASSUME_NONNULL_BEGIN
  11. extern NSString *const FBSnapshotMaxDepthKey;
  12. /**
  13. Accessors for Global Constants.
  14. */
  15. @interface FBConfiguration : NSObject
  16. /*! If set to YES will ask TestManagerDaemon for element visibility */
  17. + (void)setShouldUseTestManagerForVisibilityDetection:(BOOL)value;
  18. + (BOOL)shouldUseTestManagerForVisibilityDetection;
  19. /*! If set to YES will use compact (standards-compliant) & faster responses */
  20. + (void)setShouldUseCompactResponses:(BOOL)value;
  21. + (BOOL)shouldUseCompactResponses;
  22. /*! If set to YES (which is the default), the app will be terminated at the end of the session, if a bundleId was specified */
  23. + (void)setShouldTerminateApp:(BOOL)value;
  24. + (BOOL)shouldTerminateApp;
  25. /*! If shouldUseCompactResponses == NO, is the comma-separated list of fields to return with each element. Defaults to "type,label". */
  26. + (void)setElementResponseAttributes:(NSString *)value;
  27. + (NSString *)elementResponseAttributes;
  28. /*! Disables remote query evaluation making Xcode 9.x tests behave same as Xcode 8.x test */
  29. + (void)disableRemoteQueryEvaluation;
  30. /*! Enables the extended XCTest debug logging. Useful for developemnt purposes */
  31. + (void)enableXcTestDebugLogs;
  32. /*! Disables attribute key path analysis, which will cause XCTest on Xcode 9.x to ignore some elements */
  33. + (void)disableAttributeKeyPathAnalysis;
  34. /*! Disables XCTest automated screenshots taking */
  35. + (void)disableScreenshots;
  36. /*! Enables XCTest automated screenshots taking */
  37. + (void)enableScreenshots;
  38. /*! Disables XCTest automated videos taking (iOS 17+) */
  39. + (void)disableScreenRecordings;
  40. /*! Enables XCTest automated videos taking (iOS 17+) */
  41. + (void)enableScreenRecordings;
  42. /* The maximum typing frequency for all typing activities */
  43. + (void)setMaxTypingFrequency:(NSUInteger)value;
  44. + (NSUInteger)maxTypingFrequency;
  45. + (NSUInteger)defaultTypingFrequency;
  46. /* Use singleton test manager proxy */
  47. + (void)setShouldUseSingletonTestManager:(BOOL)value;
  48. + (BOOL)shouldUseSingletonTestManager;
  49. /* Enforces WDA to verify the presense of system alerts while checking for an active app */
  50. + (void)setShouldRespectSystemAlerts:(BOOL)value;
  51. + (BOOL)shouldRespectSystemAlerts;
  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. Whether to limit the XPath scope to descendant items only while performing a lookup
  87. in an element context. Enabled by default. Being disabled, allows to use XPath locators
  88. like ".." in order to match parent items of the current context root.
  89. */
  90. + (BOOL)limitXpathContextScope;
  91. + (void)setLimitXpathContextScope:(BOOL)enabled;
  92. /**
  93. The quality of display screenshots. The higher quality you set is the bigger screenshot size is.
  94. The highest quality value is 0 (lossless PNG) or 3 (lossless HEIC). The lowest quality is 2 (highly compressed JPEG).
  95. The default quality value is 3 (lossless HEIC).
  96. See https://developer.apple.com/documentation/xctest/xctimagequality?language=objc
  97. */
  98. + (NSUInteger)screenshotQuality;
  99. + (void)setScreenshotQuality:(NSUInteger)quality;
  100. /**
  101. The range of ports that the HTTP Server should attempt to bind on launch
  102. */
  103. + (NSRange)bindingPortRange;
  104. /**
  105. The port number where the background screenshots broadcaster is supposed to run
  106. */
  107. + (NSInteger)mjpegServerPort;
  108. /**
  109. The scaling factor for frames of the mjpeg stream. The default (and maximum) value is 100,
  110. which does not perform any scaling. The minimum value must be greater than zero.
  111. ! Setting this to a value less than 100, especially together with orientation fixing enabled
  112. ! may lead to WDA process termination because of an excessive CPU usage.
  113. */
  114. + (CGFloat)mjpegScalingFactor;
  115. + (void)setMjpegScalingFactor:(CGFloat)scalingFactor;
  116. /**
  117. YES if verbose logging is enabled. NO otherwise.
  118. */
  119. + (BOOL)verboseLoggingEnabled;
  120. /**
  121. Disables automatic handling of XCTest UI interruptions.
  122. */
  123. + (void)disableApplicationUIInterruptionsHandling;
  124. /**
  125. * Configure keyboards preference to make test running stable
  126. */
  127. + (void)configureDefaultKeyboardPreferences;
  128. /**
  129. * Turn on softwar keyboard forcefully for simulator.
  130. */
  131. + (void)forceSimulatorSoftwareKeyboardPresence;
  132. /**
  133. Defines keyboard preference enabled status
  134. */
  135. typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) {
  136. FBConfigurationKeyboardPreferenceDisabled = 0,
  137. FBConfigurationKeyboardPreferenceEnabled = 1,
  138. FBConfigurationKeyboardPreferenceNotSupported = 2,
  139. };
  140. /**
  141. * Modify keyboard configuration of 'auto-correction'.
  142. *
  143. * @param isEnabled Turn the configuration on if the value is YES
  144. */
  145. + (void)setKeyboardAutocorrection:(BOOL)isEnabled;
  146. + (FBConfigurationKeyboardPreference)keyboardAutocorrection;
  147. /**
  148. * Modify keyboard configuration of 'predictive'
  149. *
  150. * @param isEnabled Turn the configuration on if the value is YES
  151. */
  152. + (void)setKeyboardPrediction:(BOOL)isEnabled;
  153. + (FBConfigurationKeyboardPreference)keyboardPrediction;
  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. /**
  241. Sets class chain selector to apply for an automated alert click
  242. */
  243. + (void)setAutoClickAlertSelector:(NSString *)classChainSelector;
  244. + (NSString *)autoClickAlertSelector;
  245. /**
  246. * Whether to use HIDEvent for text clear.
  247. * By default this is enabled and HIDEvent is used for text clear.
  248. *
  249. * @param enabled Either YES or NO
  250. */
  251. + (void)setUseClearTextShortcut:(BOOL)enabled;
  252. + (BOOL)useClearTextShortcut;
  253. #if !TARGET_OS_TV
  254. /**
  255. Set the screenshot orientation for iOS
  256. It helps to fix the screenshot orientation when the device under test's orientation changes.
  257. For example, when a device changes to the landscape, the screenshot orientation could be wrong.
  258. Then, this setting can force change the screenshot orientation.
  259. Xcode versions, OS versions or device models and simulator or real device could influence it.
  260. @param orientation Set the orientation to adjust the screenshot.
  261. Case insensitive "portrait", "portraitUpsideDown", "landscapeRight" and "landscapeLeft" are available
  262. to force the coodinate adjust. Other words are handled as "auto", which handles
  263. the adjustment automatically. Defaults to "auto".
  264. @param error If no availale orientation strategy was given, it returns an NSError object that describes the problem.
  265. */
  266. + (BOOL)setScreenshotOrientation:(NSString *)orientation error:(NSError **)error;
  267. /**
  268. @return The value of UIInterfaceOrientation
  269. */
  270. + (NSInteger)screenshotOrientation;
  271. /**
  272. @return The orientation as String for human read
  273. */
  274. + (NSString *)humanReadableScreenshotOrientation;
  275. #endif
  276. /**
  277. Resets all session-specific settings to their default values
  278. */
  279. + (void)resetSessionSettings;
  280. /**
  281. * Whether to calculate `hittable` attribute using native APIs
  282. * instead of legacy heuristics.
  283. * This flag improves accuracy, but may affect performance.
  284. * Disabled by default.
  285. *
  286. * @param enabled Either YES or NO
  287. */
  288. + (void)setIncludeHittableInPageSource:(BOOL)enabled;
  289. + (BOOL)includeHittableInPageSource;
  290. /**
  291. * Whether to include `nativeFrame` attribute in the XML page source.
  292. *
  293. * When enabled, the XML representation will contain the precise rendered
  294. * frame of the UI element.
  295. *
  296. * This value is more accurate than the legacy `wdFrame`, which applies rounding
  297. * and may introduce inconsistencies in size and position calculations.
  298. *
  299. * The value is disabled by default to avoid potential performance overhead.
  300. *
  301. * @param enabled Either YES or NO
  302. */
  303. + (void)setIncludeNativeFrameInPageSource:(BOOL)enabled;
  304. + (BOOL)includeNativeFrameInPageSource;
  305. /**
  306. * Whether to include `minValue`/`maxValue` attributes in the page source.
  307. * These attributes are retrieved from native element snapshots and represent
  308. * value boundaries for elements like sliders or progress indicators.
  309. * This may affect performance if used on many elements.
  310. * Disabled by default.
  311. *
  312. * @param enabled Either YES or NO
  313. */
  314. + (void)setIncludeMinMaxValueInPageSource:(BOOL)enabled;
  315. + (BOOL)includeMinMaxValueInPageSource;
  316. @end
  317. NS_ASSUME_NONNULL_END