Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a setting to control alerts behaviour in runtime #458

Merged
merged 1 commit into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ + (NSArray *)routes
}
}

if (requirements[@"defaultAlertAction"]) {
if (requirements[DEFAULT_ALERT_ACTION]) {
[FBSession initWithApplication:app
defaultAlertAction:(id)requirements[@"defaultAlertAction"]];
defaultAlertAction:(id)requirements[DEFAULT_ALERT_ACTION]];
} else {
[FBSession initWithApplication:app];
}
Expand Down Expand Up @@ -250,6 +250,7 @@ + (NSArray *)routes
INCLUDE_NON_MODAL_ELEMENTS: @([FBConfiguration includeNonModalElements]),
ACCEPT_ALERT_BUTTON_SELECTOR: FBConfiguration.acceptAlertButtonSelector,
DISMISS_ALERT_BUTTON_SELECTOR: FBConfiguration.dismissAlertButtonSelector,
DEFAULT_ALERT_ACTION: request.session.defaultAlertAction ?: @"",
#if !TARGET_OS_TV
SCREENSHOT_ORIENTATION: [FBConfiguration humanReadableScreenshotOrientation],
#endif
Expand Down Expand Up @@ -335,6 +336,9 @@ + (NSArray *)routes
if (nil != [settings objectForKey:ANIMATION_COOL_OFF_TIMEOUT]) {
[FBConfiguration setAnimationCoolOffTimeout:[[settings objectForKey:ANIMATION_COOL_OFF_TIMEOUT] doubleValue]];
}
if ([[settings objectForKey:DEFAULT_ALERT_ACTION] isKindOfClass:NSString.class]) {
request.session.defaultAlertAction = [settings[DEFAULT_ALERT_ACTION] lowercaseString];
}

#if !TARGET_OS_TV
if (nil != [settings objectForKey:SCREENSHOT_ORIENTATION]) {
Expand Down
4 changes: 4 additions & 0 deletions WebDriverAgentLib/Routing/FBSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ NS_ASSUME_NONNULL_BEGIN
/*! Element cache related to that session */
@property (nonatomic, strong, readonly) FBElementCache *elementCache;

/*! The identifier of the active application */
@property (nonatomic, copy) NSString *defaultActiveApplication;

/*! The action to apply to unexpected alerts. Either "accept"/"dismiss" or nil/empty string (by default) to do nothing */
@property (nonatomic, nullable) NSString *defaultAlertAction;

+ (nullable instancetype)activeSession;

/**
Expand Down
3 changes: 1 addition & 2 deletions WebDriverAgentLib/Routing/FBSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ @interface FBSession ()
@property (nonatomic) NSDictionary<NSString *, FBApplication *> *applications;
@property (nonatomic, strong, readwrite) FBApplication *testedApplication;
@property (nonatomic, nullable) FBAlertsMonitor *alertsMonitor;
@property (nonatomic, nullable) NSString *defaultAlertAction;
@end

@interface FBSession (FBAlertsMonitorDelegate)
Expand All @@ -49,7 +48,7 @@ @implementation FBSession (FBAlertsMonitorDelegate)

- (void)didDetectAlert:(FBAlert *)alert
{
if (nil == self.defaultAlertAction) {
if (nil == self.defaultAlertAction || 0 == self.defaultAlertAction.length) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion WebDriverAgentLib/Utilities/FBSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ extern NSString* const ELEMENT_RESPONSE_ATTRIBUTES;
extern NSString* const MJPEG_SERVER_SCREENSHOT_QUALITY;
extern NSString* const MJPEG_SERVER_FRAMERATE;
extern NSString* const MJPEG_SCALING_FACTOR;
extern NSString* const MJPEG_COMPRESSION_FACTOR;
extern NSString* const SCREENSHOT_QUALITY;
extern NSString* const KEYBOARD_AUTOCORRECTION;
extern NSString* const KEYBOARD_PREDICTION;
Expand All @@ -32,6 +31,7 @@ extern NSString* const REDUCE_MOTION;
extern NSString* const DEFAULT_ACTIVE_APPLICATION;
extern NSString* const ACTIVE_APP_DETECTION_POINT;
extern NSString* const INCLUDE_NON_MODAL_ELEMENTS;
extern NSString* const DEFAULT_ALERT_ACTION;
extern NSString* const ACCEPT_ALERT_BUTTON_SELECTOR;
extern NSString* const DISMISS_ALERT_BUTTON_SELECTOR;
extern NSString* const SCREENSHOT_ORIENTATION;
Expand Down
2 changes: 1 addition & 1 deletion WebDriverAgentLib/Utilities/FBSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
NSString* const MJPEG_SERVER_SCREENSHOT_QUALITY = @"mjpegServerScreenshotQuality";
NSString* const MJPEG_SERVER_FRAMERATE = @"mjpegServerFramerate";
NSString* const MJPEG_SCALING_FACTOR = @"mjpegScalingFactor";
NSString* const MJPEG_COMPRESSION_FACTOR = @"mjpegCompressionFactor";
NSString* const SCREENSHOT_QUALITY = @"screenshotQuality";
NSString* const KEYBOARD_AUTOCORRECTION = @"keyboardAutocorrection";
NSString* const KEYBOARD_PREDICTION = @"keyboardPrediction";
Expand All @@ -27,6 +26,7 @@
NSString* const DEFAULT_ACTIVE_APPLICATION = @"defaultActiveApplication";
NSString* const ACTIVE_APP_DETECTION_POINT = @"activeAppDetectionPoint";
NSString* const INCLUDE_NON_MODAL_ELEMENTS = @"includeNonModalElements";
NSString* const DEFAULT_ALERT_ACTION = @"defaultAlertAction";
NSString* const ACCEPT_ALERT_BUTTON_SELECTOR = @"acceptAlertButtonSelector";
NSString* const DISMISS_ALERT_BUTTON_SELECTOR = @"dismissAlertButtonSelector";
NSString* const SCREENSHOT_ORIENTATION = @"screenshotOrientation";
Expand Down