appium-webdriveragent 16.14.2 → 16.15.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,15 @@
1
+ ## [16.15.1](https://github.com/appium/WebDriverAgent/compare/v16.15.0...v16.15.1) (2026-10-16)
2
+
3
+ ### Bug Fixes
4
+
5
+ * clean up AUT launches after session deletion ([#1297](https://github.com/appium/WebDriverAgent/issues/1297)) ([5139caf](https://github.com/appium/WebDriverAgent/commit/5139caf298b08cd22e4ed8ffc94ba74565783c52))
6
+
7
+ ## [16.15.0](https://github.com/appium/WebDriverAgent/compare/v16.14.2...v16.15.0) (2026-10-12)
8
+
9
+ ### Features
10
+
11
+ * add asAppUnderTest flag to /wda/apps/launch ([#1289](https://github.com/appium/WebDriverAgent/issues/1289)) ([f5c0688](https://github.com/appium/WebDriverAgent/commit/f5c068873ff6dcd1ce444d26246c102cc379d5bf))
12
+
1
13
  ## [16.14.2](https://github.com/appium/WebDriverAgent/compare/v16.14.1...v16.14.2) (2026-10-08)
2
14
 
3
15
  ### Bug Fixes
@@ -131,7 +131,8 @@
131
131
  [request.session launchApplicationWithBundleId:(id)request.arguments[@"bundleId"]
132
132
  shouldWaitForQuiescence:request.arguments[@"shouldWaitForQuiescence"]
133
133
  arguments:request.arguments[@"arguments"]
134
- environment:request.arguments[@"environment"]];
134
+ environment:request.arguments[@"environment"]
135
+ asApplicationUnderTest:[request.arguments[@"asAppUnderTest"] boolValue]];
135
136
  return FBResponseWithOK();
136
137
  }
137
138
 
@@ -15,11 +15,11 @@
15
15
  <key>CFBundlePackageType</key>
16
16
  <string>FMWK</string>
17
17
  <key>CFBundleShortVersionString</key>
18
- <string>16.14.2</string>
18
+ <string>16.15.1</string>
19
19
  <key>CFBundleSignature</key>
20
20
  <string>????</string>
21
21
  <key>CFBundleVersion</key>
22
- <string>16.14.2</string>
22
+ <string>16.15.1</string>
23
23
  <key>NSPrincipalClass</key>
24
24
  <string/>
25
25
  </dict>
@@ -107,6 +107,28 @@ extern NSString* const FBSessionWasKilledNotification;
107
107
  arguments:(nullable NSArray<NSString *> *)arguments
108
108
  environment:(nullable NSDictionary <NSString *, NSString *> *)environment;
109
109
 
110
+ /**
111
+ Launch an application with given bundle identifier in scope of current session
112
+ and optionally make it the application under test of this session.
113
+
114
+ @param bundleIdentifier Valid bundle identifier of the application to be launched
115
+ @param shouldWaitForQuiescence whether to wait for quiescence on application startup.
116
+ If not provided then the setting of the current application under test is inherited.
117
+ If there is no application under test yet then quiescence is only awaited if asApplicationUnderTest is YES
118
+ @param arguments The optional array of application command line arguments. The arguments are going to be applied if the application was not running before.
119
+ @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.
120
+ @param asApplicationUnderTest If YES then the launched application replaces the current application under test
121
+ of the session (if any), the same way as if it was launched on session startup: other applications launched later
122
+ inherit its quiescence setting, system alerts over it are respected, its unexpected termination is reported as a crash
123
+ and it gets terminated on session deletion if shouldTerminateApp is enabled
124
+ @return The application instance
125
+ */
126
+ - (XCUIApplication *)launchApplicationWithBundleId:(NSString *)bundleIdentifier
127
+ shouldWaitForQuiescence:(nullable NSNumber *)shouldWaitForQuiescence
128
+ arguments:(nullable NSArray<NSString *> *)arguments
129
+ environment:(nullable NSDictionary <NSString *, NSString *> *)environment
130
+ asApplicationUnderTest:(BOOL)asApplicationUnderTest;
131
+
110
132
  /**
111
133
  Activate an application with given bundle identifier in scope of current session.
112
134
  !This method is only available since Xcode9 SDK
@@ -43,13 +43,14 @@ static const NSTimeInterval FB_KILL_WAIT_TIMEOUT_SEC = 35.;
43
43
  NSString *const FBSessionWasKilledNotification = @"FBSessionWasKilledNotification";
44
44
 
45
45
  @interface FBSession ()
46
- @property (nullable, nonatomic) XCUIApplication *testedApplication;
46
+ // Atomic, since /wda/apps/launch may replace it while a concurrent DELETE /session reads it in -kill
47
+ @property (nullable, atomic) XCUIApplication *testedApplication;
47
48
  @property (nonatomic) BOOL isTestedApplicationExpectedToRun;
48
49
  @property (nonatomic) BOOL shouldAppsWaitForQuiescence;
49
50
  @property (nonatomic, nullable) FBAlertsMonitor *alertsMonitor;
50
51
  @property (nonatomic, readwrite) NSMutableDictionary<NSNumber *, NSMutableDictionary<NSString *, NSNumber *> *> *elementsVisibilityCache;
51
52
 
52
- - (BOOL)fb_isTestedApplicationSameAsSystemAppWithTimeout:(NSTimeInterval)timeout;
53
+ - (BOOL)fb_isApplicationSameAsSystemApp:(XCUIApplication *)application timeout:(NSTimeInterval)timeout;
53
54
  - (void)fb_terminateTestedApplicationWithTimeout:(NSTimeInterval)timeout generation:(NSUInteger)generation;
54
55
  @end
55
56
 
@@ -332,7 +333,7 @@ static NSUInteger _committedTerminationCount = 0;
332
333
  if (nil != self.testedApplication
333
334
  && FBConfiguration.sharedInstance.shouldTerminateApp
334
335
  && self.testedApplication.running
335
- && ![self fb_isTestedApplicationSameAsSystemAppWithTimeout:FB_IS_SYSTEM_APP_CHECK_TIMEOUT_SEC]) {
336
+ && ![self fb_isApplicationSameAsSystemApp:self.testedApplication timeout:FB_IS_SYSTEM_APP_CHECK_TIMEOUT_SEC]) {
336
337
  // Blocks until the app is either actually terminated or durably given up on (never left
337
338
  // pending) - see -fb_terminateTestedApplicationWithTimeout:generation: - so it's safe to
338
339
  // report this teardown as finished as soon as this returns.
@@ -387,10 +388,42 @@ static NSUInteger _committedTerminationCount = 0;
387
388
  arguments:(nullable NSArray<NSString *> *)arguments
388
389
  environment:(nullable NSDictionary <NSString *, NSString *> *)environment
389
390
  {
391
+ return [self launchApplicationWithBundleId:bundleIdentifier
392
+ shouldWaitForQuiescence:shouldWaitForQuiescence
393
+ arguments:arguments
394
+ environment:environment
395
+ asApplicationUnderTest:NO];
396
+ }
397
+
398
+ - (XCUIApplication *)launchApplicationWithBundleId:(NSString *)bundleIdentifier
399
+ shouldWaitForQuiescence:(nullable NSNumber *)shouldWaitForQuiescence
400
+ arguments:(nullable NSArray<NSString *> *)arguments
401
+ environment:(nullable NSDictionary <NSString *, NSString *> *)environment
402
+ asApplicationUnderTest:(BOOL)asApplicationUnderTest
403
+ {
404
+ NSCondition *condition = self.class.teardownCondition;
405
+ NSUInteger generation = 0;
406
+ BOOL shouldTerminateApp = NO;
407
+ if (asApplicationUnderTest) {
408
+ [condition lock];
409
+ BOOL isActive = self == _activeSession;
410
+ generation = _sessionGeneration;
411
+ shouldTerminateApp = FBConfiguration.sharedInstance.shouldTerminateApp;
412
+ [condition unlock];
413
+ if (!isActive) {
414
+ @throw [NSException exceptionWithName:FBSessionDoesNotExistException
415
+ reason:@"Session does not exist"
416
+ userInfo:nil];
417
+ }
418
+ }
419
+
390
420
  XCUIApplication *app = [self makeApplicationWithBundleId:bundleIdentifier];
391
421
  if (nil == shouldWaitForQuiescence) {
392
- // Iherit the quiescence check setting from the main app under test by default
393
- app.fb_shouldWaitForQuiescence = nil != self.testedApplication && self.shouldAppsWaitForQuiescence;
422
+ // Iherit the quiescence check setting from the main app under test by default.
423
+ // The first app under test of the session waits for quiescence, as it would on session startup
424
+ app.fb_shouldWaitForQuiescence = nil == self.testedApplication
425
+ ? asApplicationUnderTest
426
+ : self.shouldAppsWaitForQuiescence;
394
427
  } else {
395
428
  app.fb_shouldWaitForQuiescence = [shouldWaitForQuiescence boolValue];
396
429
  }
@@ -401,6 +434,38 @@ static NSUInteger _committedTerminationCount = 0;
401
434
  } else {
402
435
  [app activate];
403
436
  }
437
+ if (asApplicationUnderTest) {
438
+ BOOL waitForQuiescence = app.fb_shouldWaitForQuiescence;
439
+ // A DELETE can finish while launch/activate is still waiting for XCTest.
440
+ // Publish the AUT under the same lock that -kill uses to clear the session.
441
+ [condition lock];
442
+ BOOL isActive = self == _activeSession && generation == _sessionGeneration;
443
+ if (isActive) {
444
+ self.testedApplication = app;
445
+ self.shouldAppsWaitForQuiescence = waitForQuiescence;
446
+ }
447
+ [condition unlock];
448
+ if (!isActive) {
449
+ // The HTTP request may already have been abandoned, but its handler keeps
450
+ // running. Clean up only while this launch still owns the generation;
451
+ // a replacement session may already be using the same bundle identifier.
452
+ if (shouldTerminateApp
453
+ && ![self fb_isApplicationSameAsSystemApp:app timeout:FB_IS_SYSTEM_APP_CHECK_TIMEOUT_SEC]
454
+ && [self.class beginTerminationForGeneration:generation]) {
455
+ @try {
456
+ [app terminate];
457
+ } @catch (NSException *e) {
458
+ [FBLogger logFmt:@"%@", e.description];
459
+ } @finally {
460
+ [self.class endTermination];
461
+ }
462
+ }
463
+ @throw [NSException exceptionWithName:FBSessionDoesNotExistException
464
+ reason:@"Session was deleted during application launch"
465
+ userInfo:nil];
466
+ }
467
+ [FBLogger logFmt:@"The application '%@' is set as the application under test", bundleIdentifier];
468
+ }
404
469
  if ([app fb_isSameAppAs:self.testedApplication]) {
405
470
  self.isTestedApplicationExpectedToRun = YES;
406
471
  }
@@ -440,9 +505,9 @@ static NSUInteger _committedTerminationCount = 0;
440
505
  }
441
506
 
442
507
  // Has no async variant and can block on the shared accessibility channel. Run off-thread and give
443
- // up after `timeout`, assuming the tested app IS the system app - safer, since it means skipping
508
+ // up after `timeout`, assuming the supplied app IS the system app - safer, since it means skipping
444
509
  // termination rather than risking terminating springboard.
445
- - (BOOL)fb_isTestedApplicationSameAsSystemAppWithTimeout:(NSTimeInterval)timeout
510
+ - (BOOL)fb_isApplicationSameAsSystemApp:(XCUIApplication *)application timeout:(NSTimeInterval)timeout
446
511
  {
447
512
  __block XCUIApplication *systemApp = nil;
448
513
  __block NSException *caughtException = nil;
@@ -451,7 +516,7 @@ static NSUInteger _committedTerminationCount = 0;
451
516
  // Undocumented private API; guard in case it hard-asserts off-main like -terminate does on
452
517
  // some Xcode/iOS version - uncaught, that would crash the whole process.
453
518
  @try {
454
- systemApp = XCUIApplication.fb_systemApplication;
519
+ systemApp = [[application class] fb_systemApplication];
455
520
  } @catch (NSException *e) {
456
521
  caughtException = e;
457
522
  }
@@ -459,10 +524,10 @@ static NSUInteger _committedTerminationCount = 0;
459
524
  });
460
525
  int64_t timeoutNs = (int64_t)(timeout * NSEC_PER_SEC);
461
526
  if (0 != dispatch_semaphore_wait(sem, dispatch_time(DISPATCH_TIME_NOW, timeoutNs)) || nil != caughtException) {
462
- [FBLogger logFmt:@"Could not determine the system application within %@ seconds%@; assuming '%@' might be it and skipping its termination", @(timeout), nil == caughtException ? @"" : [NSString stringWithFormat:@" (%@)", caughtException.description], self.testedApplication.bundleID];
527
+ [FBLogger logFmt:@"Could not determine the system application within %@ seconds%@; assuming '%@' might be it and skipping its termination", @(timeout), nil == caughtException ? @"" : [NSString stringWithFormat:@" (%@)", caughtException.description], application.bundleID];
463
528
  return YES;
464
529
  }
465
- return [self.testedApplication fb_isSameAppAs:systemApp];
530
+ return [application fb_isSameAppAs:systemApp];
466
531
  }
467
532
 
468
533
  // -terminate hard-asserts off-main, but -kill can now run on a background queue. Dispatching to
@@ -16,6 +16,7 @@
16
16
  #import "FBTestMacros.h"
17
17
  #import "FBUnattachedAppLauncher.h"
18
18
  #import "XCUIApplication+FBHelpers.h"
19
+ #import "XCUIApplication+FBQuiescence.h"
19
20
  #import "XCUIApplication.h"
20
21
 
21
22
  @interface FBSession (Tests)
@@ -101,6 +102,102 @@ static NSString *const SETTINGS_BUNDLE_ID = @"com.apple.Preferences";
101
102
  FBAssertWaitTillBecomesTrue([self.session.activeApplication.bundleID isEqualToString:testedApp.bundleID]);
102
103
  }
103
104
 
105
+ - (NSString *)startSessionWithoutApplicationUnderTest
106
+ {
107
+ NSString *bundleId = (NSString *)self.testedApplication.bundleID;
108
+ [self.testedApplication terminate];
109
+ FBAssertWaitTillBecomesTrue(self.testedApplication.state == XCUIApplicationStateNotRunning);
110
+ self.session = [FBSession initWithApplication:nil];
111
+ return bundleId;
112
+ }
113
+
114
+ - (void)testApplicationCanBeLaunchedAsApplicationUnderTest
115
+ {
116
+ NSString *bundleId = [self startSessionWithoutApplicationUnderTest];
117
+ XCUIApplication *app = [self.session launchApplicationWithBundleId:bundleId
118
+ shouldWaitForQuiescence:nil
119
+ arguments:nil
120
+ environment:nil
121
+ asApplicationUnderTest:YES];
122
+ FBAssertWaitTillBecomesTrue([self.session.activeApplication.bundleID isEqualToString:bundleId]);
123
+ XCTAssertEqual(app, self.session.activeApplication);
124
+ XCTAssertTrue(app.fb_shouldWaitForQuiescence);
125
+
126
+ XCUIApplication *settingsApp = [self.session launchApplicationWithBundleId:SETTINGS_BUNDLE_ID
127
+ shouldWaitForQuiescence:nil
128
+ arguments:nil
129
+ environment:nil];
130
+ FBAssertWaitTillBecomesTrue([self.session.activeApplication.bundleID isEqualToString:SETTINGS_BUNDLE_ID]);
131
+ XCTAssertTrue(settingsApp.fb_shouldWaitForQuiescence);
132
+ }
133
+
134
+ - (void)testApplicationLaunchedAsApplicationUnderTestRespectsQuiescenceArgument
135
+ {
136
+ NSString *bundleId = [self startSessionWithoutApplicationUnderTest];
137
+ XCUIApplication *app = [self.session launchApplicationWithBundleId:bundleId
138
+ shouldWaitForQuiescence:@NO
139
+ arguments:nil
140
+ environment:nil
141
+ asApplicationUnderTest:YES];
142
+ FBAssertWaitTillBecomesTrue([self.session.activeApplication.bundleID isEqualToString:bundleId]);
143
+ XCTAssertEqual(app, self.session.activeApplication);
144
+ XCTAssertFalse(app.fb_shouldWaitForQuiescence);
145
+ }
146
+
147
+ - (void)testCrashOfApplicationLaunchedAsApplicationUnderTestIsDetected
148
+ {
149
+ NSString *bundleId = [self startSessionWithoutApplicationUnderTest];
150
+ XCUIApplication *app = [self.session launchApplicationWithBundleId:bundleId
151
+ shouldWaitForQuiescence:nil
152
+ arguments:nil
153
+ environment:nil
154
+ asApplicationUnderTest:YES];
155
+ FBAssertWaitTillBecomesTrue([self.session.activeApplication.bundleID isEqualToString:bundleId]);
156
+ [app terminate];
157
+ FBAssertWaitTillBecomesTrue(app.state == XCUIApplicationStateNotRunning);
158
+ XCTAssertThrowsSpecificNamed(self.session.activeApplication, NSException, FBApplicationCrashedException);
159
+ }
160
+
161
+ - (void)testApplicationIsNotLaunchedAsApplicationUnderTestByDefault
162
+ {
163
+ NSString *bundleId = [self startSessionWithoutApplicationUnderTest];
164
+ XCUIApplication *app = [self.session launchApplicationWithBundleId:bundleId
165
+ shouldWaitForQuiescence:nil
166
+ arguments:nil
167
+ environment:nil];
168
+ FBAssertWaitTillBecomesTrue([self.session.activeApplication.bundleID isEqualToString:bundleId]);
169
+ XCTAssertFalse(app.fb_shouldWaitForQuiescence);
170
+ [app terminate];
171
+ FBAssertWaitTillBecomesTrue(app.state == XCUIApplicationStateNotRunning);
172
+ XCTAssertNoThrow(self.session.activeApplication);
173
+ }
174
+
175
+ // DELETE /session while /wda/apps/launch is still launching the app as the application under
176
+ // test: whichever of them finishes first, the app must not outlive the session. Settings takes
177
+ // long enough to launch for the deletion to usually land in the middle.
178
+ - (void)testApplicationLaunchedAsApplicationUnderTestDoesNotOutliveConcurrentSessionDeletion
179
+ {
180
+ [self startSessionWithoutApplicationUnderTest];
181
+ XCUIApplication *settingsApp = [[XCUIApplication alloc] initWithBundleIdentifier:SETTINGS_BUNDLE_ID];
182
+ [settingsApp terminate];
183
+ FBAssertWaitTillBecomesTrue(settingsApp.state == XCUIApplicationStateNotRunning);
184
+ FBSession *session = self.session;
185
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)),
186
+ dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
187
+ [session kill];
188
+ });
189
+ @try {
190
+ [session launchApplicationWithBundleId:SETTINGS_BUNDLE_ID
191
+ shouldWaitForQuiescence:nil
192
+ arguments:nil
193
+ environment:nil
194
+ asApplicationUnderTest:YES];
195
+ } @catch (NSException *e) {
196
+ XCTAssertEqualObjects(e.name, FBSessionDoesNotExistException);
197
+ }
198
+ FBAssertWaitTillBecomesTrue(settingsApp.state == XCUIApplicationStateNotRunning);
199
+ }
200
+
104
201
  - (void)testLaunchUnattachedApp
105
202
  {
106
203
  [FBUnattachedAppLauncher launchAppWithBundleId:SETTINGS_BUNDLE_ID];
@@ -9,9 +9,67 @@
9
9
  #import <XCTest/XCTest.h>
10
10
 
11
11
  #import "FBSession.h"
12
+ #import "FBSession-Private.h"
13
+ #import "FBExceptions.h"
12
14
  #import "FBConfiguration.h"
13
15
  #import "XCUIApplicationDouble.h"
14
16
 
17
+ @interface FBSession (SystemApplicationTests)
18
+ - (BOOL)fb_isApplicationSameAsSystemApp:(XCUIApplication *)application timeout:(NSTimeInterval)timeout;
19
+ @end
20
+
21
+ static id (^FBSystemApplicationLookup)(void);
22
+
23
+ // Run teardown at the exact point where launch has started but the AUT has
24
+ // not yet been published. No wall-clock sleeps or simulator launch timing.
25
+ @interface FBAUTLaunchApplicationDouble : XCUIApplicationDouble
26
+ @property (nonatomic, copy) void (^duringLaunch)(void);
27
+ @property (nonatomic, copy) NSArray *launchArguments;
28
+ @property (nonatomic, copy) NSDictionary *launchEnvironment;
29
+ @property (nonatomic) BOOL didLaunch;
30
+ @end
31
+
32
+ @implementation FBAUTLaunchApplicationDouble
33
+ + (id)fb_systemApplication
34
+ {
35
+ return FBSystemApplicationLookup ? FBSystemApplicationLookup() : nil;
36
+ }
37
+ - (void)launch
38
+ {
39
+ self.didLaunch = YES;
40
+ if (self.duringLaunch) {
41
+ self.duringLaunch();
42
+ }
43
+ }
44
+ - (BOOL)fb_isSameAppAs:(id)application
45
+ {
46
+ return self == application;
47
+ }
48
+ @end
49
+
50
+ @interface FBAUTTerminationFailureApplicationDouble : FBAUTLaunchApplicationDouble
51
+ @property (nonatomic) BOOL didAttemptTermination;
52
+ @end
53
+
54
+ @implementation FBAUTTerminationFailureApplicationDouble
55
+ - (void)terminate
56
+ {
57
+ self.didAttemptTermination = YES;
58
+ @throw [NSException exceptionWithName:@"TerminationFailure" reason:nil userInfo:nil];
59
+ }
60
+ @end
61
+
62
+ @interface FBAUTLaunchSession : FBSession
63
+ @property (nonatomic, strong) FBAUTLaunchApplicationDouble *launchApplication;
64
+ @end
65
+
66
+ @implementation FBAUTLaunchSession
67
+ - (XCUIApplication *)makeApplicationWithBundleId:(NSString *)bundleIdentifier
68
+ {
69
+ return (id)self.launchApplication;
70
+ }
71
+ @end
72
+
15
73
  @interface FBSessionTests : XCTestCase
16
74
  @property (nonatomic, strong) FBSession *session;
17
75
  @property (nonatomic, strong) XCUIApplication *testedApplication;
@@ -31,6 +89,10 @@
31
89
 
32
90
  - (void)tearDown
33
91
  {
92
+ if ([self.session isKindOfClass:FBAUTLaunchSession.class]) {
93
+ ((FBAUTLaunchSession *)self.session).launchApplication.duringLaunch = nil;
94
+ }
95
+ FBSystemApplicationLookup = nil;
34
96
  [self.session kill];
35
97
  FBConfiguration.sharedInstance.shouldTerminateApp = self.shouldTerminateAppValue;
36
98
  [super tearDown];
@@ -64,4 +126,143 @@
64
126
  XCTAssertNil([FBSession activeSession]);
65
127
  }
66
128
 
129
+ - (FBAUTLaunchApplicationDouble *)prepareAUTLaunch
130
+ {
131
+ FBAUTLaunchSession *session = [FBAUTLaunchSession new];
132
+ session.identifier = NSUUID.UUID.UUIDString;
133
+ session.launchApplication = [FBAUTLaunchApplicationDouble new];
134
+ [FBSession markSessionActive:session];
135
+ self.session = session;
136
+ return session.launchApplication;
137
+ }
138
+
139
+ - (void)launchAsAUT
140
+ {
141
+ [self.session launchApplicationWithBundleId:@"com.facebook.awesome"
142
+ shouldWaitForQuiescence:nil
143
+ arguments:nil
144
+ environment:nil
145
+ asApplicationUnderTest:YES];
146
+ }
147
+
148
+ - (void)testCompletedLaunchRegistersAUT
149
+ {
150
+ FBAUTLaunchApplicationDouble *app = [self prepareAUTLaunch];
151
+ XCTAssertNoThrow([self launchAsAUT]);
152
+ XCTAssertEqual([self.session valueForKey:@"testedApplication"], app);
153
+ XCTAssertFalse(app.didTerminate);
154
+ }
155
+
156
+ - (void)testDeletedSessionCleansUpInFlightAUTLaunch
157
+ {
158
+ FBAUTLaunchApplicationDouble *app = [self prepareAUTLaunch];
159
+ FBConfiguration.sharedInstance.shouldTerminateApp = YES;
160
+ FBSession *session = self.session;
161
+ app.duringLaunch = ^{ [session kill]; };
162
+ XCTAssertThrowsSpecificNamed([self launchAsAUT], NSException,
163
+ FBSessionDoesNotExistException);
164
+ XCTAssertTrue(app.didTerminate);
165
+ XCTAssertNil([self.session valueForKey:@"testedApplication"]);
166
+ XCTAssertNil(FBSession.activeSession);
167
+ }
168
+
169
+ - (void)testTerminationFailurePreservesDeletedSessionErrorAndReleasesClaim
170
+ {
171
+ [self prepareAUTLaunch];
172
+ FBAUTTerminationFailureApplicationDouble *app = [FBAUTTerminationFailureApplicationDouble new];
173
+ ((FBAUTLaunchSession *)self.session).launchApplication = app;
174
+ FBConfiguration.sharedInstance.shouldTerminateApp = YES;
175
+ FBSession *session = self.session;
176
+ app.duringLaunch = ^{ [session kill]; };
177
+
178
+ XCTAssertThrowsSpecificNamed([self launchAsAUT], NSException, FBSessionDoesNotExistException);
179
+ XCTAssertTrue(app.didAttemptTermination);
180
+ XCTAssertNil([self.session valueForKey:@"testedApplication"]);
181
+ XCTAssertNil(FBSession.activeSession);
182
+
183
+ // Creating the next session must succeed even when cleanup termination throws.
184
+ // A leaked generation claim would make this fail with a session creation error.
185
+ FBSession *replacement = nil;
186
+ XCTAssertNoThrow(replacement = [FBSession initWithApplication:nil]);
187
+ XCTAssertNotNil(replacement);
188
+ XCTAssertEqual(FBSession.activeSession, replacement);
189
+ [replacement kill];
190
+ }
191
+
192
+ - (void)testDeletedSessionPreservesAppWhenTerminationIsDisabled
193
+ {
194
+ FBAUTLaunchApplicationDouble *app = [self prepareAUTLaunch];
195
+ FBSession *session = self.session;
196
+ app.duringLaunch = ^{ [session kill]; };
197
+ XCTAssertThrowsSpecificNamed([self launchAsAUT], NSException,
198
+ FBSessionDoesNotExistException);
199
+ XCTAssertFalse(app.didTerminate);
200
+ }
201
+
202
+ - (void)testAbandonedAUTLaunchDoesNotTerminateReplacementSessionApp
203
+ {
204
+ FBAUTLaunchApplicationDouble *app = [self prepareAUTLaunch];
205
+ FBConfiguration.sharedInstance.shouldTerminateApp = YES;
206
+ FBSession *session = self.session;
207
+ __block FBSession *replacement;
208
+ app.duringLaunch = ^{
209
+ [session kill];
210
+ replacement = [FBSession initWithApplication:(id)app];
211
+ };
212
+ XCTAssertThrowsSpecificNamed([self launchAsAUT], NSException,
213
+ FBSessionDoesNotExistException);
214
+ XCTAssertFalse(app.didTerminate);
215
+ XCTAssertEqual(FBSession.activeSession, replacement);
216
+ [replacement kill];
217
+ }
218
+
219
+ - (void)testAUTLaunchRejectsAnAlreadyDeletedSession
220
+ {
221
+ FBAUTLaunchApplicationDouble *app = [self prepareAUTLaunch];
222
+ [self.session kill];
223
+ XCTAssertThrowsSpecificNamed([self launchAsAUT], NSException,
224
+ FBSessionDoesNotExistException);
225
+ XCTAssertFalse(app.didLaunch);
226
+ }
227
+
228
+ - (void)testSystemApplicationCheckUsesSuppliedApplication
229
+ {
230
+ FBAUTLaunchApplicationDouble *app = [self prepareAUTLaunch];
231
+ FBSystemApplicationLookup = ^id { return app; };
232
+ XCTAssertTrue([self.session fb_isApplicationSameAsSystemApp:(id)app timeout:1.]);
233
+ FBSystemApplicationLookup = ^id { return nil; };
234
+ XCTAssertFalse([self.session fb_isApplicationSameAsSystemApp:(id)app timeout:1.]);
235
+ }
236
+
237
+ - (void)testSystemApplicationLookupExceptionSkipsTermination
238
+ {
239
+ FBAUTLaunchApplicationDouble *app = [self prepareAUTLaunch];
240
+ FBConfiguration.sharedInstance.shouldTerminateApp = YES;
241
+ FBSession *session = self.session;
242
+ app.duringLaunch = ^{ [session kill]; };
243
+ FBSystemApplicationLookup = ^id {
244
+ @throw [NSException exceptionWithName:@"LookupFailure" reason:nil userInfo:nil];
245
+ };
246
+ XCTAssertThrowsSpecificNamed([self launchAsAUT], NSException, FBSessionDoesNotExistException);
247
+ XCTAssertFalse(app.didTerminate);
248
+ }
249
+
250
+ - (void)testSystemApplicationLookupTimeoutSkipsTermination
251
+ {
252
+ FBAUTLaunchApplicationDouble *app = [self prepareAUTLaunch];
253
+ dispatch_semaphore_t releaseLookup = dispatch_semaphore_create(0);
254
+ XCTestExpectation *finished = [self expectationWithDescription:@"System application lookup finished"];
255
+ FBSystemApplicationLookup = ^id {
256
+ dispatch_semaphore_wait(releaseLookup, DISPATCH_TIME_FOREVER);
257
+ [finished fulfill];
258
+ return nil;
259
+ };
260
+ @try {
261
+ XCTAssertTrue([self.session fb_isApplicationSameAsSystemApp:(id)app timeout:0.01]);
262
+ } @finally {
263
+ dispatch_semaphore_signal(releaseLookup);
264
+ [self waitForExpectationsWithTimeout:5. handler:nil];
265
+ }
266
+ }
267
+
67
268
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appium-webdriveragent",
3
- "version": "16.14.2",
3
+ "version": "16.15.1",
4
4
  "description": "Package bundling WebDriverAgent",
5
5
  "keywords": [
6
6
  "Appium",