FBSession.h 4.9 KB

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