appium-webdriveragent 16.15.0 → 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,9 @@
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
+
1
7
  ## [16.15.0](https://github.com/appium/WebDriverAgent/compare/v16.14.2...v16.15.0) (2026-10-12)
2
8
 
3
9
  ### Features
@@ -15,11 +15,11 @@
15
15
  <key>CFBundlePackageType</key>
16
16
  <string>FMWK</string>
17
17
  <key>CFBundleShortVersionString</key>
18
- <string>16.15.0</string>
18
+ <string>16.15.1</string>
19
19
  <key>CFBundleSignature</key>
20
20
  <string>????</string>
21
21
  <key>CFBundleVersion</key>
22
- <string>16.15.0</string>
22
+ <string>16.15.1</string>
23
23
  <key>NSPrincipalClass</key>
24
24
  <string/>
25
25
  </dict>
@@ -50,7 +50,7 @@ NSString *const FBSessionWasKilledNotification = @"FBSessionWasKilledNotificatio
50
50
  @property (nonatomic, nullable) FBAlertsMonitor *alertsMonitor;
51
51
  @property (nonatomic, readwrite) NSMutableDictionary<NSNumber *, NSMutableDictionary<NSString *, NSNumber *> *> *elementsVisibilityCache;
52
52
 
53
- - (BOOL)fb_isTestedApplicationSameAsSystemAppWithTimeout:(NSTimeInterval)timeout;
53
+ - (BOOL)fb_isApplicationSameAsSystemApp:(XCUIApplication *)application timeout:(NSTimeInterval)timeout;
54
54
  - (void)fb_terminateTestedApplicationWithTimeout:(NSTimeInterval)timeout generation:(NSUInteger)generation;
55
55
  @end
56
56
 
@@ -333,7 +333,7 @@ static NSUInteger _committedTerminationCount = 0;
333
333
  if (nil != self.testedApplication
334
334
  && FBConfiguration.sharedInstance.shouldTerminateApp
335
335
  && self.testedApplication.running
336
- && ![self fb_isTestedApplicationSameAsSystemAppWithTimeout:FB_IS_SYSTEM_APP_CHECK_TIMEOUT_SEC]) {
336
+ && ![self fb_isApplicationSameAsSystemApp:self.testedApplication timeout:FB_IS_SYSTEM_APP_CHECK_TIMEOUT_SEC]) {
337
337
  // Blocks until the app is either actually terminated or durably given up on (never left
338
338
  // pending) - see -fb_terminateTestedApplicationWithTimeout:generation: - so it's safe to
339
339
  // report this teardown as finished as soon as this returns.
@@ -401,6 +401,22 @@ static NSUInteger _committedTerminationCount = 0;
401
401
  environment:(nullable NSDictionary <NSString *, NSString *> *)environment
402
402
  asApplicationUnderTest:(BOOL)asApplicationUnderTest
403
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
+
404
420
  XCUIApplication *app = [self makeApplicationWithBundleId:bundleIdentifier];
405
421
  if (nil == shouldWaitForQuiescence) {
406
422
  // Iherit the quiescence check setting from the main app under test by default.
@@ -419,9 +435,36 @@ static NSUInteger _committedTerminationCount = 0;
419
435
  [app activate];
420
436
  }
421
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
+ }
422
467
  [FBLogger logFmt:@"The application '%@' is set as the application under test", bundleIdentifier];
423
- self.testedApplication = app;
424
- self.shouldAppsWaitForQuiescence = app.fb_shouldWaitForQuiescence;
425
468
  }
426
469
  if ([app fb_isSameAppAs:self.testedApplication]) {
427
470
  self.isTestedApplicationExpectedToRun = YES;
@@ -462,9 +505,9 @@ static NSUInteger _committedTerminationCount = 0;
462
505
  }
463
506
 
464
507
  // Has no async variant and can block on the shared accessibility channel. Run off-thread and give
465
- // 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
466
509
  // termination rather than risking terminating springboard.
467
- - (BOOL)fb_isTestedApplicationSameAsSystemAppWithTimeout:(NSTimeInterval)timeout
510
+ - (BOOL)fb_isApplicationSameAsSystemApp:(XCUIApplication *)application timeout:(NSTimeInterval)timeout
468
511
  {
469
512
  __block XCUIApplication *systemApp = nil;
470
513
  __block NSException *caughtException = nil;
@@ -473,7 +516,7 @@ static NSUInteger _committedTerminationCount = 0;
473
516
  // Undocumented private API; guard in case it hard-asserts off-main like -terminate does on
474
517
  // some Xcode/iOS version - uncaught, that would crash the whole process.
475
518
  @try {
476
- systemApp = XCUIApplication.fb_systemApplication;
519
+ systemApp = [[application class] fb_systemApplication];
477
520
  } @catch (NSException *e) {
478
521
  caughtException = e;
479
522
  }
@@ -481,10 +524,10 @@ static NSUInteger _committedTerminationCount = 0;
481
524
  });
482
525
  int64_t timeoutNs = (int64_t)(timeout * NSEC_PER_SEC);
483
526
  if (0 != dispatch_semaphore_wait(sem, dispatch_time(DISPATCH_TIME_NOW, timeoutNs)) || nil != caughtException) {
484
- [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];
485
528
  return YES;
486
529
  }
487
- return [self.testedApplication fb_isSameAppAs:systemApp];
530
+ return [application fb_isSameAppAs:systemApp];
488
531
  }
489
532
 
490
533
  // -terminate hard-asserts off-main, but -kill can now run on a background queue. Dispatching to
@@ -172,6 +172,32 @@ static NSString *const SETTINGS_BUNDLE_ID = @"com.apple.Preferences";
172
172
  XCTAssertNoThrow(self.session.activeApplication);
173
173
  }
174
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
+
175
201
  - (void)testLaunchUnattachedApp
176
202
  {
177
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.15.0",
3
+ "version": "16.15.1",
4
4
  "description": "Package bundling WebDriverAgent",
5
5
  "keywords": [
6
6
  "Appium",