Skip to content

Commit

Permalink
Add useFirstMatch setting (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jul 11, 2019
1 parent 5e22df7 commit 74fac68
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
7 changes: 6 additions & 1 deletion WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
static NSString* const KEYBOARD_AUTOCORRECTION = @"keyboardAutocorrection";
static NSString* const KEYBOARD_PREDICTION = @"keyboardPrediction";
static NSString* const SNAPSHOT_TIMEOUT = @"snapshotTimeout";
static NSString* const USE_FIRST_MATCH = @"useFirstMatch";

@implementation FBSessionCommands

Expand Down Expand Up @@ -220,7 +221,8 @@ + (NSArray *)routes
SCREENSHOT_QUALITY: @([FBConfiguration screenshotQuality]),
KEYBOARD_AUTOCORRECTION: @([FBConfiguration keyboardAutocorrection]),
KEYBOARD_PREDICTION: @([FBConfiguration keyboardPrediction]),
SNAPSHOT_TIMEOUT: @([FBConfiguration snapshotTimeout])
SNAPSHOT_TIMEOUT: @([FBConfiguration snapshotTimeout]),
USE_FIRST_MATCH: @([FBConfiguration useFirstMatch]),
}
);
}
Expand Down Expand Up @@ -258,6 +260,9 @@ + (NSArray *)routes
if ([settings objectForKey:SNAPSHOT_TIMEOUT]) {
[FBConfiguration setSnapshotTimeout:[[settings objectForKey:SNAPSHOT_TIMEOUT] doubleValue]];
}
if ([settings objectForKey:USE_FIRST_MATCH]) {
[FBConfiguration setUseFirstMatch:[[settings objectForKey:USE_FIRST_MATCH] boolValue]];
}

return [self handleGetSettings:request];
}
Expand Down
10 changes: 10 additions & 0 deletions WebDriverAgentLib/Utilities/FBConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)setSnapshotTimeout:(NSTimeInterval)timeout;
+ (NSTimeInterval)snapshotTimeout;

/**
* Whether to use fast search result matching while searching for elements.
* By default this is disabled due to https://github.com/appium/appium/issues/10101
* but it still makes sense to enable it for views containing large counts of elements
*
* @param enabled Either YES or NO
*/
+ (void)setUseFirstMatch:(BOOL)enabled;
+ (BOOL)useFirstMatch;

@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 @@ -38,6 +38,7 @@
static NSUInteger FBScreenshotQuality = 1;
static NSUInteger FBMjpegScalingFactor = 100;
static NSTimeInterval FBSnapshotTimeout = 15.;
static BOOL FBShouldUseFirstMatch = NO;

@implementation FBConfiguration

Expand Down Expand Up @@ -263,6 +264,16 @@ + (NSTimeInterval)snapshotTimeout
return FBSnapshotTimeout;
}

+ (void)setUseFirstMatch:(BOOL)enabled
{
FBShouldUseFirstMatch = enabled;
}

+ (BOOL)useFirstMatch
{
return FBShouldUseFirstMatch;
}

#pragma mark Private

+ (BOOL)keyboardsPreference:(nonnull NSString *)key
Expand Down
13 changes: 2 additions & 11 deletions WebDriverAgentLib/Utilities/FBXCodeCompatibility.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import "FBXCodeCompatibility.h"

#import "FBConfiguration.h"
#import "FBErrorBuilder.h"
#import "FBLogger.h"
#import "XCUIElementQuery.h"
Expand Down Expand Up @@ -82,21 +83,11 @@ - (NSUInteger)fb_state
@end


static BOOL FBShouldUseFirstMatchSelector = NO;
static dispatch_once_t onceFirstMatchToken;

@implementation XCUIElementQuery (FBCompatibility)

- (XCUIElement *)fb_firstMatch
{
dispatch_once(&onceFirstMatchToken, ^{
// Unfortunately, firstMatch property does not work properly if
// the lookup is not executed in application context:
// https://github.com/appium/appium/issues/10101
// FBShouldUseFirstMatchSelector = [self respondsToSelector:@selector(firstMatch)];
FBShouldUseFirstMatchSelector = NO;
});
if (FBShouldUseFirstMatchSelector) {
if (FBConfiguration.useFirstMatch) {
XCUIElement* result = self.firstMatch;
return result.exists ? result : nil;
}
Expand Down

0 comments on commit 74fac68

Please sign in to comment.