diff --git a/EarlGrey/Action/GREYActions.m b/EarlGrey/Action/GREYActions.m index 8fd2618a3..1f726b40f 100644 --- a/EarlGrey/Action/GREYActions.m +++ b/EarlGrey/Action/GREYActions.m @@ -417,6 +417,7 @@ + (void)grey_setText:(NSString *)text onWebElement:(id)element { } BOOL elementIsUIControl = [element isKindOfClass:[UIControl class]]; BOOL elementIsUITextField = [element isKindOfClass:[UITextField class]]; + BOOL elementIsUITextView = [element isKindOfClass:[UITextView class]]; // Did begin editing notifications. if (elementIsUIControl) { @@ -429,6 +430,12 @@ + (void)grey_setText:(NSString *)text onWebElement:(id)element { object:element]; [NSNotificationCenter.defaultCenter postNotification:notification]; } + + if (elementIsUITextView) { + if ([((UITextView *)element).delegate respondsToSelector:@selector(textViewDidBeginEditing:)]) { + [((UITextView *)element).delegate textViewDidBeginEditing:((UITextView *)element)]; + } + } // Actually change the text. [element setText:text]; @@ -443,6 +450,12 @@ + (void)grey_setText:(NSString *)text onWebElement:(id)element { object:element]; [NSNotificationCenter.defaultCenter postNotification:notification]; } + + if (elementIsUITextView) { + if ([((UITextView *)element).delegate respondsToSelector:@selector(textViewDidChange:)]) { + [((UITextView *)element).delegate textViewDidChange:((UITextView *)element)]; + } + } // Did end editing notifications. if (elementIsUIControl) { @@ -455,6 +468,13 @@ + (void)grey_setText:(NSString *)text onWebElement:(id)element { object:element]; [NSNotificationCenter.defaultCenter postNotification:notification]; } + + if (elementIsUITextView) { + if ([((UITextView *)element).delegate respondsToSelector:@selector(textViewDidEndEditing:)]) { + [((UITextView *)element).delegate textViewDidEndEditing:((UITextView *)element)]; + } + } + } return YES; }]; diff --git a/Tests/FunctionalTests/Sources/FTRSwiftTests.swift b/Tests/FunctionalTests/Sources/FTRSwiftTests.swift index 379eb29cd..40f2d7170 100644 --- a/Tests/FunctionalTests/Sources/FTRSwiftTests.swift +++ b/Tests/FunctionalTests/Sources/FTRSwiftTests.swift @@ -137,6 +137,32 @@ class FTRSwiftTests: XCTestCase { .perform(grey_typeText("Fooo\u{8}B\u{8}Bar")) .assert(grey_text("FooBar")) } + + func testTypingOnUITextView() { + self.openTestView("Typing Views") + let typingField = grey_accessibilityID("TypingTextView") + let charCounter = grey_accessibilityID("charCounter") + + EarlGrey.selectElement(with: typingField) + .perform(grey_typeText("Simple")) + EarlGrey.selectElement(with: grey_text("Done")) + .perform(grey_tap()) + EarlGrey.selectElement(with: charCounter) + .assert(grey_text("6")) + } + + func testReplacingTextOnUITextView() { + self.openTestView("Typing Views") + let typingField = grey_accessibilityID("TypingTextView") + let charCounter = grey_accessibilityID("charCounter") + + EarlGrey.selectElement(with: typingField) + .perform(grey_replaceText("Simple")) + EarlGrey.selectElement(with: grey_text("Done")) + .perform(grey_tap()) + EarlGrey.selectElement(with: charCounter) + .assert(grey_text("6")) + } func testButtonPressWithGREYAllOf() { self.openTestView("Basic Views") diff --git a/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.h b/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.h index 99fe73550..5f1b2bd82 100644 --- a/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.h +++ b/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.h @@ -27,6 +27,7 @@ @property(nonatomic, retain) IBOutlet UITextField *inputAccessoryTextField; @property(nonatomic, retain) IBOutlet UIButton *inputButton; @property(nonatomic, retain) IBOutlet UITextField *textField; +@property(nonatomic, retain) IBOutlet UILabel *charCounter; @property(nonatomic, retain) IBOutlet UITextField *nonTypingTextField; @property(nonatomic, retain) IBOutlet FTRCustomTextView *customTextView; @property(nonatomic, retain) UIBarButtonItem *dismissKeyboardButton; diff --git a/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.m b/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.m index 62c0c2b8a..1fd27e48f 100644 --- a/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.m +++ b/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.m @@ -94,6 +94,9 @@ - (void)viewDidLoad { self.textField.userInteractionEnabled = YES; self.textField.accessibilityIdentifier = @"TypingTextField"; self.textField.autocorrectionType = UITextAutocorrectionTypeYes; + + self.charCounter.isAccessibilityElement = YES; + self.charCounter.accessibilityIdentifier = @"charCounter"; self.nonTypingTextField.delegate = self; self.nonTypingTextField.isAccessibilityElement = YES; @@ -158,6 +161,11 @@ - (void)textViewDidBeginEditing:(UITextView *)textView { self.navigationItem.rightBarButtonItem = self.dismissKeyboardButton; } +- (void)textViewDidEndEditing:(UITextView *)textView { + NSUInteger len = textView.text.length; + _charCounter.text = [NSString stringWithFormat: @"%lu", (unsigned long)len]; +} + - (void)dismissKeyboard { [self.textView resignFirstResponder]; self.navigationItem.rightBarButtonItem = nil; diff --git a/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.xib b/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.xib index 009a35faf..d96278fb0 100644 --- a/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.xib +++ b/Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.xib @@ -1,13 +1,17 @@ - + + + + - - + + + @@ -21,7 +25,7 @@ - + @@ -42,7 +46,7 @@ - + @@ -55,7 +59,7 @@ - + @@ -78,15 +82,15 @@ - + - - + + @@ -96,8 +100,15 @@ + - + @@ -121,12 +132,7 @@ - + - - - - -