diff --git a/AppFramework/Action/GREYActions.m b/AppFramework/Action/GREYActions.m index 3316d6a85..1b1963eaa 100644 --- a/AppFramework/Action/GREYActions.m +++ b/AppFramework/Action/GREYActions.m @@ -510,6 +510,8 @@ + (void)grey_setText:(NSString *)text onWebElement:(id)element { grey_execute_sync_on_main_thread(^{ BOOL elementIsUIControl = [element isKindOfClass:[UIControl class]]; BOOL elementIsUITextField = [element isKindOfClass:[UITextField class]]; + BOOL elementIsUITextView = [element isKindOfClass:[UITextView class]]; + // Did begin editing notifications. if (elementIsUIControl) { [element sendActionsForControlEvents:UIControlEventEditingDidBegin]; @@ -521,6 +523,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]; @@ -529,24 +537,39 @@ + (void)grey_setText:(NSString *)text onWebElement:(id)element { if (elementIsUIControl) { [element sendActionsForControlEvents:UIControlEventEditingChanged]; } + if (elementIsUITextField) { NSNotification *notification = [NSNotification notificationWithName:UITextFieldTextDidChangeNotification 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) { [element sendActionsForControlEvents:UIControlEventEditingDidEndOnExit]; [element sendActionsForControlEvents:UIControlEventEditingDidEnd]; } + if (elementIsUITextField) { NSNotification *notification = [NSNotification notificationWithName:UITextFieldTextDidEndEditingNotification 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/Swift/FTRSwiftTests.swift b/Tests/FunctionalTests/Sources/Swift/FTRSwiftTests.swift index 3ce537777..d68f97135 100644 --- a/Tests/FunctionalTests/Sources/Swift/FTRSwiftTests.swift +++ b/Tests/FunctionalTests/Sources/Swift/FTRSwiftTests.swift @@ -127,6 +127,32 @@ class FTRSwiftTests: XCTestCase { .assert(grey_text("FooBar")) } + func testTypingOnUITextView() { + openTestView(named: "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() { + openTestView(named: "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() { openTestView(named: "Basic Views") EarlGrey.selectElement(with: grey_text("Tab 2")).perform(grey_tap()) diff --git a/Tests/TestRig/Sources/TypingViewController.h b/Tests/TestRig/Sources/TypingViewController.h index c3304dd71..395648fd0 100644 --- a/Tests/TestRig/Sources/TypingViewController.h +++ b/Tests/TestRig/Sources/TypingViewController.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 CustomTextView *customTextView; @property(nonatomic, retain) UIBarButtonItem *dismissKeyboardButton; diff --git a/Tests/TestRig/Sources/TypingViewController.m b/Tests/TestRig/Sources/TypingViewController.m index 5fe67180a..7f1a6baed 100644 --- a/Tests/TestRig/Sources/TypingViewController.m +++ b/Tests/TestRig/Sources/TypingViewController.m @@ -54,9 +54,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { _keyboardTypeStringArray = @[ - @"Default", @"ASCIICapable", @"NumbersAndPunctuation", @"URL", @"NumberPad", @"PhonePad", - @"NamePhonePad", @"EmailAddress", @"DecimalPad", @"Twitter", @"WebSearch" - ]; + @"Default", @"ASCIICapable", @"NumbersAndPunctuation", @"URL", @"NumberPad", @"PhonePad", + @"NamePhonePad", @"EmailAddress", @"DecimalPad", @"Twitter", @"WebSearch" + ]; NSAssert([_keyboardTypeStringArray count] == kKeyboardTypeCount, @"count must be kKeyboardTypeCount"); _keyboardTypeArray[0] = UIKeyboardTypeDefault; @@ -76,47 +76,50 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (void)viewDidLoad { [super viewDidLoad]; - + self.dismissKeyboardButton = - [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone - target:self - action:@selector(dismissKeyboard)]; - + [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone + target:self + action:@selector(dismissKeyboard)]; + self.textField.delegate = self; self.textField.isAccessibilityElement = YES; 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; self.nonTypingTextField.userInteractionEnabled = YES; self.nonTypingTextField.accessibilityIdentifier = @"NonTypingTextField"; - + self.textView.delegate = self; self.textView.isAccessibilityElement = YES; self.textView.userInteractionEnabled = YES; self.textView.accessibilityIdentifier = @"TypingTextView"; self.textView.autocorrectionType = UITextAutocorrectionTypeYes; - + self.inputAccessoryTextField.delegate = self; self.inputAccessoryTextField.isAccessibilityElement = YES; self.inputAccessoryTextField.userInteractionEnabled = YES; self.inputAccessoryTextField.accessibilityIdentifier = @"InputAccessoryTextField"; self.inputAccessoryTextField.autocorrectionType = UITextAutocorrectionTypeYes; [self AddInputAccessoryViewtoKeyboard]; - + self.inputButton.accessibilityIdentifier = @"Input Button"; [self.inputButton addTarget:self action:@selector(buttonPressedForTyping) forControlEvents:UIControlEventTouchUpInside]; - + self.keyboardPicker.accessibilityIdentifier = @"KeyboardPicker"; - + self.customTextView.isAccessibilityElement = YES; self.customTextView.userInteractionEnabled = YES; self.customTextView.accessibilityIdentifier = @"CustomTextView"; - + [self.view sendSubviewToBack:_customKeyboardTracker]; self.customKeyboardTracker.isAccessibilityElement = YES; self.customKeyboardTracker.accessibilityIdentifier = @"CustomKeyboardTracker"; @@ -151,6 +154,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/TestRig/Sources/TypingViewController.xib b/Tests/TestRig/Sources/TypingViewController.xib index 62f5f6069..47338a0bf 100644 --- a/Tests/TestRig/Sources/TypingViewController.xib +++ b/Tests/TestRig/Sources/TypingViewController.xib @@ -1,13 +1,17 @@ - + + + + - - + + + @@ -21,7 +25,7 @@ - + @@ -30,7 +34,7 @@ - + @@ -42,20 +46,20 @@ - + - + - + - + @@ -66,7 +70,7 @@ - + @@ -76,16 +80,16 @@ - + - + - + @@ -96,8 +100,15 @@ + - + @@ -121,12 +132,7 @@ - + - - - - -