Skip to content
Browse files

Added method to enter text into a view based on a query.

Added a test based on a phone umber keyboard.
  • Loading branch information...
1 parent 74094e5 commit aca5e250fe5b4fec84bad8e5a2cf5e0e18772dca @drekka committed Mar 24, 2012
View
8 classes/SIUIApplication.h
@@ -202,4 +202,12 @@
*/
-(void) enterText:(NSString *) text intoView:(UIView *) view;
+/**
+ Ensures that the specified view based on a query has focus and then enters the text into it.
+
+ @param text the text we want to enter.
+ @param query the query that should find the control.
+ */
+-(void) enterText:(NSString *) text intoViewWithQuery:(NSString *) query;
+
@end
View
5 classes/SIUIApplication.m
@@ -360,4 +360,9 @@ -(void) enterText:(NSString *) text intoView:(UIView *) view {
}
+-(void) enterText:(NSString *) text intoViewWithQuery:(NSString *) query {
+ UIView<DNNode> *theView = [self findViewWithQuery:query];
+ [self enterText:text intoView:theView];
+}
+
@end
View
6 classes/SIUIViewHandler.m
@@ -15,9 +15,11 @@
// We need access to the private API of the keyboard layout so we can send keys.
@interface UIKeyboardLayout : UIView
- (id)simulateTouchForCharacter:(id)arg1 errorVector:(CGPoint)arg2 shouldTypeVariants:(BOOL)arg3 baseKeyForVariants:(BOOL)arg4;
+- (BOOL)performReturnAction;
@end
@interface UIKeyboardImpl : UIView
- (void)_setAutocorrects:(BOOL)arg1;
+- (id)returnKeyDisplayName;
@end
@implementation SIUIViewHandler
@@ -89,7 +91,7 @@ -(void) enterText:(NSString *) text keyRate:(NSTimeInterval) keyRate autoCorrect
UIKeyboardImpl *kbImpl = (UIKeyboardImpl *) [keyboardAuto.subviews objectAtIndex:0];
UIKeyboardLayout *kbLayout = (UIKeyboardLayout *) [kbImpl.subviews objectAtIndex:0];
- // Turn off auto correct.
+ // Turn on or off auto correct.
[kbImpl _setAutocorrects:autoCorrect];
// Loop and send each character.
@@ -108,7 +110,7 @@ -(void) enterText:(NSString *) text keyRate:(NSTimeInterval) keyRate autoCorrect
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:keyRate]];
DC_LOG(@"Sent character %@", sentChar);
}
- DC_LOG(@"Text entry finished");
+ DC_LOG(@"Text entry finished, return key %@", [kbImpl returnKeyDisplayName]);
}];
}
View
36 tests/SIUIApplicationTests.m
@@ -278,5 +278,41 @@ -(void) testEnterTextIntoViewFailIfNotCorrectInputProtocol {
}
}
+-(void) testEnterTextIntoViewWithQuery {
+ [self executeBlockOnMainThread:^{
+ self.testViewController.textField.text = @"";
+ }];
+
+ NSString *text = @"Hello world";
+ [[SIUIApplication application] enterText:text intoViewWithQuery:@"//UITextField[0]"];
+
+ __block NSString *enteredText = nil;
+ [self executeBlockOnMainThread:^{
+ enteredText = [self.testViewController.textField.text retain];
+ }];
+ [enteredText autorelease];
+ GHAssertEqualStrings(enteredText, text, @"Text not correct");
+}
+
+-(void) testEnterPhoneNumber {
+ [self executeBlockOnMainThread:^{
+ self.testViewController.phoneNumberField.text = @"";
+ }];
+
+ NSString *text = @"0404 053 463\n";
+ [[SIUIApplication application] enterText:text intoView:self.testViewController.phoneNumberField];
+
+ __block NSString *enteredText = nil;
+ [self executeBlockOnMainThread:^{
+ enteredText = [self.testViewController.phoneNumberField.text retain];
+ }];
+ [enteredText autorelease];
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ GHAssertEqualStrings(enteredText, @"0404 053 463", @"Text not correct");
+ } else {
+ GHAssertEqualStrings(enteredText, @"0404053463", @"Text not correct");
+ }
+}
+
@end
View
4 tests/SIUIViewHandlerTests.m
@@ -54,7 +54,7 @@ -(void) testAttributeQueryMatchesNestedPropertyValue {
-(void) testSubnodes {
handler.view = self.testViewController.view;
NSArray *subNodes = handler.dnSubNodes;
- GHAssertEquals([subNodes count], (NSUInteger) 10, @"Should be one sub view");
+ GHAssertEquals([subNodes count], (NSUInteger) 12, @"Should be one sub view");
GHAssertEquals([subNodes objectAtIndex:0], self.testViewController.button1, @"Returned node was not button 1.");
GHAssertEquals([subNodes objectAtIndex:1], self.testViewController.button2, @"Returned node was not button 2.");
GHAssertEquals([subNodes objectAtIndex:2], self.testViewController.tabBar, @"Returned node was not the tab bar.");
@@ -66,6 +66,8 @@ -(void) testSubnodes {
// There are more but at this point we can be sure it's pretty correct.
}
+#pragma mark - KVC
+
-(void) testKvcAttributesReturnsNilWhenNoTag {
handler.view = [[[UIView alloc] init] autorelease];
GHAssertNil([handler kvcAttributes], @"Expected a nil");
View
184 tests/TestView.xib
@@ -46,6 +46,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 20}, {72, 37}}</string>
<reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="595977559"/>
<string key="NSReuseIdentifierKey">_NS:225</string>
<bool key="IBUIOpaque">NO</bool>
@@ -82,6 +83,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{256, 20}, {72, 37}}</string>
<reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="139189464"/>
<string key="NSReuseIdentifierKey">_NS:225</string>
<bool key="IBUIOpaque">NO</bool>
@@ -106,6 +108,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{0, 540}, {348, 49}}</string>
<reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:541</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
@@ -132,6 +135,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{18, 320}, {312, 23}}</string>
<reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="189776538"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
@@ -146,6 +150,7 @@
<int key="NSvFlags">274</int>
<string key="NSFrame">{{20, 350}, {308, 169}}</string>
<reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="924428378"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="185341603"/>
@@ -165,6 +170,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{120, 27}, {108, 21}}</string>
<reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="563717882"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
@@ -196,6 +202,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 71}, {308, 34}}</string>
<reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="329916556"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
@@ -220,7 +227,8 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 130}, {123, 37}}</string>
<reference key="NSSuperview" ref="191373211"/>
- <reference key="NSNextKeyView" ref="812649077"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="245112534"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
@@ -240,8 +248,10 @@
<object class="IBUITextField" id="183701928">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
- <string key="NSFrame">{{20, 212}, {308, 31}}</string>
+ <string key="NSFrame">{{81, 212}, {247, 31}}</string>
<reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="22863608"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
@@ -253,7 +263,7 @@
<object class="NSColor" key="IBUITextColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MAA</bytes>
- <object class="NSColorSpace" key="NSCustomColorSpace">
+ <object class="NSColorSpace" key="NSCustomColorSpace" id="899015219">
<int key="NSID">2</int>
</object>
</object>
@@ -262,11 +272,11 @@
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
- <object class="IBUIFontDescription" key="IBUIFontDescription">
+ <object class="IBUIFontDescription" key="IBUIFontDescription" id="939510176">
<int key="type">1</int>
<double key="pointSize">14</double>
</object>
- <object class="NSFont" key="IBUIFont">
+ <object class="NSFont" key="IBUIFont" id="346351578">
<string key="NSName">Helvetica</string>
<double key="NSSize">14</double>
<int key="NSfFlags">16</int>
@@ -275,15 +285,67 @@
<object class="IBUILabel" id="245112534">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
- <string key="NSFrame">{{20, 183}, {75, 21}}</string>
+ <string key="NSFrame">{{20, 217}, {51, 21}}</string>
+ <reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="183701928"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <int key="IBUIContentMode">7</int>
+ <bool key="IBUIUserInteractionEnabled">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <string key="IBUIText">Text:</string>
+ <reference key="IBUITextColor" ref="279298181"/>
+ <nil key="IBUIHighlightedColor"/>
+ <int key="IBUIBaselineAdjustment">0</int>
+ <float key="IBUIMinimumFontSize">10</float>
+ <reference key="IBUIFontDescription" ref="147869310"/>
+ <reference key="IBUIFont" ref="27844755"/>
+ </object>
+ <object class="IBUITextField" id="934642070">
+ <reference key="NSNextResponder" ref="191373211"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{81, 251}, {247, 31}}</string>
+ <reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="812649077"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <int key="IBUITag">110</int>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <int key="IBUIContentVerticalAlignment">0</int>
+ <string key="IBUIText"/>
+ <int key="IBUIBorderStyle">3</int>
+ <object class="NSColor" key="IBUITextColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MAA</bytes>
+ <reference key="NSCustomColorSpace" ref="899015219"/>
+ </object>
+ <bool key="IBUIAdjustsFontSizeToFit">YES</bool>
+ <float key="IBUIMinimumFontSize">17</float>
+ <object class="IBUITextInputTraits" key="IBUITextInputTraits">
+ <int key="IBUIKeyboardType">5</int>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <reference key="IBUIFontDescription" ref="939510176"/>
+ <reference key="IBUIFont" ref="346351578"/>
+ </object>
+ <object class="IBUILabel" id="22863608">
+ <reference key="NSNextResponder" ref="191373211"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{20, 256}, {63, 21}}</string>
<reference key="NSSuperview" ref="191373211"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="934642070"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUIContentMode">7</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
- <string key="IBUIText">Text field:</string>
+ <string key="IBUIText">Phone:</string>
<reference key="IBUITextColor" ref="279298181"/>
<nil key="IBUIHighlightedColor"/>
<int key="IBUIBaselineAdjustment">0</int>
@@ -294,6 +356,7 @@
</array>
<string key="NSFrameSize">{348, 589}</string>
<reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="650915059"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
@@ -386,6 +449,14 @@
<int key="connectionID">50</int>
</object>
<object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">phoneNumberField</string>
+ <reference key="source" ref="372490531"/>
+ <reference key="destination" ref="934642070"/>
+ </object>
+ <int key="connectionID">53</int>
+ </object>
+ <object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">buttonTapped:</string>
<reference key="source" ref="650915059"/>
@@ -457,8 +528,10 @@
<reference ref="189776538"/>
<reference ref="812649077"/>
<reference ref="183701928"/>
- <reference ref="245112534"/>
<reference ref="329916556"/>
+ <reference ref="245112534"/>
+ <reference ref="934642070"/>
+ <reference ref="22863608"/>
</array>
<reference key="parent" ref="0"/>
</object>
@@ -538,6 +611,16 @@
<reference key="object" ref="245112534"/>
<reference key="parent" ref="191373211"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">51</int>
+ <reference key="object" ref="934642070"/>
+ <reference key="parent" ref="191373211"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">52</int>
+ <reference key="object" ref="22863608"/>
+ <reference key="parent" ref="191373211"/>
+ </object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -556,16 +639,97 @@
<string key="48.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="49.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="51.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="52.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="8.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="9.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">50</int>
+ <int key="maxID">53</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <array class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <object class="IBPartialClassDescription">
+ <string key="className">TestViewController</string>
+ <string key="superclassName">UIViewController</string>
+ <dictionary class="NSMutableDictionary" key="actions">
+ <string key="buttonTapped:">id</string>
+ <string key="waitForItTapped:">id</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="actionInfosByName">
+ <object class="IBActionInfo" key="buttonTapped:">
+ <string key="name">buttonTapped:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo" key="waitForItTapped:">
+ <string key="name">waitForItTapped:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="outlets">
+ <string key="button1">UIButton</string>
+ <string key="button2">UIButton</string>
+ <string key="displayLabel">UILabel</string>
+ <string key="phoneNumberField">UITextField</string>
+ <string key="slider">UISlider</string>
+ <string key="tabBar">UITabBar</string>
+ <string key="tableView">UITableView</string>
+ <string key="tapableLabel">UILabel</string>
+ <string key="textField">UITextField</string>
+ <string key="waitForItButton">UIButton</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="button1">
+ <string key="name">button1</string>
+ <string key="candidateClassName">UIButton</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="button2">
+ <string key="name">button2</string>
+ <string key="candidateClassName">UIButton</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="displayLabel">
+ <string key="name">displayLabel</string>
+ <string key="candidateClassName">UILabel</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="phoneNumberField">
+ <string key="name">phoneNumberField</string>
+ <string key="candidateClassName">UITextField</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="slider">
+ <string key="name">slider</string>
+ <string key="candidateClassName">UISlider</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="tabBar">
+ <string key="name">tabBar</string>
+ <string key="candidateClassName">UITabBar</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="tableView">
+ <string key="name">tableView</string>
+ <string key="candidateClassName">UITableView</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="tapableLabel">
+ <string key="name">tapableLabel</string>
+ <string key="candidateClassName">UILabel</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="textField">
+ <string key="name">textField</string>
+ <string key="candidateClassName">UITextField</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="waitForItButton">
+ <string key="name">waitForItButton</string>
+ <string key="candidateClassName">UIButton</string>
+ </object>
+ </dictionary>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/TestViewController.h</string>
+ </object>
+ </object>
+ </array>
</object>
- <object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
View
1 tests/TestViewController.h
@@ -17,6 +17,7 @@
@property (retain, nonatomic) IBOutlet UILabel *tapableLabel;
@property (retain, nonatomic) IBOutlet UILabel *displayLabel;
@property (retain, nonatomic) IBOutlet UITextField *textField;
+@property (retain, nonatomic) IBOutlet UITextField *phoneNumberField;
@property (nonatomic) NSInteger tappedButton;
@property (nonatomic) NSInteger tappedTabBarItem;
View
2 tests/TestViewController.m
@@ -21,6 +21,7 @@ @implementation TestViewController
@synthesize tapableLabel = tapableLabel_;
@synthesize displayLabel = displayLabel_;
@synthesize textField = textField_;
+@synthesize phoneNumberField = phoneNumberField_;
@synthesize tappedButton = tappedButton_;
@synthesize tappedTabBarItem = tappedTabBarItem_;
@synthesize slider = slider_;
@@ -42,6 +43,7 @@ - (void)dealloc {
self.startDragTime = nil;
self.endDragTime = nil;
self.textField = nil;
+ self.phoneNumberField = nil;
[super dealloc];
}

0 comments on commit aca5e25

Please sign in to comment.
Something went wrong with that request. Please try again.