XCUIApplication+FBHelpers.h 5.7 KB

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