diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index e3398ca1a..72e5b40fe 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -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]; } @@ -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 @@ -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]) { diff --git a/WebDriverAgentLib/Routing/FBSession.h b/WebDriverAgentLib/Routing/FBSession.h index 0eb5ebe48..b2505003c 100644 --- a/WebDriverAgentLib/Routing/FBSession.h +++ b/WebDriverAgentLib/Routing/FBSession.h @@ -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; /** diff --git a/WebDriverAgentLib/Routing/FBSession.m b/WebDriverAgentLib/Routing/FBSession.m index 7849dc96c..20f1a4c82 100644 --- a/WebDriverAgentLib/Routing/FBSession.m +++ b/WebDriverAgentLib/Routing/FBSession.m @@ -36,7 +36,6 @@ @interface FBSession () @property (nonatomic) NSDictionary *applications; @property (nonatomic, strong, readwrite) FBApplication *testedApplication; @property (nonatomic, nullable) FBAlertsMonitor *alertsMonitor; -@property (nonatomic, nullable) NSString *defaultAlertAction; @end @interface FBSession (FBAlertsMonitorDelegate) @@ -49,7 +48,7 @@ @implementation FBSession (FBAlertsMonitorDelegate) - (void)didDetectAlert:(FBAlert *)alert { - if (nil == self.defaultAlertAction) { + if (nil == self.defaultAlertAction || 0 == self.defaultAlertAction.length) { return; } diff --git a/WebDriverAgentLib/Utilities/FBSettings.h b/WebDriverAgentLib/Utilities/FBSettings.h index bd89e0b8e..8bbf8f18c 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.h +++ b/WebDriverAgentLib/Utilities/FBSettings.h @@ -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; @@ -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; diff --git a/WebDriverAgentLib/Utilities/FBSettings.m b/WebDriverAgentLib/Utilities/FBSettings.m index 3dab8cdaf..c79381428 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.m +++ b/WebDriverAgentLib/Utilities/FBSettings.m @@ -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"; @@ -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";