appium-webdriveragent 5.1.0 → 5.1.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [5.1.1](https://github.com/appium/WebDriverAgent/compare/v5.1.0...v5.1.1) (2023-05-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Assert app is installed before launching or activating it ([#704](https://github.com/appium/WebDriverAgent/issues/704)) ([94e5c51](https://github.com/appium/WebDriverAgent/commit/94e5c51bce1d4518418e999b4ac466cd46ca3bc3))
7
+
1
8
  ## [5.1.0](https://github.com/appium/WebDriverAgent/compare/v5.0.0...v5.1.0) (2023-05-14)
2
9
 
3
10
 
@@ -44,6 +44,16 @@ NS_ASSUME_NONNULL_BEGIN
44
44
  */
45
45
  + (BOOL)fb_switchToSystemApplicationWithError:(NSError **)error;
46
46
 
47
+ /**
48
+ Returns the bundle indentifier of the system app (ususally Springboard)
49
+ */
50
+ + (NSString *)fb_systemApplicationBundleID;
51
+
52
+ /**
53
+ Checks if the app is installed on the device under test.
54
+ */
55
+ - (BOOL)fb_isInstalled;
56
+
47
57
  @end
48
58
 
49
59
  NS_ASSUME_NONNULL_END
@@ -9,6 +9,7 @@
9
9
 
10
10
  #import "FBApplication.h"
11
11
 
12
+ #import "FBExceptions.h"
12
13
  #import "FBXCAccessibilityElement.h"
13
14
  #import "FBLogger.h"
14
15
  #import "FBRunLoopSpinner.h"
@@ -16,6 +17,7 @@
16
17
  #import "FBActiveAppDetectionPoint.h"
17
18
  #import "FBXCodeCompatibility.h"
18
19
  #import "FBXCTestDaemonsProxy.h"
20
+ #import "LSApplicationWorkspace.h"
19
21
  #import "XCUIApplication.h"
20
22
  #import "XCUIApplication+FBHelpers.h"
21
23
  #import "XCUIApplicationImpl.h"
@@ -133,6 +135,16 @@ static const NSTimeInterval APP_STATE_CHANGE_TIMEOUT = 5.0;
133
135
  [[FBXCAXClientProxy.sharedClient systemApplication] processIdentifier]];
134
136
  }
135
137
 
138
+ + (NSString *)fb_systemApplicationBundleID
139
+ {
140
+ static dispatch_once_t onceToken;
141
+ static NSString *systemAppBundleID;
142
+ dispatch_once(&onceToken, ^{
143
+ systemAppBundleID = [[self.class fb_systemApplication] bundleID];
144
+ });
145
+ return systemAppBundleID;
146
+ }
147
+
136
148
  + (instancetype)applicationWithPID:(pid_t)processID
137
149
  {
138
150
  if ([NSProcessInfo processInfo].processIdentifier == processID) {
@@ -141,14 +153,33 @@ static const NSTimeInterval APP_STATE_CHANGE_TIMEOUT = 5.0;
141
153
  return (FBApplication *)[FBXCAXClientProxy.sharedClient monitoredApplicationWithProcessIdentifier:processID];
142
154
  }
143
155
 
156
+ /**
157
+ https://github.com/appium/WebDriverAgent/issues/702
158
+ */
159
+ - (void)fb_assertInstalledByAction:(NSString *)action
160
+ {
161
+ if (![self.bundleID isEqualToString:[self.class fb_systemApplicationBundleID]] && !self.fb_isInstalled) {
162
+ NSString *message = [NSString stringWithFormat:@"The application '%@' cannot be %@ because it is not installed on the device under test",
163
+ self.bundleID, action];
164
+ [[NSException exceptionWithName:FBApplicationMissingException reason:message userInfo:nil] raise];
165
+ }
166
+ }
167
+
144
168
  - (void)launch
145
169
  {
170
+ [self fb_assertInstalledByAction:@"launched"];
146
171
  [super launch];
147
172
  if (![self fb_waitForAppElement:APP_STATE_CHANGE_TIMEOUT]) {
148
173
  [FBLogger logFmt:@"The application '%@' is not running in foreground after %.2f seconds", self.bundleID, APP_STATE_CHANGE_TIMEOUT];
149
174
  }
150
175
  }
151
176
 
177
+ - (void)activate
178
+ {
179
+ [self fb_assertInstalledByAction:@"activated"];
180
+ [super activate];
181
+ }
182
+
152
183
  - (void)terminate
153
184
  {
154
185
  [super terminate];
@@ -181,4 +212,9 @@ static const NSTimeInterval APP_STATE_CHANGE_TIMEOUT = 5.0;
181
212
  error:error];
182
213
  }
183
214
 
215
+ - (BOOL)fb_isInstalled
216
+ {
217
+ return [[LSApplicationWorkspace defaultWorkspace] applicationIsInstalled:self.bundleID];
218
+ }
219
+
184
220
  @end
@@ -24,7 +24,8 @@
24
24
  commandStatus = [FBCommandStatus noSuchDriverErrorWithMessage:exception.reason
25
25
  traceback:traceback];
26
26
  } else if ([exception.name isEqualToString:FBInvalidArgumentException]
27
- || [exception.name isEqualToString:FBElementAttributeUnknownException]) {
27
+ || [exception.name isEqualToString:FBElementAttributeUnknownException]
28
+ || [exception.name isEqualToString:FBApplicationMissingException]) {
28
29
  commandStatus = [FBCommandStatus invalidArgumentErrorWithMessage:exception.reason
29
30
  traceback:traceback];
30
31
  } else if ([exception.name isEqualToString:FBApplicationCrashedException]
@@ -49,4 +49,7 @@ extern NSString *const FBClassChainQueryParseException;
49
49
  /*! Exception used to notify about application crash */
50
50
  extern NSString *const FBApplicationCrashedException;
51
51
 
52
+ /*! Exception used to notify about the application is not installed */
53
+ extern NSString *const FBApplicationMissingException;
54
+
52
55
  NS_ASSUME_NONNULL_END
@@ -20,3 +20,4 @@ NSString *const FBInvalidXPathException = @"FBInvalidXPathException";
20
20
  NSString *const FBXPathQueryEvaluationException = @"FBXPathQueryEvaluationException";
21
21
  NSString *const FBClassChainQueryParseException = @"FBClassChainQueryParseException";
22
22
  NSString *const FBApplicationCrashedException = @"FBApplicationCrashedException";
23
+ NSString *const FBApplicationMissingException = @"FBApplicationMissingException";
@@ -11,6 +11,7 @@
11
11
 
12
12
  #import "FBIntegrationTestCase.h"
13
13
  #import "FBApplication.h"
14
+ #import "FBExceptions.h"
14
15
  #import "FBMacros.h"
15
16
  #import "FBSession.h"
16
17
  #import "FBXCodeCompatibility.h"
@@ -100,6 +101,34 @@ static NSString *const SETTINGS_BUNDLE_ID = @"com.apple.Preferences";
100
101
  FBAssertWaitTillBecomesTrue([self.session.activeApplication.bundleID isEqualToString:testedApp.bundleID]);
101
102
  }
102
103
 
104
+ - (void)testAppWithInvalidBundleIDCannotBeStarted
105
+ {
106
+ FBApplication *testedApp = [[FBApplication alloc] initWithBundleIdentifier:@"yolo"];
107
+ @try {
108
+ [testedApp launch];
109
+ XCTFail(@"An exception is expected to be thrown");
110
+ } @catch (NSException *exception) {
111
+ XCTAssertEqualObjects(FBApplicationMissingException, exception.name);
112
+ }
113
+ }
114
+
115
+ - (void)testAppWithInvalidBundleIDCannotBeActivated
116
+ {
117
+ FBApplication *testedApp = [[FBApplication alloc] initWithBundleIdentifier:@"yolo"];
118
+ @try {
119
+ [testedApp activate];
120
+ XCTFail(@"An exception is expected to be thrown");
121
+ } @catch (NSException *exception) {
122
+ XCTAssertEqualObjects(FBApplicationMissingException, exception.name);
123
+ }
124
+ }
125
+
126
+ - (void)testAppWithInvalidBundleIDCannotBeTerminated
127
+ {
128
+ FBApplication *testedApp = [[FBApplication alloc] initWithBundleIdentifier:@"yolo"];
129
+ [testedApp terminate];
130
+ }
131
+
103
132
  - (void)testLaunchUnattachedApp
104
133
  {
105
134
  [FBUnattachedAppLauncher launchAppWithBundleId:SETTINGS_BUNDLE_ID];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appium-webdriveragent",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
4
4
  "description": "Package bundling WebDriverAgent",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {