XCUIApplication+FBHelpers.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. @class XCElementSnapshot;
  11. @protocol FBXCAccessibilityElement;
  12. @class FBXMLGenerationOptions;
  13. NS_ASSUME_NONNULL_BEGIN
  14. @interface XCUIApplication (FBHelpers)
  15. /**
  16. Deactivates application for given time
  17. @param duration amount of time application should deactivated
  18. @param error If there is an error, upon return contains an NSError object that describes the problem.
  19. @return YES if the operation succeeds, otherwise NO.
  20. */
  21. - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)error;
  22. /**
  23. Return application elements tree in form of nested dictionaries
  24. */
  25. - (NSDictionary *)fb_tree;
  26. /**
  27. @param excludedAttributes Set of possible attributes to be excluded i.e frame, enabled, visible, accessible, focused. If set to nil or an empty array then no attributes will be excluded from the resulting JSON
  28. @return application elements tree in form of nested dictionaries
  29. */
  30. - (NSDictionary *)fb_tree:(nullable NSSet<NSString *> *) excludedAttributes;
  31. /**
  32. Return application elements accessibility tree in form of nested dictionaries
  33. */
  34. - (NSDictionary *)fb_accessibilityTree;
  35. /**
  36. Return application elements tree in a form of xml string
  37. with default options.
  38. @return nil if there was a failure while retriveing the page source.
  39. */
  40. - (nullable NSString *)fb_xmlRepresentation;
  41. /**
  42. Return application elements tree in a form of xml string
  43. @param options Optional values that affect the resulting XML generation process.
  44. @return nil if there was a failure while retriveing the page source.
  45. */
  46. - (nullable NSString *)fb_xmlRepresentationWithOptions:(nullable FBXMLGenerationOptions *)options;
  47. /**
  48. Return application elements tree in form of internal XCTest debugDescription string
  49. */
  50. - (NSString *)fb_descriptionRepresentation;
  51. /**
  52. Returns the element, which currently holds the keyboard input focus or nil if there are no such elements.
  53. */
  54. - (nullable XCUIElement *)fb_activeElement;
  55. #if TARGET_OS_TV
  56. /**
  57. Returns the element, which currently focused.
  58. */
  59. - (nullable XCUIElement *)fb_focusedElement;
  60. #endif
  61. /**
  62. Waits until the current on-screen accessbility element belongs to the current application instance
  63. @param timeout The maximum time to wait for the element to appear
  64. @returns Either YES or NO
  65. */
  66. - (BOOL)fb_waitForAppElement:(NSTimeInterval)timeout;
  67. /**
  68. Retrieves the information about the applications the given accessiblity elements
  69. belong to
  70. @param axElements the list of accessibility elements
  71. @returns The list of dictionaries. Each dictionary contains `bundleId` and `pid` items
  72. */
  73. + (NSArray<NSDictionary<NSString *, id> *> *)fb_appsInfoWithAxElements:(NSArray<id<FBXCAccessibilityElement>> *)axElements;
  74. /**
  75. Retrieves the information about the currently active apps
  76. @returns The list of dictionaries. Each dictionary contains `bundleId` and `pid` items.
  77. */
  78. + (NSArray<NSDictionary<NSString *, id> *> *)fb_activeAppsInfo;
  79. /**
  80. Tries to dismiss the on-screen keyboard
  81. @param keyNames Optional list of possible keyboard key labels to tap
  82. in order to dismiss the keyboard.
  83. @param error The resulting error object if the method fails to dismiss the keyboard
  84. @returns YES if the keyboard dismissal was successful or NO otherwise
  85. */
  86. - (BOOL)fb_dismissKeyboardWithKeyNames:(nullable NSArray<NSString *> *)keyNames
  87. error:(NSError **)error;
  88. /**
  89. A wrapper over https://developer.apple.com/documentation/xctest/xcuiapplication/4190847-performaccessibilityauditwithaud?language=objc
  90. @param auditTypes Combination of https://developer.apple.com/documentation/xctest/xcuiaccessibilityaudittype?language=objc
  91. @param error If there is an error, upon return contains an NSError object that describes the problem.
  92. @return List of found issues or nil if there was a failure
  93. */
  94. - (nullable NSArray<NSDictionary<NSString *, NSString*> *> *)fb_performAccessibilityAuditWithAuditTypesSet:(NSSet<NSString *> *)auditTypes
  95. error:(NSError **)error;
  96. /**
  97. A wrapper over https://developer.apple.com/documentation/xctest/xcuiapplication/4190847-performaccessibilityauditwithaud?language=objc
  98. @param auditTypes Combination of https://developer.apple.com/documentation/xctest/xcuiaccessibilityaudittype?language=objc
  99. @param error If there is an error, upon return contains an NSError object that describes the problem.
  100. @return List of found issues or nil if there was a failure
  101. */
  102. - (nullable NSArray<NSDictionary<NSString *, NSString*> *> *)fb_performAccessibilityAuditWithAuditTypes:(uint64_t)auditTypes
  103. error:(NSError **)error;
  104. /**
  105. Constructor used to get current active application
  106. */
  107. + (instancetype)fb_activeApplication;
  108. /**
  109. Constructor used to get current active application
  110. @param bundleId The bundle identifier of an app, which should be selected as active by default
  111. if it is present in the list of active applications
  112. */
  113. + (instancetype)fb_activeApplicationWithDefaultBundleId:(nullable NSString *)bundleId;
  114. /**
  115. Constructor used to get the system application (e.g. Springboard on iOS)
  116. */
  117. + (instancetype)fb_systemApplication;
  118. /**
  119. Retrieves the list of all currently active applications
  120. */
  121. + (NSArray<XCUIApplication *> *)fb_activeApplications;
  122. /**
  123. Switch to system app (called Springboard on iOS)
  124. @param error If there is an error, upon return contains an NSError object that describes the problem.
  125. @return YES if the operation succeeds, otherwise NO.
  126. */
  127. + (BOOL)fb_switchToSystemApplicationWithError:(NSError **)error;
  128. /**
  129. Determines whether the other app is the same as the current one
  130. @param otherApp Other app instance
  131. @return YES if the other app has the same identifier
  132. */
  133. - (BOOL)fb_isSameAppAs:(nullable XCUIApplication *)otherApp;
  134. @end
  135. NS_ASSUME_NONNULL_END