Skip to content

Commit 338c67e

Browse files
authored
Merge branch 'master' into long-test-test
2 parents dca3ca0 + 4b256c1 commit 338c67e

15 files changed

Lines changed: 135 additions & 13 deletions

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## [9.5.1](https://github.com/appium/WebDriverAgent/compare/v9.5.0...v9.5.1) (2025-04-10)
2+
3+
### Bug Fixes
4+
5+
* Make sure we don't store element snapshot in the cache ([#1001](https://github.com/appium/WebDriverAgent/issues/1001)) ([cfe052b](https://github.com/appium/WebDriverAgent/commit/cfe052bb3adb3f3b24d0a34f386c60cf1516b308))
6+
7+
## [9.5.0](https://github.com/appium/WebDriverAgent/compare/v9.4.1...v9.5.0) (2025-04-10)
8+
9+
### Features
10+
11+
* Add support for the autoClickAlertSelector setting ([#1002](https://github.com/appium/WebDriverAgent/issues/1002)) ([fd31b95](https://github.com/appium/WebDriverAgent/commit/fd31b9589199d0a7bc76919f6aa7c7c74c498b90))
12+
113
## [9.4.1](https://github.com/appium/WebDriverAgent/compare/v9.4.0...v9.4.1) (2025-04-05)
214

315
### Miscellaneous Chores

WebDriverAgentLib/Categories/XCUIElement+FBClassChain.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ NS_ASSUME_NONNULL_BEGIN
5050
@return an array of descendants matching given class chain
5151
@throws FBUnknownAttributeException if any of predicates in the chain contains unknown attribute(s)
5252
*/
53-
- (NSArray<XCUIElement *> *)fb_descendantsMatchingClassChain:(NSString *)classChainQuery shouldReturnAfterFirstMatch:(BOOL)shouldReturnAfterFirstMatch;
53+
- (NSArray<XCUIElement *> *)fb_descendantsMatchingClassChain:(NSString *)classChainQuery
54+
shouldReturnAfterFirstMatch:(BOOL)shouldReturnAfterFirstMatch;
5455

5556
@end
5657

WebDriverAgentLib/Commands/FBElementCommands.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ + (NSArray *)routes
269269
NSString *focusedUUID = [elementCache storeElement:(useNativeCachingStrategy
270270
? focusedElement
271271
: [focusedElement fb_stableInstanceWithUid:focusedElement.fb_uid])];
272+
focusedElement.lastSnapshot = nil;
272273
if (focusedUUID && [focusedUUID isEqualToString:(id)request.parameters[@"uuid"]]) {
273274
isFocused = YES;
274275
}

WebDriverAgentLib/Commands/FBSessionCommands.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "FBSessionCommands.h"
1111

1212
#import "FBCapabilities.h"
13+
#import "FBClassChainQueryParser.h"
1314
#import "FBConfiguration.h"
1415
#import "FBExceptions.h"
1516
#import "FBLogger.h"
@@ -347,6 +348,7 @@ + (NSArray *)routes
347348
FB_SETTING_INCLUDE_NON_MODAL_ELEMENTS: @([FBConfiguration includeNonModalElements]),
348349
FB_SETTING_ACCEPT_ALERT_BUTTON_SELECTOR: FBConfiguration.acceptAlertButtonSelector,
349350
FB_SETTING_DISMISS_ALERT_BUTTON_SELECTOR: FBConfiguration.dismissAlertButtonSelector,
351+
FB_SETTING_AUTO_CLICK_ALERT_SELECTOR: FBConfiguration.autoClickAlertSelector,
350352
FB_SETTING_DEFAULT_ALERT_ACTION: request.session.defaultAlertAction ?: @"",
351353
FB_SETTING_MAX_TYPING_FREQUENCY: @([FBConfiguration maxTypingFrequency]),
352354
FB_SETTING_RESPECT_SYSTEM_ALERTS: @([FBConfiguration shouldRespectSystemAlerts]),
@@ -431,6 +433,13 @@ + (NSArray *)routes
431433
if (nil != [settings objectForKey:FB_SETTING_DISMISS_ALERT_BUTTON_SELECTOR]) {
432434
[FBConfiguration setDismissAlertButtonSelector:(NSString *)[settings objectForKey:FB_SETTING_DISMISS_ALERT_BUTTON_SELECTOR]];
433435
}
436+
if (nil != [settings objectForKey:FB_SETTING_AUTO_CLICK_ALERT_SELECTOR]) {
437+
FBCommandStatus *status = [self.class configureAutoClickAlertWithSelector:settings[FB_SETTING_AUTO_CLICK_ALERT_SELECTOR]
438+
forSession:request.session];
439+
if (status.hasError) {
440+
return FBResponseWithStatus(status);
441+
}
442+
}
434443
if (nil != [settings objectForKey:FB_SETTING_WAIT_FOR_IDLE_TIMEOUT]) {
435444
[FBConfiguration setWaitForIdleTimeout:[[settings objectForKey:FB_SETTING_WAIT_FOR_IDLE_TIMEOUT] doubleValue]];
436445
}
@@ -467,6 +476,26 @@ + (NSArray *)routes
467476

468477
#pragma mark - Helpers
469478

479+
+ (FBCommandStatus *)configureAutoClickAlertWithSelector:(NSString *)selector
480+
forSession:(FBSession *)session
481+
{
482+
if (0 == [selector length]) {
483+
[FBConfiguration setAutoClickAlertSelector:selector];
484+
[session disableAlertsMonitor];
485+
return [FBCommandStatus ok];
486+
}
487+
488+
NSError *error;
489+
FBClassChain *parsedChain = [FBClassChainQueryParser parseQuery:selector error:&error];
490+
if (nil == parsedChain) {
491+
return [FBCommandStatus invalidSelectorErrorWithMessage:error.localizedDescription
492+
traceback:nil];
493+
}
494+
[FBConfiguration setAutoClickAlertSelector:selector];
495+
[session enableAlertsMonitor];
496+
return [FBCommandStatus ok];
497+
}
498+
470499
+ (NSString *)buildTimestamp
471500
{
472501
return [NSString stringWithFormat:@"%@ %@",

WebDriverAgentLib/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>9.4.1</string>
18+
<string>9.5.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>9.4.1</string>
22+
<string>9.5.1</string>
2323
<key>NSPrincipalClass</key>
2424
<string/>
2525
</dict>

WebDriverAgentLib/Routing/FBCommandStatus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
1919
@property (nonatomic, nullable, readonly) NSString* message;
2020
@property (nonatomic, nullable, readonly) NSString* traceback;
2121
@property (nonatomic, readonly) HTTPStatusCode statusCode;
22-
22+
@property (nonatomic, readonly) BOOL hasError;
2323

2424
+ (instancetype)ok;
2525

WebDriverAgentLib/Routing/FBCommandStatus.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ - (instancetype)initWithError:(NSString *)error
109109
return self;
110110
}
111111

112+
- (BOOL)hasError
113+
{
114+
return self.statusCode != kHTTPStatusCodeOK;
115+
}
116+
112117
+ (instancetype)ok
113118
{
114119
return [[FBCommandStatus alloc] initWithValue:nil];

WebDriverAgentLib/Routing/FBResponsePayload.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
id<FBResponsePayload> FBResponseWithCachedElement(XCUIElement *element, FBElementCache *elementCache, BOOL compact)
5656
{
5757
[elementCache storeElement:maybeStable(element)];
58-
return FBResponseWithStatus([FBCommandStatus okWithValue:FBDictionaryResponseWithElement(element, compact)]);
58+
NSDictionary *response = FBDictionaryResponseWithElement(element, compact);
59+
element.lastSnapshot = nil;
60+
return FBResponseWithStatus([FBCommandStatus okWithValue:response]);
5961
}
6062

6163
id<FBResponsePayload> FBResponseWithCachedElements(NSArray<XCUIElement *> *elements, FBElementCache *elementCache, BOOL compact)
@@ -64,6 +66,7 @@
6466
for (XCUIElement *element in elements) {
6567
[elementCache storeElement:maybeStable(element)];
6668
[elementsResponse addObject:FBDictionaryResponseWithElement(element, compact)];
69+
element.lastSnapshot = nil;
6770
}
6871
return FBResponseWithStatus([FBCommandStatus okWithValue:elementsResponse]);
6972
}

WebDriverAgentLib/Routing/FBSession.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ extern NSString* const FB_SAFARI_BUNDLE_ID;
121121
*/
122122
- (NSUInteger)applicationStateWithBundleId:(NSString *)bundleIdentifier;
123123

124+
/**
125+
Allows to enable automated session alerts monitoring.
126+
Repeated calls are ignored if alerts monitoring has been already enabled.
127+
128+
@returns YES if the actual alerts monitoring state has been changed
129+
*/
130+
- (BOOL)enableAlertsMonitor;
131+
132+
/**
133+
Allows to disable automated alerts monitoring
134+
Repeated calls are ignored if alerts monitoring has been already disabled.
135+
136+
@returns YES if the actual alerts monitoring state has been changed
137+
*/
138+
- (BOOL)disableAlertsMonitor;
139+
124140
@end
125141

126142
NS_ASSUME_NONNULL_END

WebDriverAgentLib/Routing/FBSession.m

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#import "FBXCTestDaemonsProxy.h"
2626
#import "XCUIApplication+FBQuiescence.h"
2727
#import "XCUIElement.h"
28+
#import "XCUIElement+FBClassChain.h"
2829

2930
/*!
3031
The intial value for the default application property.
@@ -53,6 +54,22 @@ @implementation FBSession (FBAlertsMonitorDelegate)
5354

5455
- (void)didDetectAlert:(FBAlert *)alert
5556
{
57+
NSString *autoClickAlertSelector = FBConfiguration.autoClickAlertSelector;
58+
if ([autoClickAlertSelector length] > 0) {
59+
@try {
60+
NSArray<XCUIElement*> *matches = [alert.alertElement fb_descendantsMatchingClassChain:autoClickAlertSelector
61+
shouldReturnAfterFirstMatch:YES];
62+
if (matches.count > 0) {
63+
[[matches objectAtIndex:0] tap];
64+
}
65+
} @catch (NSException *e) {
66+
[FBLogger logFmt:@"Could not click at the alert element '%@'. Original error: %@",
67+
autoClickAlertSelector, e.description];
68+
}
69+
// This setting has priority over other settings if enabled
70+
return;
71+
}
72+
5673
if (nil == self.defaultAlertAction || 0 == self.defaultAlertAction.length) {
5774
return;
5875
}
@@ -125,23 +142,41 @@ + (instancetype)initWithApplication:(nullable XCUIApplication *)application
125142
defaultAlertAction:(NSString *)defaultAlertAction
126143
{
127144
FBSession *session = [self.class initWithApplication:application];
128-
session.alertsMonitor = [[FBAlertsMonitor alloc] init];
129-
session.alertsMonitor.delegate = (id<FBAlertsMonitorDelegate>)session;
130145
session.defaultAlertAction = [defaultAlertAction lowercaseString];
131-
[session.alertsMonitor enable];
146+
[session enableAlertsMonitor];
132147
return session;
133148
}
134149

150+
- (BOOL)enableAlertsMonitor
151+
{
152+
if (nil != self.alertsMonitor) {
153+
return NO;
154+
}
155+
156+
self.alertsMonitor = [[FBAlertsMonitor alloc] init];
157+
self.alertsMonitor.delegate = (id<FBAlertsMonitorDelegate>)self;
158+
[self.alertsMonitor enable];
159+
return YES;
160+
}
161+
162+
- (BOOL)disableAlertsMonitor
163+
{
164+
if (nil == self.alertsMonitor) {
165+
return NO;
166+
}
167+
168+
[self.alertsMonitor disable];
169+
self.alertsMonitor = nil;
170+
return YES;
171+
}
172+
135173
- (void)kill
136174
{
137175
if (nil == _activeSession) {
138176
return;
139177
}
140178

141-
if (nil != self.alertsMonitor) {
142-
[self.alertsMonitor disable];
143-
self.alertsMonitor = nil;
144-
}
179+
[self disableAlertsMonitor];
145180

146181
FBScreenRecordingPromise *activeScreenRecording = FBScreenRecordingContainer.sharedInstance.screenRecordingPromise;
147182
if (nil != activeScreenRecording) {

0 commit comments

Comments
 (0)