Skip to content

Commit

Permalink
Make snapshot timeout configurable (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jun 27, 2019
1 parent 86098af commit f2fd28b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
12 changes: 6 additions & 6 deletions WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import <objc/runtime.h>

#import "FBAlert.h"
#import "FBConfiguration.h"
#import "FBLogger.h"
#import "FBImageUtils.h"
#import "FBMacros.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<XCTestManager_ManagerInterface> 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
Expand All @@ -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];
}
Expand Down
7 changes: 6 additions & 1 deletion WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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])
}
);
}
Expand Down Expand Up @@ -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];
}
Expand Down
8 changes: 8 additions & 0 deletions WebDriverAgentLib/Utilities/FBConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions WebDriverAgentLib/Utilities/FBConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
static NSUInteger FBMjpegServerFramerate = 10;
static NSUInteger FBScreenshotQuality = 1;
static NSUInteger FBMjpegScalingFactor = 100;
static NSTimeInterval FBSnapshotTimeout = 15.;

@implementation FBConfiguration

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f2fd28b

Please sign in to comment.