Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EarlGrey 1.x | UITextView notifications are not triggered when using replaceText #771

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions EarlGrey/Action/GREYActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
Expand All @@ -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) {
Expand All @@ -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;
}];
Expand Down
26 changes: 26 additions & 0 deletions Tests/FunctionalTests/Sources/FTRSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
38 changes: 22 additions & 16 deletions Tests/FunctionalTests/TestRig/Sources/FTRTypingViewController.xib
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="NO">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I ask which Xcode you used? Just want to confirm.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xcode 10.0 on MacOS Mojave!

<device id="retina6_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<development version="7000" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="FTRTypingViewController">
<connections>
<outlet property="charCounter" destination="dpR-cT-oKE" id="ZfS-ER-41X"/>
<outlet property="customKeyboardTracker" destination="bnj-yZ-VR3" id="0ns-aw-ahE"/>
<outlet property="customTextView" destination="kf2-uc-vdE" id="XsY-7I-QdM"/>
<outlet property="inputAccessoryTextField" destination="Zla-Kl-dQS" id="XJs-DG-mGU"/>
Expand All @@ -21,7 +25,7 @@
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Input Accessory View TextField" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Zla-Kl-dQS" userLabel="Input Accessory Text Field">
Expand All @@ -42,7 +46,7 @@
<constraint firstAttribute="width" constant="133" id="Sle-WE-dbc"/>
</constraints>
<state key="normal" title="next returnKeyType">
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="changeReturnKeyType:" destination="-1" eventType="touchUpInside" id="jOw-jE-AVj"/>
Expand All @@ -55,7 +59,7 @@
</textField>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" keyboardDismissMode="interactive" translatesAutoresizingMaskIntoConstraints="NO" id="F8N-FE-LqS">
<rect key="frame" x="20" y="179" width="374" height="53"/>
<color key="backgroundColor" red="0.91907269021739135" green="0.91907269021739135" blue="0.91907269021739135" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.91907269021739135" green="0.91907269021739135" blue="0.91907269021739135" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="53" id="dkB-da-5H4"/>
</constraints>
Expand All @@ -78,15 +82,15 @@
</pickerView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kf2-uc-vdE" customClass="FTRCustomTextView">
<rect key="frame" x="74" y="240" width="266" height="51"/>
<color key="backgroundColor" red="0.72336632013320923" green="0.72336632013320923" blue="0.72336632013320923" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.72336632013320923" green="0.72336632013320923" blue="0.72336632013320923" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<accessibility key="accessibilityConfiguration" identifier="CustomTextView"/>
<constraints>
<constraint firstAttribute="width" constant="266" id="Jks-lU-kXW"/>
<constraint firstAttribute="height" constant="51" id="KQW-5b-HjZ"/>
</constraints>
</view>
<view contentMode="bottomLeft" translatesAutoresizingMaskIntoConstraints="NO" id="bnj-yZ-VR3" customClass="FTRCustomKeyboardTracker">
<rect key="frame" x="149" y="606" width="88" height="51"/>
<view contentMode="bottomLeft" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="bnj-yZ-VR3" customClass="FTRCustomKeyboardTracker">
<rect key="frame" x="149" y="835" width="88" height="51"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<accessibility key="accessibilityConfiguration" identifier="CustomKeyboardTracker"/>
<constraints>
Expand All @@ -96,8 +100,15 @@
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="10" id="vJa-7j-eqY"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="CharCounter" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="5" translatesAutoresizingMaskIntoConstraints="NO" id="dpR-cT-oKE" userLabel="Character Count">
<rect key="frame" x="20" y="238" width="51" height="53"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="ugr-WT-H7I" firstAttribute="top" secondItem="PBX-7b-uV2" secondAttribute="bottom" constant="-2" id="235-Sq-djF"/>
<constraint firstItem="D9d-aK-L7i" firstAttribute="top" secondItem="kf2-uc-vdE" secondAttribute="bottom" constant="22" id="89S-kl-2ip"/>
Expand All @@ -121,12 +132,7 @@
<constraint firstItem="HbD-2h-bQc" firstAttribute="trailing" secondItem="PBX-7b-uV2" secondAttribute="trailing" id="zCU-gO-eFg"/>
<constraint firstAttribute="bottom" secondItem="bnj-yZ-VR3" secondAttribute="bottom" constant="10" id="zv1-fF-81e"/>
</constraints>
<point key="canvasLocation" x="-17.5" y="29.5"/>
<point key="canvasLocation" x="-28" y="26.53673163418291"/>
</view>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>