Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add a method to enter text into the current first responder #174

Merged
merged 2 commits into from

3 participants

@jpsim

Text is entered into the view by simulating taps on the appropriate keyboard keys if the keyboard is already displayed. Useful to enter text in UIWebViews or components with no accessibility labels.

@jpsim

I've signed the CLA. Thanks

@efirestone efirestone merged commit 3d66999 into kif-framework:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 0 deletions.
  1. +9 −0 Classes/KIFTestStep.h
  2. +17 −0 Classes/KIFTestStep.m
View
9 Classes/KIFTestStep.h
@@ -328,6 +328,15 @@ typedef KIFTestStepResult (^KIFTestStepExecutionBlock)(KIFTestStep *step, NSErro
+ (id)stepToTapScreenAtPoint:(CGPoint)screenPoint;
/*!
+ @method stepToEnterTextIntoCurrentFirstResponder:
+ @abstract A step that enters text into a the current first responder.
+ @discussion Text is entered into the view by simulating taps on the appropriate keyboard keys if the keyboard is already displayed. Useful to enter text in UIWebViews or components with no accessibility labels.
+ @param text The text to enter.
+ @result A configured test step.
+ */
++ (id)stepToEnterTextIntoCurrentFirstResponder:(NSString *)text;
+
+/*!
@method stepToEnterText:intoViewWithAccessibilityLabel:
@abstract A step that enters text into a particular view in the view hierarchy.
@discussion The view or accessibility element with the given label is searched for in the view hierarchy. If the element isn't found or isn't currently tappable, then the step will attempt to wait until it is. Once the view is present and tappable, a tap event is simulated in the center of the view or element, then text is entered into the view by simulating taps on the appropriate keyboard keys.
View
17 Classes/KIFTestStep.m
@@ -350,6 +350,23 @@ + (id)stepToTapScreenAtPoint:(CGPoint)screenPoint;
}];
}
++ (id)stepToEnterTextIntoCurrentFirstResponder:(NSString *)text {
+ NSString *description = [NSString stringWithFormat:@"Type the text \"%@\" into the current first responder", text];
+ return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
+ // Wait for the keyboard
+ CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
+
+ for (NSUInteger characterIndex = 0; characterIndex < [text length]; characterIndex++) {
+ NSString *characterString = [text substringWithRange:NSMakeRange(characterIndex, 1)];
+
+ if (![self _enterCharacter:characterString]) {
+ KIFTestCondition(NO, error, @"Failed to find key for character \"%@\"", characterString);
+ }
+ }
+ return KIFTestStepResultSuccess;
+ }];
+}
+
+ (id)stepToEnterText:(NSString *)text intoViewWithAccessibilityLabel:(NSString *)label;
{
return [self stepToEnterText:text intoViewWithAccessibilityLabel:label traits:UIAccessibilityTraitNone expectedResult:nil];
Something went wrong with that request. Please try again.