Skip to content

Commit

Permalink
Don't change the typing delay based on animation speed, improve relia…
Browse files Browse the repository at this point in the history
…bility when typing delay < 0.01s
  • Loading branch information
justinseanmartin committed Jun 23, 2016
1 parent e0986e3 commit 819aec6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
3 changes: 3 additions & 0 deletions Classes/KIFTypist.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
+ (void)registerForNotifications;
+ (BOOL)keyboardHidden;
+ (BOOL)enterCharacter:(NSString *)characterString;

+ (NSTimeInterval)keystrokeDelay;
+ (void)setKeystrokeDelay:(NSTimeInterval)delay;

+ (BOOL)hasHardwareKeyboard;
+ (BOOL)hasKeyInputResponder;

Expand Down
7 changes: 6 additions & 1 deletion Classes/KIFTypist.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ + (BOOL)enterCharacter:(NSString *)characterString;
[[UIKeyboardImpl sharedInstance] addInputString:characterString];
}

KIFRunLoopRunInModeRelativeToAnimationSpeed(kCFRunLoopDefaultMode, keystrokeDelay, false);
CFRunLoopRunInMode(kCFRunLoopDefaultMode, keystrokeDelay, false);
return YES;
}

+ (NSTimeInterval)keystrokeDelay;
{
return keystrokeDelay;
}

+ (void)setKeystrokeDelay:(NSTimeInterval)delay
{
keystrokeDelay = delay;
Expand Down
52 changes: 28 additions & 24 deletions Classes/KIFUITestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -387,30 +387,34 @@ - (void)enterTextIntoCurrentFirstResponder:(NSString *)text

- (void)enterTextIntoCurrentFirstResponder:(NSString *)text fallbackView:(UIView *)fallbackView
{
[text enumerateSubstringsInRange:NSMakeRange(0, text.length)
options:NSStringEnumerationByComposedCharacterSequences
usingBlock: ^(NSString *characterString,NSRange substringRange,NSRange enclosingRange,BOOL * stop)

{
if (![KIFTypist enterCharacter:characterString]) {
// Attempt to cheat if we couldn't find the character
UIView * fallback = fallbackView;
if (!fallback) {
UIResponder *firstResponder = [[[UIApplication sharedApplication] keyWindow] firstResponder];

if ([firstResponder isKindOfClass:[UIView class]]) {
fallback = (UIView *)firstResponder;
}
}

if ([fallback isKindOfClass:[UITextField class]] || [fallback isKindOfClass:[UITextView class]] || [fallback isKindOfClass:[UISearchBar class]]) {
NSLog(@"KIF: Unable to find keyboard key for %@. Inserting manually.", characterString);
[(UITextField *)fallback setText:[[(UITextField *)fallback text] stringByAppendingString:characterString]];
} else {
[self failWithError:[NSError KIFErrorWithFormat:@"Failed to find key for character \"%@\"", characterString] stopTest:YES];
}
}
}];
[text enumerateSubstringsInRange:NSMakeRange(0, text.length)
options:NSStringEnumerationByComposedCharacterSequences
usingBlock: ^(NSString *characterString,NSRange substringRange,NSRange enclosingRange,BOOL * stop)
{
if (![KIFTypist enterCharacter:characterString]) {
// Attempt to cheat if we couldn't find the character
UIView * fallback = fallbackView;
if (!fallback) {
UIResponder *firstResponder = [[[UIApplication sharedApplication] keyWindow] firstResponder];

if ([firstResponder isKindOfClass:[UIView class]]) {
fallback = (UIView *)firstResponder;
}
}

if ([fallback isKindOfClass:[UITextField class]] || [fallback isKindOfClass:[UITextView class]] || [fallback isKindOfClass:[UISearchBar class]]) {
NSLog(@"KIF: Unable to find keyboard key for %@. Inserting manually.", characterString);
[(UITextField *)fallback setText:[[(UITextField *)fallback text] stringByAppendingString:characterString]];
} else {
[self failWithError:[NSError KIFErrorWithFormat:@"Failed to find key for character \"%@\"", characterString] stopTest:YES];
}
}
}];

NSTimeInterval remainingWaitTime = 0.01 - [KIFTypist keystrokeDelay];
if (remainingWaitTime > 0) {
CFRunLoopRunInMode(UIApplicationCurrentRunMode, remainingWaitTime, false);
}
}

- (void)enterText:(NSString *)text intoViewWithAccessibilityLabel:(NSString *)label
Expand Down

0 comments on commit 819aec6

Please sign in to comment.