XCUIDevice+FBHelpers.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. #if !TARGET_OS_TV
  11. #import <CoreLocation/CoreLocation.h>
  12. #endif
  13. NS_ASSUME_NONNULL_BEGIN
  14. typedef NS_ENUM(NSUInteger, FBUIInterfaceAppearance) {
  15. FBUIInterfaceAppearanceUnspecified,
  16. FBUIInterfaceAppearanceLight,
  17. FBUIInterfaceAppearanceDark
  18. };
  19. @interface XCUIDevice (FBHelpers)
  20. /**
  21. Matches or mismatches TouchID request
  22. @param shouldMatch determines if TouchID should be matched
  23. @return YES if the operation succeeds, otherwise NO.
  24. */
  25. - (BOOL)fb_fingerTouchShouldMatch:(BOOL)shouldMatch;
  26. /**
  27. Forces the device under test to switch to the home screen
  28. @param error If there is an error, upon return contains an NSError object that describes the problem.
  29. @return YES if the operation succeeds, otherwise NO.
  30. */
  31. - (BOOL)fb_goToHomescreenWithError:(NSError **)error;
  32. /**
  33. Checks if the screen is locked or not.
  34. @return YES if screen is locked
  35. */
  36. - (BOOL)fb_isScreenLocked;
  37. /**
  38. Forces the device under test to switch to the lock screen. An immediate return will happen if the device is already locked and an error is going to be thrown if the screen has not been locked after the timeout.
  39. @param error If there is an error, upon return contains an NSError object that describes the problem.
  40. @return YES if the operation succeeds, otherwise NO.
  41. */
  42. - (BOOL)fb_lockScreen:(NSError **)error;
  43. /**
  44. Forces the device under test to unlock. An immediate return will happen if the device is already unlocked and an error is going to be thrown if the screen has not been unlocked after the timeout.
  45. @param error If there is an error, upon return contains an NSError object that describes the problem.
  46. @return YES if the operation succeeds, otherwise NO.
  47. */
  48. - (BOOL)fb_unlockScreen:(NSError **)error;
  49. /**
  50. Returns screenshot
  51. @param error If there is an error, upon return contains an NSError object that describes the problem.
  52. @return Device screenshot as PNG-encoded data or nil in case of failure
  53. */
  54. - (nullable NSData *)fb_screenshotWithError:(NSError*__autoreleasing*)error;
  55. /**
  56. Returns device's current wifi ip4 address
  57. */
  58. - (nullable NSString *)fb_wifiIPAddress;
  59. /**
  60. Opens the particular url scheme using the default application assigned to it.
  61. This API only works since XCode 14.3/iOS 16.4
  62. Older Xcode/iOS version try to use Siri fallback.
  63. @param url The url scheme represented as a string, for example https://apple.com
  64. @param error If there is an error, upon return contains an NSError object that describes the problem.
  65. @return YES if the operation was successful
  66. */
  67. - (BOOL)fb_openUrl:(NSString *)url error:(NSError **)error;
  68. /**
  69. Opens the particular url scheme using the given application
  70. This API only works since XCode 14.3/iOS 16.4
  71. @param url The url scheme represented as a string, for example https://apple.com
  72. @param bundleId The bundle identifier of an application to use in order to open the given URL
  73. @param error If there is an error, upon return contains an NSError object that describes the problem.
  74. @return YES if the operation was successful
  75. */
  76. - (BOOL)fb_openUrl:(NSString *)url withApplication:(NSString *)bundleId error:(NSError **)error;
  77. /**
  78. Presses the corresponding hardware button on the device with duration.
  79. @param buttonName One of the supported button names: volumeUp (real devices only), volumeDown (real device only), home
  80. @param duration Duration in seconds or nil.
  81. This argument works only on tvOS. When this argument is nil on tvOS,
  82. https://developer.apple.com/documentation/xctest/xcuiremote/1627476-pressbutton will be called.
  83. Others are https://developer.apple.com/documentation/xctest/xcuiremote/1627475-pressbutton.
  84. A single tap when this argument is `nil` is equal to when the duration is 0.005 seconds in XCTest.
  85. On iOS, this value will be ignored. It always calls https://developer.apple.com/documentation/xctest/xcuidevice/1619052-pressbutton
  86. @return YES if the button has been pressed
  87. */
  88. - (BOOL)fb_pressButton:(NSString *)buttonName forDuration:(nullable NSNumber *)duration error:(NSError **)error;
  89. /**
  90. Activates Siri service voice recognition with the given text to parse
  91. @param text The actual string to parse
  92. @param error If there is an error, upon return contains an NSError object that describes the problem.
  93. @return YES the command has been successfully executed by Siri voice recognition service
  94. */
  95. - (BOOL)fb_activateSiriVoiceRecognitionWithText:(NSString *)text error:(NSError **)error;
  96. /**
  97. Emulated triggering of the given low-level IOHID device event. The constants for possible events are defined
  98. in https://unix.superglobalmegacorp.com/xnu/newsrc/iokit/IOKit/hidsystem/IOHIDUsageTables.h.html
  99. Popular constants:
  100. - kHIDPage_Consumer = 0x0C
  101. - kHIDUsage_Csmr_VolumeIncrement = 0xE9 (Volume Up)
  102. - kHIDUsage_Csmr_VolumeDecrement = 0xEA (Volume Down)
  103. - kHIDUsage_Csmr_Menu = 0x40 (Home)
  104. - kHIDUsage_Csmr_Power = 0x30 (Power)
  105. - kHIDUsage_Csmr_Snapshot = 0x65 (Power + Home)
  106. @param page The event page identifier
  107. @param usage The event usage identifier (usages are defined per-page)
  108. @param duration The event duration in float seconds (XCTest uses 0.005 for a single press event)
  109. @param error If there is an error, upon return contains an NSError object that describes the problem.
  110. @return YES the event has successfully been triggered
  111. */
  112. - (BOOL)fb_performIOHIDEventWithPage:(unsigned int)page
  113. usage:(unsigned int)usage
  114. duration:(NSTimeInterval)duration
  115. error:(NSError **)error;
  116. /**
  117. Allows to set device appearance
  118. @param appearance The desired appearance value
  119. @param error If there is an error, upon return contains an NSError object that describes the problem.
  120. @return YES if the appearance has been successfully set
  121. */
  122. - (BOOL)fb_setAppearance:(FBUIInterfaceAppearance)appearance error:(NSError **)error;
  123. /**
  124. Get current appearance prefefence.
  125. @return 0 (automatic), 1 (light) or 2 (dark), or nil
  126. */
  127. - (nullable NSNumber *)fb_getAppearance;
  128. #if !TARGET_OS_TV
  129. /**
  130. Allows to set a simulated geolocation coordinates.
  131. Only works since Xcode 14.3/iOS 16.4
  132. @param location The simlated location coordinates to set
  133. @param error If there is an error, upon return contains an NSError object that describes the problem.
  134. @return YES if the simulated location has been successfully set
  135. */
  136. - (BOOL)fb_setSimulatedLocation:(CLLocation *)location error:(NSError **)error;
  137. /**
  138. Allows to get a simulated geolocation coordinates.
  139. Only works since Xcode 14.3/iOS 16.4
  140. @param error If there is an error, upon return contains an NSError object that describes the problem.
  141. @return The current simulated location or nil in case of failure or if no location has previously been seet
  142. (the returned error will be nil in the latter case)
  143. */
  144. - (nullable CLLocation *)fb_getSimulatedLocation:(NSError **)error;
  145. /**
  146. Allows to clear a previosuly set simulated geolocation coordinates.
  147. Only works since Xcode 14.3/iOS 16.4
  148. @param error If there is an error, upon return contains an NSError object that describes the problem.
  149. @return YES if the simulated location has been successfully cleared
  150. */
  151. - (BOOL)fb_clearSimulatedLocation:(NSError **)error;
  152. #endif
  153. @end
  154. NS_ASSUME_NONNULL_END