appium-webdriveragent 5.15.6 → 5.15.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/PrivateHeaders/XCTest/XCUIApplication.h +0 -1
  3. package/WebDriverAgent.xcodeproj/project.pbxproj +6 -18
  4. package/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +38 -0
  5. package/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +148 -5
  6. package/WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.m +1 -1
  7. package/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.h +0 -1
  8. package/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m +5 -3
  9. package/WebDriverAgentLib/Categories/XCUIElement+FBTVFocuse.m +2 -2
  10. package/WebDriverAgentLib/Commands/FBAlertViewCommands.m +4 -4
  11. package/WebDriverAgentLib/Commands/FBCustomCommands.m +2 -2
  12. package/WebDriverAgentLib/Commands/FBDebugCommands.m +2 -3
  13. package/WebDriverAgentLib/Commands/FBElementCommands.m +2 -4
  14. package/WebDriverAgentLib/Commands/FBFindElementCommands.m +0 -1
  15. package/WebDriverAgentLib/Commands/FBOrientationCommands.m +9 -8
  16. package/WebDriverAgentLib/Commands/FBSessionCommands.m +7 -9
  17. package/WebDriverAgentLib/Commands/FBTouchActionCommands.m +0 -1
  18. package/WebDriverAgentLib/FBAlert.m +3 -3
  19. package/WebDriverAgentLib/Routing/FBSession.h +13 -14
  20. package/WebDriverAgentLib/Routing/FBSession.m +49 -46
  21. package/WebDriverAgentLib/Utilities/FBAlertsMonitor.m +3 -3
  22. package/WebDriverAgentLib/Utilities/FBKeyboard.m +6 -5
  23. package/WebDriverAgentLib/Utilities/FBMjpegServer.m +0 -1
  24. package/WebDriverAgentLib/Utilities/FBPasteboard.m +2 -2
  25. package/WebDriverAgentLib/Utilities/FBScreen.m +1 -2
  26. package/WebDriverAgentLib/Utilities/FBTVNavigationTracker.m +1 -2
  27. package/WebDriverAgentLib/Utilities/FBXCodeCompatibility.h +0 -33
  28. package/WebDriverAgentLib/Utilities/FBXCodeCompatibility.m +2 -40
  29. package/WebDriverAgentLib/WebDriverAgentLib.h +0 -1
  30. package/WebDriverAgentTests/IntegrationTests/FBAutoAlertsHandlerTests.m +2 -3
  31. package/WebDriverAgentTests/IntegrationTests/FBElementVisibilityTests.m +0 -1
  32. package/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.h +1 -3
  33. package/WebDriverAgentTests/IntegrationTests/FBIntegrationTestCase.m +5 -5
  34. package/WebDriverAgentTests/IntegrationTests/FBSafariAlertTests.m +1 -2
  35. package/WebDriverAgentTests/IntegrationTests/FBSessionIntegrationTests.m +11 -10
  36. package/WebDriverAgentTests/IntegrationTests/FBTapTest.m +0 -1
  37. package/WebDriverAgentTests/IntegrationTests/FBW3CMultiTouchActionsIntegrationTests.m +0 -1
  38. package/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m +8 -8
  39. package/WebDriverAgentTests/IntegrationTests/XCUIDeviceHelperTests.m +5 -4
  40. package/WebDriverAgentTests/IntegrationTests/XCUIElementHelperIntegrationTests.m +0 -1
  41. package/WebDriverAgentTests/UnitTests/Doubles/{FBApplicationDouble.h → XCUIApplicationDouble.h} +1 -1
  42. package/WebDriverAgentTests/UnitTests/Doubles/{FBApplicationDouble.m → XCUIApplicationDouble.m} +3 -3
  43. package/WebDriverAgentTests/UnitTests/FBSessionTests.m +3 -3
  44. package/package.json +2 -2
  45. package/WebDriverAgentLib/FBApplication.h +0 -49
  46. package/WebDriverAgentLib/FBApplication.m +0 -185
@@ -10,12 +10,12 @@
10
10
  #import <XCTest/XCTest.h>
11
11
 
12
12
  #import "FBAlert.h"
13
- #import "FBApplication.h"
14
13
  #import "FBTestMacros.h"
15
14
  #import "FBIntegrationTestCase.h"
16
15
  #import "FBConfiguration.h"
17
16
  #import "FBMacros.h"
18
17
  #import "FBRunLoopSpinner.h"
18
+ #import "XCUIApplication+FBHelpers.h"
19
19
  #import "XCUIDevice+FBRotation.h"
20
20
  #import "XCUIElement.h"
21
21
  #import "XCUIElement+FBIsVisible.h"
@@ -30,7 +30,7 @@ NSString *const FBTapsCountLabelIdentifier = @"numberOfTapsLabel";
30
30
 
31
31
  @interface FBIntegrationTestCase ()
32
32
  @property (nonatomic, strong) XCUIApplication *testedApplication;
33
- @property (nonatomic, strong) FBApplication *springboard;
33
+ @property (nonatomic, strong) XCUIApplication *springboard;
34
34
  @end
35
35
 
36
36
  @implementation FBIntegrationTestCase
@@ -46,7 +46,7 @@ NSString *const FBTapsCountLabelIdentifier = @"numberOfTapsLabel";
46
46
  [FBConfiguration disableApplicationUIInterruptionsHandling];
47
47
  [FBConfiguration disableScreenshots];
48
48
  self.continueAfterFailure = NO;
49
- self.springboard = FBApplication.fb_systemApplication;
49
+ self.springboard = XCUIApplication.fb_systemApplication;
50
50
  self.testedApplication = [XCUIApplication new];
51
51
  }
52
52
 
@@ -91,10 +91,10 @@ NSString *const FBTapsCountLabelIdentifier = @"numberOfTapsLabel";
91
91
  {
92
92
  [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonHome];
93
93
  [self.testedApplication fb_waitUntilStable];
94
- FBAssertWaitTillBecomesTrue(FBApplication.fb_systemApplication.icons[@"Safari"].exists);
94
+ FBAssertWaitTillBecomesTrue(XCUIApplication.fb_systemApplication.icons[@"Safari"].exists);
95
95
  [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonHome];
96
96
  [self.testedApplication fb_waitUntilStable];
97
- FBAssertWaitTillBecomesTrue(FBApplication.fb_systemApplication.icons[@"Calendar"].firstMatch.fb_isVisible);
97
+ FBAssertWaitTillBecomesTrue(XCUIApplication.fb_systemApplication.icons[@"Calendar"].firstMatch.fb_isVisible);
98
98
  }
99
99
 
100
100
  - (void)goToSpringBoardExtras
@@ -10,7 +10,6 @@
10
10
  #import <XCTest/XCTest.h>
11
11
 
12
12
  #import "FBIntegrationTestCase.h"
13
- #import "FBApplication.h"
14
13
  #import "FBTestMacros.h"
15
14
  #import "FBMacros.h"
16
15
  #import "FBSession.h"
@@ -33,7 +32,7 @@ static NSString *const SAFARI_BUNDLE_ID = @"com.apple.mobilesafari";
33
32
  - (void)setUp
34
33
  {
35
34
  [super setUp];
36
- self.session = [FBSession initWithApplication:FBApplication.fb_activeApplication];
35
+ self.session = [FBSession initWithApplication:XCUIApplication.fb_activeApplication];
37
36
  [self.session launchApplicationWithBundleId:SAFARI_BUNDLE_ID
38
37
  shouldWaitForQuiescence:nil
39
38
  arguments:nil
@@ -10,13 +10,14 @@
10
10
  #import <XCTest/XCTest.h>
11
11
 
12
12
  #import "FBIntegrationTestCase.h"
13
- #import "FBApplication.h"
14
13
  #import "FBExceptions.h"
15
14
  #import "FBMacros.h"
16
15
  #import "FBSession.h"
17
16
  #import "FBXCodeCompatibility.h"
18
17
  #import "FBTestMacros.h"
19
18
  #import "FBUnattachedAppLauncher.h"
19
+ #import "XCUIApplication+FBHelpers.h"
20
+ #import "XCUIApplication.h"
20
21
 
21
22
  @interface FBSession (Tests)
22
23
 
@@ -35,7 +36,7 @@ static NSString *const SETTINGS_BUNDLE_ID = @"com.apple.Preferences";
35
36
  {
36
37
  [super setUp];
37
38
  [self launchApplication];
38
- FBApplication *app = [[FBApplication alloc] initWithBundleIdentifier:self.testedApplication.bundleID];
39
+ XCUIApplication *app = [[XCUIApplication alloc] initWithBundleIdentifier:self.testedApplication.bundleID];
39
40
  self.session = [FBSession initWithApplication:app];
40
41
  }
41
42
 
@@ -47,7 +48,7 @@ static NSString *const SETTINGS_BUNDLE_ID = @"com.apple.Preferences";
47
48
 
48
49
  - (void)testSettingsAppCanBeOpenedInScopeOfTheCurrentSession
49
50
  {
50
- FBApplication *testedApp = FBApplication.fb_activeApplication;
51
+ XCUIApplication *testedApp = XCUIApplication.fb_activeApplication;
51
52
  [self.session launchApplicationWithBundleId:SETTINGS_BUNDLE_ID
52
53
  shouldWaitForQuiescence:nil
53
54
  arguments:nil
@@ -61,7 +62,7 @@ static NSString *const SETTINGS_BUNDLE_ID = @"com.apple.Preferences";
61
62
 
62
63
  - (void)testSettingsAppCanBeReopenedInScopeOfTheCurrentSession
63
64
  {
64
- FBApplication *systemApp = self.springboard;
65
+ XCUIApplication *systemApp = self.springboard;
65
66
  [self.session launchApplicationWithBundleId:SETTINGS_BUNDLE_ID
66
67
  shouldWaitForQuiescence:nil
67
68
  arguments:nil
@@ -78,7 +79,7 @@ static NSString *const SETTINGS_BUNDLE_ID = @"com.apple.Preferences";
78
79
 
79
80
  - (void)testMainAppCanBeReactivatedInScopeOfTheCurrentSession
80
81
  {
81
- FBApplication *testedApp = FBApplication.fb_activeApplication;
82
+ XCUIApplication *testedApp = XCUIApplication.fb_activeApplication;
82
83
  [self.session launchApplicationWithBundleId:SETTINGS_BUNDLE_ID
83
84
  shouldWaitForQuiescence:nil
84
85
  arguments:nil
@@ -90,8 +91,8 @@ static NSString *const SETTINGS_BUNDLE_ID = @"com.apple.Preferences";
90
91
 
91
92
  - (void)testMainAppCanBeRestartedInScopeOfTheCurrentSession
92
93
  {
93
- FBApplication *systemApp = self.springboard;
94
- FBApplication *testedApp = [[FBApplication alloc] initWithBundleIdentifier:self.testedApplication.bundleID];
94
+ XCUIApplication *systemApp = self.springboard;
95
+ XCUIApplication *testedApp = [[XCUIApplication alloc] initWithBundleIdentifier:self.testedApplication.bundleID];
95
96
  [self.session terminateApplicationWithBundleId:testedApp.bundleID];
96
97
  FBAssertWaitTillBecomesTrue([self.session.activeApplication.bundleID isEqualToString:systemApp.bundleID]);
97
98
  [self.session launchApplicationWithBundleId:testedApp.bundleID
@@ -105,12 +106,12 @@ static NSString *const SETTINGS_BUNDLE_ID = @"com.apple.Preferences";
105
106
  {
106
107
  [FBUnattachedAppLauncher launchAppWithBundleId:SETTINGS_BUNDLE_ID];
107
108
  [self.session kill];
108
- XCTAssertEqualObjects(SETTINGS_BUNDLE_ID, FBApplication.fb_activeApplication.bundleID);
109
+ XCTAssertEqualObjects(SETTINGS_BUNDLE_ID, XCUIApplication.fb_activeApplication.bundleID);
109
110
  }
110
111
 
111
112
  - (void)testAppWithInvalidBundleIDCannotBeStarted
112
113
  {
113
- FBApplication *testedApp = [[FBApplication alloc] initWithBundleIdentifier:@"yolo"];
114
+ XCUIApplication *testedApp = [[XCUIApplication alloc] initWithBundleIdentifier:@"yolo"];
114
115
  @try {
115
116
  [testedApp launch];
116
117
  XCTFail(@"An exception is expected to be thrown");
@@ -121,7 +122,7 @@ static NSString *const SETTINGS_BUNDLE_ID = @"com.apple.Preferences";
121
122
 
122
123
  - (void)testAppWithInvalidBundleIDCannotBeActivated
123
124
  {
124
- FBApplication *testedApp = [[FBApplication alloc] initWithBundleIdentifier:@"yolo"];
125
+ XCUIApplication *testedApp = [[XCUIApplication alloc] initWithBundleIdentifier:@"yolo"];
125
126
  @try {
126
127
  [testedApp activate];
127
128
  XCTFail(@"An exception is expected to be thrown");
@@ -11,7 +11,6 @@
11
11
 
12
12
  #import "FBIntegrationTestCase.h"
13
13
 
14
- #import "FBApplication.h"
15
14
  #import "FBElementCache.h"
16
15
  #import "FBTestMacros.h"
17
16
  #import "XCUIDevice+FBRotation.h"
@@ -11,7 +11,6 @@
11
11
 
12
12
  #import "FBIntegrationTestCase.h"
13
13
 
14
- #import "FBApplication.h"
15
14
  #import "XCUIElement.h"
16
15
  #import "XCUIApplication+FBTouchAction.h"
17
16
  #import "FBTestMacros.h"
@@ -11,11 +11,11 @@
11
11
 
12
12
  #import <mach/mach_time.h>
13
13
 
14
- #import "FBApplication.h"
15
14
  #import "FBIntegrationTestCase.h"
16
15
  #import "FBElement.h"
17
16
  #import "FBMacros.h"
18
17
  #import "FBTestMacros.h"
18
+ #import "XCUIApplication.h"
19
19
  #import "XCUIApplication+FBHelpers.h"
20
20
  #import "XCUIElement+FBIsVisible.h"
21
21
  #import "FBXCodeCompatibility.h"
@@ -34,8 +34,8 @@
34
34
  - (void)testQueringSpringboard
35
35
  {
36
36
  [self goToSpringBoardFirstPage];
37
- XCTAssertTrue(FBApplication.fb_systemApplication.icons[@"Safari"].exists);
38
- XCTAssertTrue(FBApplication.fb_systemApplication.icons[@"Calendar"].firstMatch.exists);
37
+ XCTAssertTrue(XCUIApplication.fb_systemApplication.icons[@"Safari"].exists);
38
+ XCTAssertTrue(XCUIApplication.fb_systemApplication.icons[@"Calendar"].firstMatch.exists);
39
39
  }
40
40
 
41
41
  - (void)testApplicationTree
@@ -58,10 +58,10 @@
58
58
 
59
59
  - (void)testActiveApplication
60
60
  {
61
- FBApplication *systemApp = FBApplication.fb_systemApplication;
62
- XCTAssertTrue([FBApplication fb_activeApplication].buttons[@"Alerts"].fb_isVisible);
61
+ XCUIApplication *systemApp = XCUIApplication.fb_systemApplication;
62
+ XCTAssertTrue([XCUIApplication fb_activeApplication].buttons[@"Alerts"].fb_isVisible);
63
63
  [self goToSpringBoardFirstPage];
64
- XCTAssertEqualObjects([FBApplication fb_activeApplication].bundleID, systemApp.bundleID);
64
+ XCTAssertEqualObjects([XCUIApplication fb_activeApplication].bundleID, systemApp.bundleID);
65
65
  XCTAssertTrue(systemApp.icons[@"Safari"].fb_isVisible);
66
66
  }
67
67
 
@@ -102,14 +102,14 @@
102
102
  }
103
103
 
104
104
  NSError *error;
105
- NSArray *auditIssues1 = [FBApplication.fb_activeApplication fb_performAccessibilityAuditWithAuditTypes:~0UL
105
+ NSArray *auditIssues1 = [XCUIApplication.fb_activeApplication fb_performAccessibilityAuditWithAuditTypes:~0UL
106
106
  error:&error];
107
107
  XCTAssertNotNil(auditIssues1);
108
108
  XCTAssertNil(error);
109
109
 
110
110
  NSMutableSet *set = [NSMutableSet new];
111
111
  [set addObject:@"XCUIAccessibilityAuditTypeAll"];
112
- NSArray *auditIssues2 = [FBApplication.fb_activeApplication fb_performAccessibilityAuditWithAuditTypesSet:set.copy
112
+ NSArray *auditIssues2 = [XCUIApplication.fb_activeApplication fb_performAccessibilityAuditWithAuditTypesSet:set.copy
113
113
  error:&error];
114
114
  XCTAssertEqualObjects(auditIssues1, auditIssues2);
115
115
  XCTAssertNil(error);
@@ -9,11 +9,12 @@
9
9
 
10
10
  #import <XCTest/XCTest.h>
11
11
 
12
- #import "FBApplication.h"
13
12
  #import "FBIntegrationTestCase.h"
14
13
  #import "FBImageUtils.h"
15
14
  #import "FBMacros.h"
16
15
  #import "FBTestMacros.h"
16
+ #import "XCUIApplication.h"
17
+ #import "XCUIApplication+FBHelpers.h"
17
18
  #import "XCUIDevice+FBHelpers.h"
18
19
  #import "XCUIDevice+FBRotation.h"
19
20
  #import "XCUIScreen.h"
@@ -101,7 +102,7 @@
101
102
  NSError *error;
102
103
  XCTAssertTrue([[XCUIDevice sharedDevice] fb_goToHomescreenWithError:&error]);
103
104
  XCTAssertNil(error);
104
- XCTAssertTrue([FBApplication fb_activeApplication].icons[@"Safari"].exists);
105
+ XCTAssertTrue([XCUIApplication fb_activeApplication].icons[@"Safari"].exists);
105
106
  }
106
107
 
107
108
  - (void)testLockUnlockScreen
@@ -124,7 +125,7 @@
124
125
 
125
126
  NSError *error;
126
127
  XCTAssertTrue([XCUIDevice.sharedDevice fb_openUrl:@"https://apple.com" error:&error]);
127
- FBAssertWaitTillBecomesTrue([FBApplication.fb_activeApplication.bundleID isEqualToString:@"com.apple.mobilesafari"]);
128
+ FBAssertWaitTillBecomesTrue([XCUIApplication.fb_activeApplication.bundleID isEqualToString:@"com.apple.mobilesafari"]);
128
129
  XCTAssertNil(error);
129
130
  }
130
131
 
@@ -138,7 +139,7 @@
138
139
  XCTAssertTrue([XCUIDevice.sharedDevice fb_openUrl:@"https://apple.com"
139
140
  withApplication:@"com.apple.mobilesafari"
140
141
  error:&error]);
141
- FBAssertWaitTillBecomesTrue([FBApplication.fb_activeApplication.bundleID isEqualToString:@"com.apple.mobilesafari"]);
142
+ FBAssertWaitTillBecomesTrue([XCUIApplication.fb_activeApplication.bundleID isEqualToString:@"com.apple.mobilesafari"]);
142
143
  XCTAssertNil(error);
143
144
  }
144
145
 
@@ -10,7 +10,6 @@
10
10
  #import <XCTest/XCTest.h>
11
11
  #import "XCTest/XCUIElementTypes.h"
12
12
 
13
- #import "FBApplication.h"
14
13
  #import "FBIntegrationTestCase.h"
15
14
  #import "FBTestMacros.h"
16
15
  #import "FBElement.h"
@@ -9,7 +9,7 @@
9
9
 
10
10
  #import <Foundation/Foundation.h>
11
11
 
12
- @interface FBApplicationDouble : NSObject
12
+ @interface XCUIApplicationDouble : NSObject
13
13
  @property (nonatomic, assign, readonly) BOOL didTerminate;
14
14
  @property (nonatomic, strong) NSString* bundleID;
15
15
  @property (nonatomic) BOOL fb_shouldWaitForQuiescence;
@@ -7,13 +7,13 @@
7
7
  * of patent rights can be found in the PATENTS file in the same directory.
8
8
  */
9
9
 
10
- #import "FBApplicationDouble.h"
10
+ #import "XCUIApplicationDouble.h"
11
11
 
12
- @interface FBApplicationDouble ()
12
+ @interface XCUIApplicationDouble ()
13
13
  @property (nonatomic, assign, readwrite) BOOL didTerminate;
14
14
  @end
15
15
 
16
- @implementation FBApplicationDouble
16
+ @implementation XCUIApplicationDouble
17
17
 
18
18
  - (instancetype)init
19
19
  {
@@ -9,13 +9,13 @@
9
9
 
10
10
  #import <XCTest/XCTest.h>
11
11
 
12
- #import "FBApplicationDouble.h"
13
12
  #import "FBSession.h"
14
13
  #import "FBConfiguration.h"
14
+ #import "XCUIApplicationDouble.h"
15
15
 
16
16
  @interface FBSessionTests : XCTestCase
17
17
  @property (nonatomic, strong) FBSession *session;
18
- @property (nonatomic, strong) FBApplication *testedApplication;
18
+ @property (nonatomic, strong) XCUIApplication *testedApplication;
19
19
  @property (nonatomic) BOOL shouldTerminateAppValue;
20
20
  @end
21
21
 
@@ -24,7 +24,7 @@
24
24
  - (void)setUp
25
25
  {
26
26
  [super setUp];
27
- self.testedApplication = (id)FBApplicationDouble.new;
27
+ self.testedApplication = (id)XCUIApplicationDouble.new;
28
28
  self.shouldTerminateAppValue = FBConfiguration.shouldTerminateApp;
29
29
  [FBConfiguration setShouldTerminateApp:NO];
30
30
  self.session = [FBSession initWithApplication:self.testedApplication];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appium-webdriveragent",
3
- "version": "5.15.6",
3
+ "version": "5.15.7",
4
4
  "description": "Package bundling WebDriverAgent",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -87,7 +87,7 @@
87
87
  "mocha": "^10.0.0",
88
88
  "pre-commit": "^1.2.2",
89
89
  "prettier": "^3.0.0",
90
- "semantic-release": "^22.0.5",
90
+ "semantic-release": "^23.0.0",
91
91
  "sinon": "^17.0.0",
92
92
  "ts-node": "^10.9.1",
93
93
  "typescript": "~5.2"
@@ -1,49 +0,0 @@
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
-
10
- #import <WebDriverAgentLib/XCUIApplication.h>
11
-
12
- NS_ASSUME_NONNULL_BEGIN
13
-
14
- @interface FBApplication : XCUIApplication
15
-
16
- /**
17
- Constructor used to get current active application
18
- */
19
- + (instancetype)fb_activeApplication;
20
-
21
- /**
22
- Constructor used to get current active application
23
-
24
- @param bundleId The bundle identifier of an app, which should be selected as active by default
25
- if it is present in the list of active applications
26
- */
27
- + (instancetype)fb_activeApplicationWithDefaultBundleId:(nullable NSString *)bundleId;
28
-
29
- /**
30
- Constructor used to get the system application (e.g. Springboard on iOS)
31
- */
32
- + (instancetype)fb_systemApplication;
33
-
34
- /**
35
- Retrieves the list of all currently active applications
36
- */
37
- + (NSArray<FBApplication *> *)fb_activeApplications;
38
-
39
- /**
40
- Switch to system app (called Springboard on iOS)
41
-
42
- @param error If there is an error, upon return contains an NSError object that describes the problem.
43
- @return YES if the operation succeeds, otherwise NO.
44
- */
45
- + (BOOL)fb_switchToSystemApplicationWithError:(NSError **)error;
46
-
47
- @end
48
-
49
- NS_ASSUME_NONNULL_END
@@ -1,185 +0,0 @@
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
-
10
- #import "FBApplication.h"
11
-
12
- #import "FBXCAccessibilityElement.h"
13
- #import "FBLogger.h"
14
- #import "FBExceptions.h"
15
- #import "FBRunLoopSpinner.h"
16
- #import "FBMacros.h"
17
- #import "FBActiveAppDetectionPoint.h"
18
- #import "FBXCodeCompatibility.h"
19
- #import "FBXCTestDaemonsProxy.h"
20
- #import "XCUIApplication.h"
21
- #import "XCUIApplication+FBHelpers.h"
22
- #import "XCUIApplicationImpl.h"
23
- #import "XCUIApplicationProcess.h"
24
- #import "XCUIElement.h"
25
- #import "XCUIElementQuery.h"
26
- #import "FBXCAXClientProxy.h"
27
-
28
-
29
- static const NSTimeInterval APP_STATE_CHANGE_TIMEOUT = 5.0;
30
-
31
- @interface FBApplication ()
32
- @end
33
-
34
- @implementation FBApplication
35
-
36
- + (instancetype)fb_activeApplication
37
- {
38
- return [self fb_activeApplicationWithDefaultBundleId:nil];
39
- }
40
-
41
- + (NSArray<FBApplication *> *)fb_activeApplications
42
- {
43
- NSArray<id<FBXCAccessibilityElement>> *activeApplicationElements = [FBXCAXClientProxy.sharedClient activeApplications];
44
- NSMutableArray<FBApplication *> *result = [NSMutableArray array];
45
- if (activeApplicationElements.count > 0) {
46
- for (id<FBXCAccessibilityElement> applicationElement in activeApplicationElements) {
47
- FBApplication *app = [FBApplication fb_applicationWithPID:applicationElement.processIdentifier];
48
- if (nil != app) {
49
- [result addObject:app];
50
- }
51
- }
52
- }
53
- return result.count > 0 ? result.copy : @[self.class.fb_systemApplication];
54
- }
55
-
56
- + (instancetype)fb_activeApplicationWithDefaultBundleId:(nullable NSString *)bundleId
57
- {
58
- NSArray<id<FBXCAccessibilityElement>> *activeApplicationElements = [FBXCAXClientProxy.sharedClient activeApplications];
59
- id<FBXCAccessibilityElement> activeApplicationElement = nil;
60
- id<FBXCAccessibilityElement> currentElement = nil;
61
- if (nil != bundleId) {
62
- currentElement = FBActiveAppDetectionPoint.sharedInstance.axElement;
63
- if (nil != currentElement) {
64
- NSArray<NSDictionary *> *appInfos = [self fb_appsInfoWithAxElements:@[currentElement]];
65
- [FBLogger logFmt:@"Detected on-screen application: %@", appInfos.firstObject[@"bundleId"]];
66
- if ([[appInfos.firstObject objectForKey:@"bundleId"] isEqualToString:(id)bundleId]) {
67
- activeApplicationElement = currentElement;
68
- }
69
- }
70
- }
71
- if (nil == activeApplicationElement && activeApplicationElements.count > 1) {
72
- if (nil != bundleId) {
73
- NSArray<NSDictionary *> *appInfos = [self fb_appsInfoWithAxElements:activeApplicationElements];
74
- NSMutableArray<NSString *> *bundleIds = [NSMutableArray array];
75
- for (NSDictionary *appInfo in appInfos) {
76
- [bundleIds addObject:(NSString *)appInfo[@"bundleId"]];
77
- }
78
- [FBLogger logFmt:@"Detected system active application(s): %@", bundleIds];
79
- // Try to select the desired application first
80
- for (NSUInteger appIdx = 0; appIdx < appInfos.count; appIdx++) {
81
- if ([[[appInfos objectAtIndex:appIdx] objectForKey:@"bundleId"] isEqualToString:(id)bundleId]) {
82
- activeApplicationElement = [activeApplicationElements objectAtIndex:appIdx];
83
- break;
84
- }
85
- }
86
- }
87
- // Fall back to the "normal" algorithm if the desired application is either
88
- // not set or is not active
89
- if (nil == activeApplicationElement) {
90
- if (nil == currentElement) {
91
- currentElement = FBActiveAppDetectionPoint.sharedInstance.axElement;
92
- }
93
- if (nil == currentElement) {
94
- [FBLogger log:@"Cannot precisely detect the current application. Will use the system's recently active one"];
95
- if (nil == bundleId) {
96
- [FBLogger log:@"Consider changing the 'defaultActiveApplication' setting to the bundle identifier of the desired application under test"];
97
- }
98
- } else {
99
- for (id<FBXCAccessibilityElement> appElement in activeApplicationElements) {
100
- if (appElement.processIdentifier == currentElement.processIdentifier) {
101
- activeApplicationElement = appElement;
102
- break;
103
- }
104
- }
105
- }
106
- }
107
- }
108
-
109
- if (nil != activeApplicationElement) {
110
- FBApplication *application = [FBApplication fb_applicationWithPID:activeApplicationElement.processIdentifier];
111
- if (nil != application) {
112
- return application;
113
- }
114
- [FBLogger log:@"Cannot translate the active process identifier into an application object"];
115
- }
116
-
117
- if (activeApplicationElements.count > 0) {
118
- [FBLogger logFmt:@"Getting the most recent active application (out of %@ total items)", @(activeApplicationElements.count)];
119
- for (id<FBXCAccessibilityElement> appElement in activeApplicationElements) {
120
- FBApplication *application = [FBApplication fb_applicationWithPID:appElement.processIdentifier];
121
- if (nil != application) {
122
- return application;
123
- }
124
- }
125
- }
126
-
127
- [FBLogger log:@"Cannot retrieve any active applications. Assuming the system application is the active one"];
128
- return [self fb_systemApplication];
129
- }
130
-
131
- + (instancetype)fb_systemApplication
132
- {
133
- return [self fb_applicationWithPID:
134
- [[FBXCAXClientProxy.sharedClient systemApplication] processIdentifier]];
135
- }
136
-
137
- + (instancetype)applicationWithPID:(pid_t)processID
138
- {
139
- if ([NSProcessInfo processInfo].processIdentifier == processID) {
140
- return nil;
141
- }
142
- return (FBApplication *)[FBXCAXClientProxy.sharedClient monitoredApplicationWithProcessIdentifier:processID];
143
- }
144
-
145
- - (void)launch
146
- {
147
- [super launch];
148
- if (![self fb_waitForAppElement:APP_STATE_CHANGE_TIMEOUT]) {
149
- [FBLogger logFmt:@"The application '%@' is not running in foreground after %.2f seconds", self.bundleID, APP_STATE_CHANGE_TIMEOUT];
150
- }
151
- }
152
-
153
- - (void)terminate
154
- {
155
- [super terminate];
156
- if (![self waitForState:XCUIApplicationStateNotRunning timeout:APP_STATE_CHANGE_TIMEOUT]) {
157
- [FBLogger logFmt:@"The active application is still '%@' after %.2f seconds timeout", self.bundleID, APP_STATE_CHANGE_TIMEOUT];
158
- }
159
- }
160
-
161
- + (BOOL)fb_switchToSystemApplicationWithError:(NSError **)error
162
- {
163
- FBApplication *systemApp = self.fb_systemApplication;
164
- @try {
165
- if ([systemApp fb_state] < 2) {
166
- [systemApp launch];
167
- } else {
168
- [systemApp fb_activate];
169
- }
170
- } @catch (NSException *e) {
171
- return [[[FBErrorBuilder alloc]
172
- withDescription:nil == e ? @"Cannot open the home screen" : e.reason]
173
- buildError:error];
174
- }
175
- return [[[[FBRunLoopSpinner new]
176
- timeout:5]
177
- timeoutErrorMessage:@"Timeout waiting until the home screen is visible"]
178
- spinUntilTrue:^BOOL{
179
- FBApplication *activeApp = self.fb_activeApplication;
180
- return nil != activeApp && [activeApp.bundleID isEqualToString:systemApp.bundleID];
181
- }
182
- error:error];
183
- }
184
-
185
- @end