FBSession.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. @class FBElementCache;
  11. @class XCUIApplication;
  12. NS_ASSUME_NONNULL_BEGIN
  13. /** Bundle identifier of Mobile Safari browser */
  14. extern NSString* const FB_SAFARI_BUNDLE_ID;
  15. /**
  16. Class that represents testing session
  17. */
  18. @interface FBSession : NSObject
  19. /*! Application tested during that session */
  20. @property (nonatomic, readonly) XCUIApplication *activeApplication;
  21. /*! Session's identifier */
  22. @property (nonatomic, readonly) NSString *identifier;
  23. /*! Element cache related to that session */
  24. @property (nonatomic, readonly) FBElementCache *elementCache;
  25. /*! The identifier of the active application */
  26. @property (nonatomic) NSString *defaultActiveApplication;
  27. /*! The action to apply to unexpected alerts. Either "accept"/"dismiss" or nil/empty string (by default) to do nothing */
  28. @property (nonatomic, nullable) NSString *defaultAlertAction;
  29. /*! Whether to use the native caching strategy for elements or the custom one: https://discuss.appium.io/t/elements-state-coming-from-xpath-vs-ios-predicate-string/34016 */
  30. @property (nonatomic) BOOL useNativeCachingStrategy;
  31. /*! Keeps cached visibility values for the current snapshots tree */
  32. @property (nonatomic, readonly) NSMutableDictionary<NSNumber *, NSMutableDictionary<NSString *, NSNumber *> *> *elementsVisibilityCache;
  33. + (nullable instancetype)activeSession;
  34. /**
  35. Fetches session for given identifier.
  36. If identifier doesn't match activeSession identifier, will return nil.
  37. @param identifier Identifier for searched session
  38. @return session. Can return nil if session does not exists
  39. */
  40. + (nullable instancetype)sessionWithIdentifier:(NSString *)identifier;
  41. /**
  42. Creates and saves new session for application
  43. @param application The application that we want to create session for
  44. @return new session
  45. */
  46. + (instancetype)initWithApplication:(nullable XCUIApplication *)application;
  47. /**
  48. Creates and saves new session for application with default alert handling behaviour
  49. @param application The application that we want to create session for
  50. @param defaultAlertAction The default reaction to on-screen alert. Either 'accept' or 'dismiss'
  51. @return new session
  52. */
  53. + (instancetype)initWithApplication:(nullable XCUIApplication *)application
  54. defaultAlertAction:(NSString *)defaultAlertAction;
  55. /**
  56. Kills application associated with that session and removes session
  57. */
  58. - (void)kill;
  59. /**
  60. Launch an application with given bundle identifier in scope of current session.
  61. !This method is only available since Xcode9 SDK
  62. @param bundleIdentifier Valid bundle identifier of the application to be launched
  63. @param shouldWaitForQuiescence whether to wait for quiescence on application startup
  64. @param arguments The optional array of application command line arguments. The arguments are going to be applied if the application was not running before.
  65. @param environment The optional dictionary of environment variables for the application, which is going to be executed. The environment variables are going to be applied if the application was not running before.
  66. @return The application instance
  67. */
  68. - (XCUIApplication *)launchApplicationWithBundleId:(NSString *)bundleIdentifier
  69. shouldWaitForQuiescence:(nullable NSNumber *)shouldWaitForQuiescence
  70. arguments:(nullable NSArray<NSString *> *)arguments
  71. environment:(nullable NSDictionary <NSString *, NSString *> *)environment;
  72. /**
  73. Activate an application with given bundle identifier in scope of current session.
  74. !This method is only available since Xcode9 SDK
  75. @param bundleIdentifier Valid bundle identifier of the application to be activated
  76. @return The application instance
  77. */
  78. - (XCUIApplication *)activateApplicationWithBundleId:(NSString *)bundleIdentifier;
  79. /**
  80. Terminate an application with the given bundle id. The application should be previously
  81. executed by launchApplicationWithBundleId method or passed to the init method.
  82. @param bundleIdentifier Valid bundle identifier of the application to be terminated
  83. @return Either YES if the app has been successfully terminated or NO if it was not running
  84. */
  85. - (BOOL)terminateApplicationWithBundleId:(NSString *)bundleIdentifier;
  86. /**
  87. Get the state of the particular application in scope of the current session.
  88. !This method is only returning reliable results since Xcode9 SDK
  89. @param bundleIdentifier Valid bundle identifier of the application to get the state from
  90. @return Application state as integer number. See
  91. https://developer.apple.com/documentation/xctest/xcuiapplicationstate?language=objc
  92. for more details on possible enum values
  93. */
  94. - (NSUInteger)applicationStateWithBundleId:(NSString *)bundleIdentifier;
  95. /**
  96. Allows to enable automated session alerts monitoring.
  97. Repeated calls are ignored if alerts monitoring has been already enabled.
  98. @returns YES if the actual alerts monitoring state has been changed
  99. */
  100. - (BOOL)enableAlertsMonitor;
  101. /**
  102. Allows to disable automated alerts monitoring
  103. Repeated calls are ignored if alerts monitoring has been already disabled.
  104. @returns YES if the actual alerts monitoring state has been changed
  105. */
  106. - (BOOL)disableAlertsMonitor;
  107. @end
  108. NS_ASSUME_NONNULL_END