Skip to content

Commit 1c7a174

Browse files
authored
Merge pull request #1317 from kif-framework/markj/enter_text_character_delay
Add character typing delay option for enter text
2 parents bee9233 + db117b5 commit 1c7a174

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

Sources/KIF/Classes/KIFUITestActor.h

+19
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ typedef NS_ENUM(NSUInteger, KIFPullToRefreshTiming) {
401401
- (void)enterTextIntoCurrentFirstResponder:(NSString *)text;
402402
- (void)enterTextIntoCurrentFirstResponder:(NSString *)text fallbackView:(UIView *)fallbackView;
403403

404+
/*!
405+
@abstract Enters text into a the current first responder.
406+
@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 WKWebViews or components with no accessibility labels.
407+
@param text The text to enter.
408+
@param characterTypingDelay the amount to delay between typing each character.
409+
*/
410+
- (void)enterTextIntoCurrentFirstResponder:(NSString *)text fallbackView:(UIView *)fallbackView characterTypingDelay:(CFTimeInterval)characterTypingDelay;
411+
404412
/*!
405413
@abstract Enters text into a particular view in the view hierarchy.
406414
@discussion If the element 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.
@@ -411,6 +419,17 @@ typedef NS_ENUM(NSUInteger, KIFPullToRefreshTiming) {
411419
*/
412420
- (void)enterText:(NSString *)text intoElement:(UIAccessibilityElement *)element inView:(UIView *)view expectedResult:(NSString *)expectedResult;
413421

422+
/*!
423+
@abstract Enters text into a particular view in the view hierarchy.
424+
@discussion If the element 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.
425+
@param text The text to enter.
426+
@param expectedResult What the text value should be after entry, including any formatting done by the field. If this is nil, the "text" parameter will be used.
427+
@param element the element to type into.
428+
@param view the view to type into.
429+
@param characterTypingDelay the amount to delay between typing each character.
430+
*/
431+
- (void)enterText:(NSString *)text intoElement:(UIAccessibilityElement *)element inView:(UIView *)view expectedResult:(NSString *)expectedResult characterTypingDelay:(CFTimeInterval)characterTypingDelay;
432+
414433
/*!
415434
@abstract Enters text into a particular view in the view hierarchy.
416435
@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.

Sources/KIF/Classes/KIFUITestActor.m

+14-2
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,11 @@ - (void)enterTextIntoCurrentFirstResponder:(NSString *)text
513513
[self enterTextIntoCurrentFirstResponder:text fallbackView:nil];
514514
}
515515

516-
- (void)enterTextIntoCurrentFirstResponder:(NSString *)text fallbackView:(UIView *)fallbackView
516+
- (void)enterTextIntoCurrentFirstResponder:(NSString *)text fallbackView:(UIView *)fallbackView {
517+
[self enterTextIntoCurrentFirstResponder:text fallbackView:fallbackView characterTypingDelay:0.0];
518+
}
519+
520+
- (void)enterTextIntoCurrentFirstResponder:(NSString *)text fallbackView:(UIView *)fallbackView characterTypingDelay:(CFTimeInterval)characterTypingDelay
517521
{
518522
[text enumerateSubstringsInRange:NSMakeRange(0, text.length)
519523
options:NSStringEnumerationByComposedCharacterSequences
@@ -551,6 +555,9 @@ - (void)enterTextIntoCurrentFirstResponder:(NSString *)text fallbackView:(UIView
551555

552556
[self failWithError:[NSError KIFErrorWithFormat:@"Failed to find key for character \"%@\"", characterString] stopTest:YES];
553557
}
558+
if (characterTypingDelay > 0) {
559+
CFRunLoopRunInMode(UIApplicationCurrentRunMode, characterTypingDelay, false);
560+
}
554561
}];
555562

556563
NSTimeInterval remainingWaitTime = 0.01 - [KIFTypist keystrokeDelay];
@@ -575,14 +582,19 @@ - (void)enterText:(NSString *)text intoViewWithAccessibilityLabel:(NSString *)la
575582
}
576583

577584
- (void)enterText:(NSString *)text intoElement:(UIAccessibilityElement *)element inView:(UIView *)view expectedResult:(NSString *)expectedResult;
585+
{
586+
[self enterText:text intoElement:element inView:view expectedResult:expectedResult characterTypingDelay:0.0];
587+
}
588+
589+
- (void)enterText:(NSString *)text intoElement:(UIAccessibilityElement *)element inView:(UIView *)view expectedResult:(NSString *)expectedResult characterTypingDelay:(CFTimeInterval)characterTypingDelay;
578590
{
579591
// In iOS7, tapping a field that is already first responder moves the cursor to the front of the field
580592
if (view.window.firstResponder != view) {
581593
[self tapAccessibilityElement:element inView:view];
582594
[self waitForTimeInterval:0.25 relativeToAnimationSpeed:YES];
583595
}
584596

585-
[self enterTextIntoCurrentFirstResponder:text fallbackView:view];
597+
[self enterTextIntoCurrentFirstResponder:text fallbackView:view characterTypingDelay:characterTypingDelay];
586598
if (self.validateEnteredText) {
587599
[self expectView:view toContainText:expectedResult ?: text];
588600
}

Sources/KIF/Classes/KIFUIViewTestActor.h

+26
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@ extern NSString *const inputFieldTestString;
355355
*/
356356
- (void)enterText:(NSString *)text expectedResult:(NSString *)expectedResult;
357357

358+
/*!
359+
@abstract Enters text into a particular view matching the tester's search predicate, then asserts that the view contains the expected text.
360+
@discussion If the element 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.
361+
@param text The text to enter.
362+
@param expectedResult What the text value should be after entry completes, including any formatting done by the field. If this is nil, the "text" parameter will be used.
363+
@param characterTypingDelay the amount to delay between typing each character.
364+
*/
365+
- (void)enterText:(NSString *)text expectedResult:(NSString *)expectedResult characterTypingDelay:(CFTimeInterval)characterTypingDelay;
366+
358367
/*!
359368
@abstract Enters text into a the current first responder.
360369
@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 WKWebViews or components with no accessibility labels.
@@ -388,6 +397,14 @@ extern NSString *const inputFieldTestString;
388397
@param text The text to enter after clearing the view.
389398
*/
390399
- (void)clearAndEnterText:(NSString *)text;
400+
401+
/*!
402+
@abstract Clears text from a particular view matching the tester's search predicate, then sets new text.
403+
@discussion If the element 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 cleared from the view by simulating taps on the backspace key, the new text is then entered by simulating taps on the appropriate keyboard keys.
404+
@param text The text to enter after clearing the view.
405+
@param characterTypingDelay the amount to delay between typing each character.
406+
*/
407+
- (void)clearAndEnterText:(NSString *)text characterTypingDelay:(CFTimeInterval)characterTypingDelay;
391408
/*!
392409
@abstract Clears text from a particular view matching the tester's search predicate, sets new text, then asserts that the view contains the expected text.
393410
@discussion If the element 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 cleared from the view by simulating taps on the backspace key, the new text is then entered by simulating taps on the appropriate keyboard keys, finally the text of the view is compared against the expected result.
@@ -397,6 +414,15 @@ extern NSString *const inputFieldTestString;
397414
*/
398415
- (void)clearAndEnterText:(NSString *)text expectedResult:(NSString *)expectedResult;
399416

417+
/*!
418+
@abstract Clears text from a particular view matching the tester's search predicate, sets new text, then asserts that the view contains the expected text.
419+
@discussion If the element 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 cleared from the view by simulating taps on the backspace key, the new text is then entered by simulating taps on the appropriate keyboard keys, finally the text of the view is compared against the expected result.
420+
@param text The text to enter after clearing the view.
421+
@param expectedResult What the text value should be after entry completes, including any formatting done by the field. If this is nil, the "text" parameter will be used.
422+
@param characterTypingDelay the amount to delay between typing each character.
423+
*/
424+
- (void)clearAndEnterText:(NSString *)text expectedResult:(NSString *)expectedResult characterTypingDelay:(CFTimeInterval)characterTypingDelay;
425+
400426
/*!
401427
@abstract Sets text into a particular view matching the tester's search predicate.
402428
@discussion The text is set on the view directly with 'setText:'. Does not result in first responder changes. Does not perform expected result validation.

Sources/KIF/Classes/KIFUIViewTestActor.m

+18-3
Original file line numberDiff line numberDiff line change
@@ -326,26 +326,41 @@ - (void)enterText:(NSString *)text;
326326
}
327327

328328
- (void)enterText:(NSString *)text expectedResult:(NSString *)expectedResult;
329+
{
330+
[self enterText:text expectedResult:expectedResult characterTypingDelay:0.0];
331+
}
332+
333+
- (void)enterText:(NSString *)text expectedResult:(NSString *)expectedResult characterTypingDelay:(CFTimeInterval)characterTypingDelay;
329334
{
330335
if (!self.validateEnteredText && expectedResult) {
331336
[self failWithMessage:@"Can't supply an expectedResult string if `validateEnteredText` is NO."];
332337
}
333338

334339
@autoreleasepool {
335340
KIFUIObject *found = [self _predicateSearchWithRequiresMatch:YES mustBeTappable:NO];
336-
[self.actor enterText:text intoElement:found.element inView:found.view expectedResult:expectedResult];
341+
[self.actor enterText:text intoElement:found.element inView:found.view expectedResult:expectedResult characterTypingDelay:characterTypingDelay];
337342
}
338343
}
339344

340345
- (void)clearAndEnterText:(NSString *)text;
341346
{
342-
[self clearAndEnterText:text expectedResult:nil];
347+
[self clearAndEnterText:text expectedResult:nil characterTypingDelay:0.0];
348+
}
349+
350+
- (void)clearAndEnterText:(NSString *)text characterTypingDelay:(CFTimeInterval)characterTypingDelay;
351+
{
352+
[self clearAndEnterText:text expectedResult:nil characterTypingDelay:characterTypingDelay];
343353
}
344354

345355
- (void)clearAndEnterText:(NSString *)text expectedResult:(NSString *)expectedResult;
356+
{
357+
[self clearAndEnterText:text expectedResult:expectedResult characterTypingDelay:0.0];
358+
}
359+
360+
- (void)clearAndEnterText:(NSString *)text expectedResult:(NSString *)expectedResult characterTypingDelay:(CFTimeInterval)characterTypingDelay;
346361
{
347362
[self clearText];
348-
[self enterText:text expectedResult:expectedResult];
363+
[self enterText:text expectedResult:expectedResult characterTypingDelay:characterTypingDelay];
349364
}
350365

351366
- (void)enterTextIntoCurrentFirstResponder:(NSString *)text;

0 commit comments

Comments
 (0)