diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m b/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m index ecbc23555..5b5e8c13a 100644 --- a/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m +++ b/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m @@ -12,6 +12,7 @@ #import #import "FBAlert.h" +#import "FBConfiguration.h" #import "FBLogger.h" #import "FBImageUtils.h" #import "FBMacros.h" @@ -74,8 +75,6 @@ - (XCElementSnapshot *)fb_lastSnapshot return [self.query fb_elementSnapshotForDebugDescription]; } -static const NSTimeInterval AX_TIMEOUT = 15.; - - (nullable XCElementSnapshot *)fb_snapshotWithAttributes { if (![FBConfiguration shouldLoadSnapshotWithAttributes]) { return nil; @@ -117,12 +116,13 @@ - (nullable XCElementSnapshot *)fb_snapshotWithAttributes { if (nil == axAttributes) { return nil; } - + + NSTimeInterval axTimeout = [FBConfiguration snapshotTimeout]; __block XCElementSnapshot *snapshotWithAttributes = nil; __block NSError *innerError = nil; id proxy = [FBXCTestDaemonsProxy testRunnerProxy]; dispatch_semaphore_t sem = dispatch_semaphore_create(0); - [FBXCTestDaemonsProxy tryToSetAxTimeout:AX_TIMEOUT + [FBXCTestDaemonsProxy tryToSetAxTimeout:axTimeout forProxy:proxy withHandler:^(int res) { [proxy _XCT_snapshotForElement:self.lastSnapshot.accessibilityElement @@ -137,9 +137,9 @@ - (nullable XCElementSnapshot *)fb_snapshotWithAttributes { dispatch_semaphore_signal(sem); }]; }]; - dispatch_semaphore_wait(sem, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(AX_TIMEOUT * NSEC_PER_SEC))); + dispatch_semaphore_wait(sem, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(axTimeout * NSEC_PER_SEC))); if (nil == snapshotWithAttributes) { - [FBLogger logFmt:@"Getting the snapshot timed out after %@ seconds", @(AX_TIMEOUT)]; + [FBLogger logFmt:@"Cannot take the snapshot of %@ after %@ seconds", self.description, @(axTimeout)]; if (nil != innerError) { [FBLogger logFmt:@"Internal error: %@", innerError.description]; } diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index 9865748ac..d99652399 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -29,6 +29,7 @@ static NSString* const SCREENSHOT_QUALITY = @"screenshotQuality"; static NSString* const KEYBOARD_AUTOCORRECTION = @"keyboardAutocorrection"; static NSString* const KEYBOARD_PREDICTION = @"keyboardPrediction"; +static NSString* const SNAPSHOT_TIMEOUT = @"snapshotTimeout"; @implementation FBSessionCommands @@ -218,7 +219,8 @@ + (NSArray *)routes MJPEG_SCALING_FACTOR: @([FBConfiguration mjpegScalingFactor]), SCREENSHOT_QUALITY: @([FBConfiguration screenshotQuality]), KEYBOARD_AUTOCORRECTION: @([FBConfiguration keyboardAutocorrection]), - KEYBOARD_PREDICTION: @([FBConfiguration keyboardPrediction]) + KEYBOARD_PREDICTION: @([FBConfiguration keyboardPrediction]), + SNAPSHOT_TIMEOUT: @([FBConfiguration snapshotTimeout]) } ); } @@ -253,6 +255,9 @@ + (NSArray *)routes if ([settings objectForKey:KEYBOARD_PREDICTION]) { [FBConfiguration setKeyboardPrediction:[[settings objectForKey:KEYBOARD_PREDICTION] boolValue]]; } + if ([settings objectForKey:SNAPSHOT_TIMEOUT]) { + [FBConfiguration setSnapshotTimeout:[[settings objectForKey:SNAPSHOT_TIMEOUT] doubleValue]]; + } return [self handleGetSettings:request]; } diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.h b/WebDriverAgentLib/Utilities/FBConfiguration.h index c7c1886be..1a7d46404 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.h +++ b/WebDriverAgentLib/Utilities/FBConfiguration.h @@ -129,6 +129,14 @@ NS_ASSUME_NONNULL_BEGIN + (void)setKeyboardPrediction:(BOOL)isEnabled; + (BOOL)keyboardPrediction; +/** + * The maximum time to wait until accessibility snapshot is taken + * + * @param timeout The number of float seconds to wait (15 seconds by default) + */ ++ (void)setSnapshotTimeout:(NSTimeInterval)timeout; ++ (NSTimeInterval)snapshotTimeout; + @end NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 59df78bef..61131b3ba 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -37,6 +37,7 @@ static NSUInteger FBMjpegServerFramerate = 10; static NSUInteger FBScreenshotQuality = 1; static NSUInteger FBMjpegScalingFactor = 100; +static NSTimeInterval FBSnapshotTimeout = 15.; @implementation FBConfiguration @@ -252,6 +253,16 @@ + (void)setKeyboardPrediction:(BOOL)isEnabled [self configureKeyboardsPreference:@(isEnabled) forPreferenceKey:FBKeyboardPredictionKey]; } ++ (void)setSnapshotTimeout:(NSTimeInterval)timeout +{ + FBSnapshotTimeout = timeout; +} + ++ (NSTimeInterval)snapshotTimeout +{ + return FBSnapshotTimeout; +} + #pragma mark Private + (BOOL)keyboardsPreference:(nonnull NSString *)key