/
KIFTestStep.m
1036 lines (829 loc) · 48.7 KB
/
KIFTestStep.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// KIFTestStep.m
// KIF
//
// Created by Michael Thole on 5/20/11.
// Licensed to Square, Inc. under one or more contributor license agreements.
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.
#import "KIFTestStep.h"
#import "CGGeometry-KIFAdditions.h"
#import "UIAccessibilityElement-KIFAdditions.h"
#import "UIApplication-KIFAdditions.h"
#import "UIScrollView-KIFAdditions.h"
#import "UITouch-KIFAdditions.h"
#import "UIView-KIFAdditions.h"
#import "UIWindow-KIFAdditions.h"
static NSTimeInterval KIFTestStepDefaultTimeout = 10.0;
@interface KIFTestStep ()
@property (nonatomic, copy) KIFTestStepExecutionBlock executionBlock;
@property (nonatomic, copy) NSString *notificationName;
@property (nonatomic, retain) id notificationObject;
@property BOOL notificationOccurred;
@property BOOL observingForNotification;
@property (nonatomic, retain) KIFTestStep *childStep;
+ (BOOL)_isUserInteractionEnabledForView:(UIView *)view;
+ (BOOL)_enterCharacter:(NSString *)characterString;
+ (BOOL)_enterCharacter:(NSString *)characterString history:(NSMutableDictionary *)history;
+ (BOOL)_enterCustomKeyboardCharacter:(NSString *)characterString;
+ (UIAccessibilityElement *)_accessibilityElementWithLabel:(NSString *)label accessibilityValue:(NSString *)value tappable:(BOOL)mustBeTappable traits:(UIAccessibilityTraits)traits error:(out NSError **)error;
typedef CGPoint KIFDisplacement;
+ (KIFDisplacement)_displacementForSwipingInDirection:(KIFSwipeDirection)direction;
@end
@implementation KIFTestStep
@synthesize description;
@synthesize executionBlock;
@synthesize notificationName;
@synthesize notificationObject;
@synthesize notificationOccurred;
@synthesize observingForNotification;
@synthesize timeout;
@synthesize childStep;
#pragma mark Class Methods
+ (NSTimeInterval)defaultTimeout;
{
return KIFTestStepDefaultTimeout;
}
+ (void)setDefaultTimeout:(NSTimeInterval)newDefaultTimeout;
{
KIFTestStepDefaultTimeout = newDefaultTimeout;
}
+ (id)stepWithDescription:(NSString *)description executionBlock:(KIFTestStepExecutionBlock)executionBlock;
{
NSAssert(description.length, @"All steps must have a description");
NSAssert(executionBlock, @"A custom step cannot be created with an execution block");
KIFTestStep *step = [[self alloc] init];
step.description = description;
step.executionBlock = executionBlock;
return [step autorelease];
}
+ (id)stepThatFails;
{
return [self stepWithDescription:@"Always fails" executionBlock:^(KIFTestStep *step, NSError **error) {
KIFTestCondition(NO, error, @"This test always fails");
}];
}
+ (id)stepThatSucceeds;
{
return [self stepWithDescription:@"Always succeeds" executionBlock:^(KIFTestStep *step, NSError **error) {
return KIFTestStepResultSuccess;
}];
}
+ (void)stepFailed;
{
// Add a logging call here or set a breakpoint to debug failed KIFTestCondition calls
}
+ (id)stepToWaitForViewWithAccessibilityLabel:(NSString *)label;
{
return [self stepToWaitForViewWithAccessibilityLabel:label traits:UIAccessibilityTraitNone];
}
+ (id)stepToWaitForViewWithAccessibilityLabel:(NSString *)label traits:(UIAccessibilityTraits)traits;
{
return [self stepToWaitForViewWithAccessibilityLabel:label value:nil traits:traits];
}
+ (id)stepToWaitForViewWithAccessibilityLabel:(NSString *)label value:(NSString *)value traits:(UIAccessibilityTraits)traits;
{
NSString *description = nil;
if (value.length) {
description = [NSString stringWithFormat:@"Wait for view with accessibility label \"%@\" and accessibility value \"%@\"", label, value];
} else {
description = [NSString stringWithFormat:@"Wait for view with accessibility label \"%@\"", label];
}
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [self _accessibilityElementWithLabel:label accessibilityValue:value tappable:NO traits:traits error:error];
NSString *waitDescription = nil;
if (value.length) {
waitDescription = [NSString stringWithFormat:@"Waiting for presence of accessibility element with label \"%@\" and accessibility value \"%@\"", label, value];
} else {
waitDescription = [NSString stringWithFormat:@"Waiting for presence of accessibility element with label \"%@\"", label];
}
KIFTestWaitCondition(element, error, @"%@", waitDescription);
return KIFTestStepResultSuccess;
}];
}
+ (id)stepToWaitForAbsenceOfViewWithAccessibilityLabel:(NSString *)label;
{
return [self stepToWaitForAbsenceOfViewWithAccessibilityLabel:label traits:UIAccessibilityTraitNone];
}
+ (id)stepToWaitForAbsenceOfViewWithAccessibilityLabel:(NSString *)label traits:(UIAccessibilityTraits)traits;
{
return [self stepToWaitForAbsenceOfViewWithAccessibilityLabel:label value:nil traits:traits];
}
+ (id)stepToWaitForAbsenceOfViewWithAccessibilityLabel:(NSString *)label value:(NSString *)value traits:(UIAccessibilityTraits)traits;
{
NSString *description = nil;
if (value.length) {
description = [NSString stringWithFormat:@"Wait for view with accessibility label \"%@\" and accessibility value \"%@\" to be gone", label, value];
} else {
description = [NSString stringWithFormat:@"Wait for view with accessibility label \"%@\" to be gone", label];
}
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
// If the app is ignoring interaction events, then wait before doing our analysis
KIFTestWaitCondition(![[UIApplication sharedApplication] isIgnoringInteractionEvents], error, @"Application is ignoring interaction events.");
// If the element can't be found, then we're done
UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementWithLabel:label accessibilityValue:value traits:traits];
if (!element) {
return KIFTestStepResultSuccess;
}
UIView *view = [UIAccessibilityElement viewContainingAccessibilityElement:element];
// If we found an element, but it's not associated with a view, then something's wrong. Wait it out and try again.
KIFTestWaitCondition(view, error, @"Cannot find view containing accessibility element with the label \"%@\"", label);
// Hidden views count as absent
KIFTestWaitCondition([view isHidden], error, @"Accessibility element with label \"%@\" is visible and not hidden.", label);
return KIFTestStepResultSuccess;
}];
}
+ (id)stepToWaitForTappableViewWithAccessibilityLabel:(NSString *)label;
{
return [self stepToWaitForTappableViewWithAccessibilityLabel:label traits:UIAccessibilityTraitNone];
}
+ (id)stepToWaitForTappableViewWithAccessibilityLabel:(NSString *)label traits:(UIAccessibilityTraits)traits;
{
return [self stepToWaitForTappableViewWithAccessibilityLabel:label value:nil traits:traits];
}
+ (id)stepToWaitForTappableViewWithAccessibilityLabel:(NSString *)label value:(NSString *)value traits:(UIAccessibilityTraits)traits;
{
NSString *description = nil;
if (value.length) {
description = [NSString stringWithFormat:@"Wait for tappable view with accessibility label \"%@\" and accessibility value \"%@\"", label, value];
} else {
description = [NSString stringWithFormat:@"Wait for tappable view with accessibility label \"%@\"", label];
}
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [self _accessibilityElementWithLabel:label accessibilityValue:value tappable:YES traits:traits error:error];
return (element ? KIFTestStepResultSuccess : KIFTestStepResultWait);
}];
}
+ (id)stepToWaitForTimeInterval:(NSTimeInterval)interval description:(NSString *)description;
{
// In general, we should discourage use of a step like this. It's pragmatic to include it though.
__block NSTimeInterval startTime = 0;
KIFTestStep *step = [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
if (startTime == 0) {
startTime = [NSDate timeIntervalSinceReferenceDate];
}
KIFTestWaitCondition((([NSDate timeIntervalSinceReferenceDate] - startTime) >= interval), error, @"Waiting for time interval to expire.");
return KIFTestStepResultSuccess;
}];
// Increase timeout by interval so that the step doesn't timeout prematurely.
step.timeout += ceil(interval);
return step;
}
+ (id)stepToWaitForNotificationName:(NSString *)name object:(id)object;
{
NSString *description = [NSString stringWithFormat:@"Wait for notification \"%@\"", name];
KIFTestStep *step = [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
if (!step.observingForNotification) {
step.notificationName = name;
step.notificationObject = object;
step.observingForNotification = YES;
[[NSNotificationCenter defaultCenter] addObserver:step selector:@selector(_onObservedNotification:) name:name object:object];
}
KIFTestWaitCondition(step.notificationOccurred, error, @"Waiting for notification \"%@\"", name);
return KIFTestStepResultSuccess;
}];
return step;
}
+ (id)stepToWaitForNotificationName:(NSString *)name object:(id)object whileExecutingStep:(KIFTestStep *)childStep;
{
NSString *description = [NSString stringWithFormat:@"Wait for notification \"%@\" while executing child step \"%@\"", name, childStep];
KIFTestStep *step = [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
if (!step.observingForNotification) {
step.notificationName = name;
step.notificationObject = object;
step.observingForNotification = YES;
[[NSNotificationCenter defaultCenter] addObserver:step selector:@selector(_onObservedNotification:) name:name object:object];
}
// Execute the step we are observing for changes
KIFTestStepResult result = [step.childStep executeAndReturnError:error];
KIFTestWaitCondition(result != KIFTestStepResultWait, error, @"Waiting for completion of child step \"%@\"", step.childStep);
// Wait for the actual notification
KIFTestWaitCondition(step.notificationOccurred, error, @"Waiting for notification \"%@\"", name);
return KIFTestStepResultSuccess;
}];
step.childStep = childStep;
return step;
}
+ (id)stepToTapViewWithAccessibilityLabel:(NSString *)label;
{
return [self stepToTapViewWithAccessibilityLabel:label traits:UIAccessibilityTraitNone];
}
+ (id)stepToTapViewWithAccessibilityLabel:(NSString *)label traits:(UIAccessibilityTraits)traits;
{
return [self stepToTapViewWithAccessibilityLabel:label value:nil traits:traits];
}
+ (id)stepToTapViewWithAccessibilityLabel:(NSString *)label value:(NSString *)value traits:(UIAccessibilityTraits)traits;
{
NSString *description = nil;
if (value.length) {
description = [NSString stringWithFormat:@"Tap view with accessibility label \"%@\" and accessibility value \"%@\"", label, value];
} else {
description = [NSString stringWithFormat:@"Tap view with accessibility label \"%@\"", label];
}
// After tapping the view we want to wait a short period to allow things to settle (animations and such). We can't do this using CFRunLoopRunInMode() because certain things, such as the built-in media picker, do things with the run loop that are not compatible with this kind of wait. Instead we leverage the way KIF hooks into the existing run loop by returning "wait" results for the desired period.
const NSTimeInterval quiesceWaitInterval = 0.5;
__block NSTimeInterval quiesceStartTime = 0.0;
__block UIView *view = nil;
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
// If we've already tapped the view and stored it to a variable, and we've waited for the quiesce time to elapse, then we're done.
if (view) {
KIFTestWaitCondition(([NSDate timeIntervalSinceReferenceDate] - quiesceStartTime) >= quiesceWaitInterval, error, @"Waiting for view to become the first responder.");
return KIFTestStepResultSuccess;
}
UIAccessibilityElement *element = [self _accessibilityElementWithLabel:label accessibilityValue:value tappable:YES traits:traits error:error];
if (!element) {
return KIFTestStepResultWait;
}
view = [UIAccessibilityElement viewContainingAccessibilityElement:element];
KIFTestWaitCondition(view, error, @"Failed to find view for accessibility element with label \"%@\"", label);
if (![self _isUserInteractionEnabledForView:view]) {
if (error) {
*error = [[[NSError alloc] initWithDomain:@"KIFTest" code:KIFTestStepResultFailure userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"View with accessibility label \"%@\" is not enabled for interaction", label], NSLocalizedDescriptionKey, nil]] autorelease];
}
return KIFTestStepResultWait;
}
CGRect elementFrame = [view.window convertRect:element.accessibilityFrame toView:view];
CGPoint tappablePointInElement = [view tappablePointInRect:elementFrame];
// This is mostly redundant of the test in _accessibilityElementWithLabel:
KIFTestWaitCondition(!isnan(tappablePointInElement.x), error, @"The element with accessibility label %@ is not tappable", label);
[view tapAtPoint:tappablePointInElement];
KIFTestCondition(![view canBecomeFirstResponder] || [view isDescendantOfFirstResponder], error, @"Failed to make the view %@ which contains the accessibility element \"%@\" into the first responder", view, label);
quiesceStartTime = [NSDate timeIntervalSinceReferenceDate];
KIFTestWaitCondition(NO, error, @"Waiting for the view to settle.");
}];
}
+ (id)stepForViewWithAccessibilityLabel:(NSString *)label description:(NSString *)description executionBlock:(KIFTestStepExecutionBlockWithView)executionBlock
{
// viewFinderBlock will first try to find the view with the given |accessibilityLabel| then will
// invoke the |executionBlock|.
id viewFinderBlock = ^(KIFTestStep *step, NSError **error) {
UIApplication *app = [UIApplication sharedApplication];
// Scroll to make sure the view is visible, otherwise we will get an accessibilityElement that maps to the first visible parent view of the view we want.
UIAccessibilityElement *element = [self _accessibilityElementWithLabel:label accessibilityValue:nil tappable:NO traits:UIAccessibilityTraitNone error:error];
KIFTestWaitCondition(element, error, @"Wait for view with accessibility label \"%@\"", label);
// Now that the view is scrolled onto the screen, get the element again.
element = [app accessibilityElementWithLabel:label accessibilityValue:nil traits:UIAccessibilityTraitNone];
UIView *view = [UIAccessibilityElement viewContainingAccessibilityElement:element];
if (!view) {
return KIFTestStepResultFailure;
}
// Execute the block.
return executionBlock(step, view, error);
};
return [KIFTestStep stepWithDescription:description executionBlock:viewFinderBlock];
}
+ (id)stepToTapScreenAtPoint:(CGPoint)screenPoint;
{
NSString *description = [NSString stringWithFormat:@"Tap screen at point \"%@\"", NSStringFromCGPoint(screenPoint)];
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
// Try all the windows until we get one back that actually has something in it at the given point
UIView *view = nil;
for (UIWindow *window in [[[UIApplication sharedApplication] windows] reverseObjectEnumerator]) {
CGPoint windowPoint = [window convertPoint:screenPoint fromView:nil];
view = [window hitTest:windowPoint withEvent:nil];
// If we hit the window itself, then skip it.
if (view == window || view == nil) {
continue;
}
}
KIFTestWaitCondition(view, error, @"No view was found at the point %@", NSStringFromCGPoint(screenPoint));
// This is mostly redundant of the test in _accessibilityElementWithLabel:
CGPoint viewPoint = [view convertPoint:screenPoint fromView:nil];
[view tapAtPoint:viewPoint];
return KIFTestStepResultSuccess;
}];
}
+ (id)stepToEnterText:(NSString *)text intoViewWithAccessibilityLabel:(NSString *)label;
{
return [self stepToEnterText:text intoViewWithAccessibilityLabel:label traits:UIAccessibilityTraitNone expectedResult:nil];
}
+ (id)stepToEnterText:(NSString *)text intoViewWithAccessibilityLabel:(NSString *)label traits:(UIAccessibilityTraits)traits expectedResult:(NSString *)expectedResult;
{
NSString *description = [NSString stringWithFormat:@"Type the text \"%@\" into the view with accessibility label \"%@\"", text, label];
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [self _accessibilityElementWithLabel:label accessibilityValue:nil tappable:YES traits:traits error:error];
if (!element) {
return KIFTestStepResultWait;
}
UIView *view = [UIAccessibilityElement viewContainingAccessibilityElement:element];
KIFTestWaitCondition(view, error, @"Cannot find view with accessibility label \"%@\"", label);
CGRect elementFrame = [view.window convertRect:element.accessibilityFrame toView:view];
CGPoint tappablePointInElement = [view tappablePointInRect:elementFrame];
// This is mostly redundant of the test in _accessibilityElementWithLabel:
KIFTestCondition(!isnan(tappablePointInElement.x), error, @"The element with accessibility label %@ is not tappable", label);
[view tapAtPoint:tappablePointInElement];
KIFTestWaitCondition([view isDescendantOfFirstResponder], error, @"Failed to make the view with accessibility label \"%@\" the first responder. First responder is %@", label, [[[UIApplication sharedApplication] keyWindow] firstResponder]);
// Wait for the keyboard
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
for (NSUInteger characterIndex = 0; characterIndex < [text length]; characterIndex++) {
NSString *characterString = [text substringWithRange:NSMakeRange(characterIndex, 1)];
if (![self _enterCharacter:characterString]) {
// Attempt to cheat if we couldn't find the character
if ([view isKindOfClass:[UITextField class]] || [view isKindOfClass:[UITextView class]]) {
NSLog(@"KIF: Unable to find keyboard key for %@. Inserting manually.", characterString);
[(UITextField *)view setText:[[(UITextField *)view text] stringByAppendingString:characterString]];
} else {
KIFTestCondition(NO, error, @"Failed to find key for character \"%@\"", characterString);
}
}
}
// This is probably a UITextField- or UITextView-ish view, so make sure it worked
if ([view respondsToSelector:@selector(text)]) {
// We trim \n and \r because they trigger the return key, so they won't show up in the final product on single-line inputs
NSString *expected = [expectedResult ? expectedResult : text stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSString *actual = [[view performSelector:@selector(text)] stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
KIFTestCondition([actual isEqualToString:expected], error, @"Failed to actually enter text \"%@\" in field; instead, it was \"%@\"", text, actual);
}
return KIFTestStepResultSuccess;
}];
}
+ (id)stepToSelectPickerViewRowWithTitle:(NSString *)title;
{
NSString *description = [NSString stringWithFormat:@"Select the \"%@\" item from the picker", title];
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
// Find the picker view
UIPickerView *pickerView = [[[[UIApplication sharedApplication] pickerViewWindow] subviewsWithClassNameOrSuperClassNamePrefix:@"UIPickerView"] lastObject];
KIFTestCondition(pickerView, error, @"No picker view is present");
NSInteger componentCount = [pickerView.dataSource numberOfComponentsInPickerView:pickerView];
KIFTestCondition(componentCount == 1, error, @"The picker view has multiple columns, which is not supported in testing.");
for (NSInteger componentIndex = 0; componentIndex < componentCount; componentIndex++) {
NSInteger rowCount = [pickerView.dataSource pickerView:pickerView numberOfRowsInComponent:componentIndex];
for (NSInteger rowIndex = 0; rowIndex < rowCount; rowIndex++) {
NSString *rowTitle = nil;
if ([pickerView.delegate respondsToSelector:@selector(pickerView:titleForRow:forComponent:)]) {
rowTitle = [pickerView.delegate pickerView:pickerView titleForRow:rowIndex forComponent:componentIndex];
} else if ([pickerView.delegate respondsToSelector:@selector(pickerView:viewForRow:forComponent:reusingView:)]) {
// This delegate inserts views directly, so try to figure out what the title is by looking for a label
UIView *rowView = [pickerView.delegate pickerView:pickerView viewForRow:rowIndex forComponent:componentIndex reusingView:nil];
NSArray *labels = [rowView subviewsWithClassNameOrSuperClassNamePrefix:@"UILabel"];
UILabel *label = (labels.count > 0 ? [labels objectAtIndex:0] : nil);
rowTitle = label.text;
}
if ([rowTitle isEqual:title]) {
[pickerView selectRow:rowIndex inComponent:componentIndex animated:YES];
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
// Tap in the middle of the picker view to select the item
[pickerView tap];
// The combination of selectRow:inComponent:animated: and tap does not consistently result in
// pickerView:didSelectRow:inComponent: being called on the delegate. We need to do it explicitly.
if ([pickerView.delegate respondsToSelector:@selector(pickerView:didSelectRow:inComponent:)]) {
[pickerView.delegate pickerView:pickerView didSelectRow:rowIndex inComponent:componentIndex];
}
return KIFTestStepResultSuccess;
}
}
}
KIFTestCondition(NO, error, @"Failed to find picker view value with title \"%@\"", title);
return KIFTestStepResultFailure;
}];
}
+ (id)stepToSetOn:(BOOL)switchIsOn forSwitchWithAccessibilityLabel:(NSString *)label;
{
NSString *description = [NSString stringWithFormat:@"Toggle the switch with accessibility label \"%@\" to %@", label, switchIsOn ? @"ON" : @"OFF"];
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [self _accessibilityElementWithLabel:label accessibilityValue:nil tappable:YES traits:UIAccessibilityTraitNone error:error];
if (!element) {
return KIFTestStepResultWait;
}
UISwitch *switchView = (UISwitch *)[UIAccessibilityElement viewContainingAccessibilityElement:element];
KIFTestWaitCondition(switchView, error, @"Cannot find switch with accessibility label \"%@\"", label);
KIFTestWaitCondition([switchView isKindOfClass:[UISwitch class]], error, @"View with accessibility label \"%@\" is a %@, not a UISwitch", label, NSStringFromClass([switchView class]));
// No need to switch it if it's already in the correct position
BOOL current = switchView.on;
if (current == switchIsOn) {
return KIFTestStepResultSuccess;
}
CGRect elementFrame = [switchView.window convertRect:element.accessibilityFrame toView:switchView];
CGPoint tappablePointInElement = [switchView tappablePointInRect:elementFrame];
// This is mostly redundant of the test in _accessibilityElementWithLabel:
KIFTestCondition(!isnan(tappablePointInElement.x), error, @"The element with accessibility label %@ is not tappable", label);
[switchView tapAtPoint:tappablePointInElement];
// This is a UISwitch, so make sure it worked
if (switchIsOn != switchView.on) {
NSLog(@"Faking turning switch %@ with accessibility label %@", switchIsOn ? @"ON" : @"OFF", label);
[switchView setOn:switchIsOn animated:YES];
[switchView sendActionsForControlEvents:UIControlEventValueChanged];
}
// The switch animation takes a second to finish, and the action callback doesn't get called until it does.
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5f, false);
KIFTestCondition(switchView.on == switchIsOn, error, @"Failed to toggle switch to \"%@\"; instead, it was \"%@\"", switchIsOn ? @"ON" : @"OFF", switchView.on ? @"ON" : @"OFF");
return KIFTestStepResultSuccess;
}];
}
+ (id)stepToDismissPopover;
{
return [self stepWithDescription:@"Dismiss the popover" executionBlock:^(KIFTestStep *step, NSError **error) {
const NSTimeInterval tapDelay = 0.05;
NSArray *windows = [[UIApplication sharedApplication] windows];
KIFTestCondition(windows.count, error, @"Failed to find any windows in the application");
UIView *dimmingView = [[[windows objectAtIndex:0] subviewsWithClassNamePrefix:@"UIDimmingView"] lastObject];
[dimmingView tapAtPoint:CGPointMake(50.0f, 50.0f)];
CFRunLoopRunInMode(kCFRunLoopDefaultMode, tapDelay, false);
return KIFTestStepResultSuccess;
}];
}
+ (id)stepToSimulateMemoryWarning;
{
return [KIFTestStep stepWithDescription:@"Simulate a memory warning" executionBlock:^(KIFTestStep *step, NSError **error) {
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification object:[UIApplication sharedApplication]];
return KIFTestStepResultSuccess;
}];
}
+ (id)stepToTapRowInTableViewWithAccessibilityLabel:(NSString*)tableViewLabel atIndexPath:(NSIndexPath *)indexPath
{
NSString *description = [NSString stringWithFormat:@"Step to tap row %d in tableView with label %@", [indexPath row], tableViewLabel];
return [KIFTestStep stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementWithLabel:tableViewLabel];
KIFTestCondition(element, error, @"View with label %@ not found", tableViewLabel);
UITableView *tableView = (UITableView*)[UIAccessibilityElement viewContainingAccessibilityElement:element];
KIFTestCondition([tableView isKindOfClass:[UITableView class]], error, @"Specified view is not a UITableView");
KIFTestCondition(tableView, error, @"Table view with label %@ not found", tableViewLabel);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (!cell) {
KIFTestCondition([indexPath section] < [tableView numberOfSections], error, @"Section %d is not found in '%@' table view", [indexPath section], tableViewLabel);
KIFTestCondition([indexPath row] < [tableView numberOfRowsInSection:[indexPath section]], error, @"Row %d is not found in section %d of '%@' table view", [indexPath row], [indexPath section], tableViewLabel);
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
cell = [tableView cellForRowAtIndexPath:indexPath];
}
KIFTestCondition(cell, error, @"Table view cell at index path %@ not found", indexPath);
CGRect cellFrame = [cell.contentView convertRect:[cell.contentView frame] toView:tableView];
[tableView tapAtPoint:CGPointCenteredInRect(cellFrame)];
return KIFTestStepResultSuccess;
}];
}
#define NUM_POINTS_IN_SWIPE_PATH 20
+ (id)stepToSwipeViewWithAccessibilityLabel:(NSString *)label inDirection:(KIFSwipeDirection)direction
{
// The original version of this came from http://groups.google.com/group/kif-framework/browse_thread/thread/df3f47eff9f5ac8c
NSString *directionDescription = nil;
switch(direction)
{
case KIFSwipeDirectionRight:
directionDescription = @"right";
break;
case KIFSwipeDirectionLeft:
directionDescription = @"left";
break;
case KIFSwipeDirectionUp:
directionDescription = @"up";
break;
case KIFSwipeDirectionDown:
directionDescription = @"down";
break;
}
NSString *description = [NSString stringWithFormat:@"Step to swipe %@ on view with accessibility label %@", directionDescription, label];
return [KIFTestStep stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [self _accessibilityElementWithLabel:label accessibilityValue:nil tappable:NO traits:UIAccessibilityTraitNone error:error];
if (!element) {
return KIFTestStepResultWait;
}
UIView *viewToSwipe = [UIAccessibilityElement viewContainingAccessibilityElement:element];
KIFTestWaitCondition(viewToSwipe, error, @"Cannot find view with accessibility label \"%@\"", label);
// Within this method, all geometry is done in the coordinate system of
// the view to swipe.
CGRect elementFrame = [viewToSwipe.window convertRect:element.accessibilityFrame toView:viewToSwipe];
CGPoint swipeStart = CGPointCenteredInRect(elementFrame);
KIFDisplacement swipeDisplacement = [self _displacementForSwipingInDirection:direction];
CGPoint swipePath[NUM_POINTS_IN_SWIPE_PATH];
for (int pointIndex = 0; pointIndex < NUM_POINTS_IN_SWIPE_PATH; pointIndex++)
{
CGFloat swipeProgress = ((CGFloat)pointIndex)/(NUM_POINTS_IN_SWIPE_PATH - 1);
swipePath[pointIndex] = CGPointMake(swipeStart.x + (swipeProgress * swipeDisplacement.x),
swipeStart.y + (swipeProgress * swipeDisplacement.y));
}
[viewToSwipe dragAlongPathWithPoints:swipePath count:NUM_POINTS_IN_SWIPE_PATH];
return KIFTestStepResultSuccess;
}];
}
+ (id)stepToWaitForFirstResponderWithAccessibilityLabel:(NSString *)label;
{
NSString *description = [NSString stringWithFormat:@"Verify that the first responder is the view with accessibility label '%@'", label];
return [KIFTestStep stepWithDescription:description executionBlock:^KIFTestStepResult(KIFTestStep *step, NSError *__autoreleasing *error) {
UIResponder *firstResponder = [[[UIApplication sharedApplication] keyWindow] firstResponder];
KIFTestWaitCondition([[firstResponder accessibilityLabel] isEqualToString:label], error, @"Expected accessibility label for first responder to be '%@', got '%@'", label, [firstResponder accessibilityLabel]);
return KIFTestStepResultSuccess;
}];
}
#pragma mark Step Collections
+ (NSArray *)stepsToChoosePhotoInAlbum:(NSString *)albumName atRow:(NSInteger)row column:(NSInteger)column;
{
NSMutableArray *steps = [NSMutableArray array];
[steps addObject:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"Choose Photo"]];
// This is basically the same as the step to tap with an accessibility label except that the accessibility labels for the albums have the number of photos appended to the end, such as "My Photos (3)." This means that we have to do a prefix match rather than an exact match.
NSString *description = [NSString stringWithFormat:@"Select the \"%@\" photo album", albumName];
[steps addObject:[KIFTestStep stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
NSString *labelPrefix = [NSString stringWithFormat:@"%@, (", albumName];
UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementMatchingBlock:^(UIAccessibilityElement *element) {
return [element.accessibilityLabel hasPrefix:labelPrefix];
}];
KIFTestWaitCondition(element, error, @"Failed to find photo album with name %@", albumName);
UIView *view = [UIAccessibilityElement viewContainingAccessibilityElement:element];
KIFTestWaitCondition(view, error, @"Failed to find view for photo album with name %@", albumName);
if (![self _isUserInteractionEnabledForView:view]) {
if (error) {
*error = [[[NSError alloc] initWithDomain:@"KIFTest" code:KIFTestStepResultFailure userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Album picker is not enabled for interaction"], NSLocalizedDescriptionKey, nil]] autorelease];
}
return KIFTestStepResultWait;
}
CGRect elementFrame = [view.window convertRect:element.accessibilityFrame toView:view];
CGPoint tappablePointInElement = [view tappablePointInRect:elementFrame];
[view tapAtPoint:tappablePointInElement];
return KIFTestStepResultSuccess;
}]];
[steps addObject:[KIFTestStep stepToWaitForTimeInterval:0.5 description:@"Wait for media picker view controller to be pushed."]];
// Tap the desired photo in the grid
// TODO: This currently only works for the first page of photos. It should scroll appropriately at some point.
const CGFloat headerHeight = 64.0;
const CGSize thumbnailSize = CGSizeMake(75.0, 75.0);
const CGFloat thumbnailMargin = 5.0;
CGPoint thumbnailCenter;
thumbnailCenter.x = thumbnailMargin + (MAX(0, column - 1) * (thumbnailSize.width + thumbnailMargin)) + thumbnailSize.width / 2.0;
thumbnailCenter.y = headerHeight + thumbnailMargin + (MAX(0, row - 1) * (thumbnailSize.height + thumbnailMargin)) + thumbnailSize.height / 2.0;
[steps addObject:[KIFTestStep stepToTapScreenAtPoint:thumbnailCenter]];
// Dismiss the resize UI
[steps addObject:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"Choose"]];
return steps;
}
#pragma mark Initialization
- (id)init;
{
self = [super init];
if (!self) {
return nil;
}
self.timeout = [[self class] defaultTimeout];
return self;
}
- (void)dealloc;
{
[executionBlock release];
executionBlock = nil;
[description release];
description = nil;
[notificationName release];
notificationName = nil;
[notificationObject release];
notificationObject = nil;
[childStep release];
childStep = nil;
[super dealloc];
}
#pragma mark Public Methods
- (KIFTestStepResult)executeAndReturnError:(NSError **)error;
{
KIFTestStepResult result = KIFTestStepResultFailure;
if (self.executionBlock) {
@try {
result = self.executionBlock(self, error);
}
@catch (id exception) {
// We need to catch exceptions and things like NSInternalInconsistencyException, which is actually an NSString
KIFTestCondition(NO, error, @"Step threw exception: %@", exception);
}
}
return result;
}
- (void)cleanUp;
{
if (notificationName || notificationObject) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:notificationName object:notificationObject];
}
}
#pragma mark Private Methods
- (void)_onObservedNotification:(NSNotification *)notification;
{
self.notificationOccurred = YES;
}
+ (BOOL)_isUserInteractionEnabledForView:(UIView *)view;
{
BOOL isUserInteractionEnabled = view.userInteractionEnabled;
// Navigation item views don't have user interaction enabled, but their parent nav bar does and will forward the event
if (!isUserInteractionEnabled && [view isKindOfClass:NSClassFromString(@"UINavigationItemView")]) {
// If this view is inside a nav bar, and the nav bar is enabled, then consider it enabled
UIView *navBar = [view superview];
while (navBar && ![navBar isKindOfClass:[UINavigationBar class]]) {
navBar = [navBar superview];
}
if (navBar && navBar.userInteractionEnabled) {
isUserInteractionEnabled = YES;
}
}
// UIActionsheet Buttons have UIButtonLabels with userInteractionEnabled=NO inside,
// grab the superview UINavigationButton instead.
if (!isUserInteractionEnabled && [view isKindOfClass:NSClassFromString(@"UIButtonLabel")]) {
UIView *button = [view superview];
while (button && ![button isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
button = [button superview];
}
if (button && button.userInteractionEnabled) {
isUserInteractionEnabled = YES;
}
}
return isUserInteractionEnabled;
}
+ (NSString *)_representedKeyboardStringForCharacter:(NSString *)characterString;
{
// Interpret control characters appropriately
if ([characterString isEqual:@"\b"]) {
characterString = @"Delete";
}
return characterString;
}
+ (BOOL)_enterCharacter:(NSString *)characterString;
{
return [self _enterCharacter:characterString history:[NSMutableDictionary dictionary]];
}
+ (BOOL)_enterCharacter:(NSString *)characterString history:(NSMutableDictionary *)history;
{
const NSTimeInterval keystrokeDelay = 0.05f;
// Each key on the keyboard does not have its own view, so we have to ask for the list of keys,
// find the appropriate one, and tap inside the frame of that key on the main keyboard view.
if (!characterString.length) {
return YES;
}
UIWindow *keyboardWindow = [[UIApplication sharedApplication] keyboardWindow];
UIView *keyboardView = [[keyboardWindow subviewsWithClassNamePrefix:@"UIKBKeyplaneView"] lastObject];
// If we didn't find the standard keyboard view, then we may have a custom keyboard
if (!keyboardView) {
return [self _enterCustomKeyboardCharacter:characterString];
}
id /*UIKBKeyplane*/ keyplane = [keyboardView valueForKey:@"keyplane"];
BOOL isShiftKeyplane = [[keyplane valueForKey:@"isShiftKeyplane"] boolValue];
NSMutableArray *unvisitedForKeyplane = [history objectForKey:[NSValue valueWithNonretainedObject:keyplane]];
if (!unvisitedForKeyplane) {
unvisitedForKeyplane = [NSMutableArray arrayWithObjects:@"More", @"International", nil];
if (!isShiftKeyplane) {
[unvisitedForKeyplane insertObject:@"Shift" atIndex:0];
}
[history setObject:unvisitedForKeyplane forKey:[NSValue valueWithNonretainedObject:keyplane]];
}
NSArray *keys = [keyplane valueForKey:@"keys"];
// Interpret control characters appropriately
characterString = [self _representedKeyboardStringForCharacter:characterString];
id keyToTap = nil;
id modifierKey = nil;
NSString *selectedModifierRepresentedString = nil;
while (YES) {
for (id/*UIKBKey*/ key in keys) {
NSString *representedString = [key valueForKey:@"representedString"];
// Find the key based on the key's represented string
if ([representedString isEqual:characterString]) {
keyToTap = key;
}
if (!modifierKey && unvisitedForKeyplane.count && [[unvisitedForKeyplane objectAtIndex:0] isEqual:representedString]) {
modifierKey = key;
selectedModifierRepresentedString = representedString;
[unvisitedForKeyplane removeObjectAtIndex:0];
}
}
if (keyToTap) {
break;
}
if (modifierKey) {
break;
}
if (!unvisitedForKeyplane.count) {
return NO;
}
// If we didn't find the key or the modifier, then this modifier must not exist on this keyboard. Remove it.
[unvisitedForKeyplane removeObjectAtIndex:0];
}
if (keyToTap) {
[keyboardView tapAtPoint:CGPointCenteredInRect([keyToTap frame])];
CFRunLoopRunInMode(kCFRunLoopDefaultMode, keystrokeDelay, false);
return YES;
}
// We didn't find anything, so try the symbols pane
if (modifierKey) {
[keyboardView tapAtPoint:CGPointCenteredInRect([modifierKey frame])];
CFRunLoopRunInMode(kCFRunLoopDefaultMode, keystrokeDelay, false);
// If we're back at a place we've been before, and we still have things to explore in the previous
id /*UIKBKeyplane*/ newKeyplane = [keyboardView valueForKey:@"keyplane"];
id /*UIKBKeyplane*/ previousKeyplane = [history valueForKey:@"previousKeyplane"];
if (newKeyplane == previousKeyplane) {
// Come back to the keyplane that we just tested so that we can try the other modifiers
NSMutableArray *previousKeyplaneHistory = [history objectForKey:[NSValue valueWithNonretainedObject:newKeyplane]];
[previousKeyplaneHistory insertObject:[history valueForKey:@"lastModifierRepresentedString"] atIndex:0];
} else {
[history setValue:keyplane forKey:@"previousKeyplane"];
[history setValue:selectedModifierRepresentedString forKey:@"lastModifierRepresentedString"];
}
return [self _enterCharacter:characterString history:history];
}
return NO;
}
+ (BOOL)_enterCustomKeyboardCharacter:(NSString *)characterString;
{
const NSTimeInterval keystrokeDelay = 0.05f;
if (!characterString.length) {
return YES;
}
characterString = [self _representedKeyboardStringForCharacter:characterString];
// For custom keyboards, use the classic methods of looking up views based on accessibility labels
UIWindow *keyboardWindow = [[UIApplication sharedApplication] keyboardWindow];
UIAccessibilityElement *element = [keyboardWindow accessibilityElementWithLabel:characterString];
if (!element) {
return NO;
}
UIView *view = [UIAccessibilityElement viewContainingAccessibilityElement:element];
CGRect keyFrame = [view.window convertRect:[element accessibilityFrame] toView:view];
[view tapAtPoint:CGPointCenteredInRect(keyFrame)];
CFRunLoopRunInMode(kCFRunLoopDefaultMode, keystrokeDelay, false);
return YES;
}
+ (UIAccessibilityElement *)_accessibilityElementWithLabel:(NSString *)label accessibilityValue:(NSString *)value tappable:(BOOL)mustBeTappable traits:(UIAccessibilityTraits)traits error:(out NSError **)error;
{
UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementWithLabel:label accessibilityValue:value traits:traits];
if (!element) {
if (error) {
// For purposes of a better error message, see if we can find the view, just not a view with the specified value.
if (value && [[UIApplication sharedApplication] accessibilityElementWithLabel:label accessibilityValue:nil traits:traits]) {
*error = [[[NSError alloc] initWithDomain:@"KIFTest" code:KIFTestStepResultFailure userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Found an accessibility element with the label \"%@\", but not with the value \"%@\"", label, value], NSLocalizedDescriptionKey, nil]] autorelease];
// Check the traits, too.
} else if (traits != UIAccessibilityTraitNone && [[UIApplication sharedApplication] accessibilityElementWithLabel:label accessibilityValue:nil traits:UIAccessibilityTraitNone]) {
*error = [[[NSError alloc] initWithDomain:@"KIFTest" code:KIFTestStepResultFailure userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Found an accessibility element with the label \"%@\", but not with the traits \"%llu\"", label, traits], NSLocalizedDescriptionKey, nil]] autorelease];
} else {
*error = [[[NSError alloc] initWithDomain:@"KIFTest" code:KIFTestStepResultFailure userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Failed to find accessibility element with the label \"%@\"", label], NSLocalizedDescriptionKey, nil]] autorelease];
}
}
return nil;
}
// Make sure the element is visible
UIView *view = [UIAccessibilityElement viewContainingAccessibilityElement:element];
if (!view) {
if (error) {
*error = [[[NSError alloc] initWithDomain:@"KIFTest" code:KIFTestStepResultFailure userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat: @"Cannot find view containing accessibility element with the label \"%@\"", label], NSLocalizedDescriptionKey, nil]] autorelease];
}
return nil;
}
// Scroll the view to be visible if necessary
UIScrollView *scrollView = (UIScrollView *)view;
while (scrollView && ![scrollView isKindOfClass:[UIScrollView class]]) {
scrollView = (UIScrollView *)scrollView.superview;
}
if (scrollView) {
if ((UIAccessibilityElement *)view == element) {
[scrollView scrollViewToVisible:view animated:YES];
} else {
CGRect elementFrame = [view.window convertRect:element.accessibilityFrame toView:scrollView];
[scrollView scrollRectToVisible:elementFrame animated:YES];
}
// Give the scroll view a small amount of time to perform the scroll.
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.3, false);
}
if ([[UIApplication sharedApplication] isIgnoringInteractionEvents]) {
if (error) {
*error = [[[NSError alloc] initWithDomain:@"KIFTest" code:KIFTestStepResultFailure userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Application is ignoring interaction events", NSLocalizedDescriptionKey, nil]] autorelease];
}
return nil;
}
// There are some issues with the tappability check in UIWebViews, so if the view is a UIWebView we will just skip the check.
if ([NSStringFromClass([view class]) isEqualToString:@"UIWebBrowserView"]) {
return element;
}
if (mustBeTappable) {
// Make sure the view is tappable
if (![view isTappable]) {
if (error) {
*error = [[[NSError alloc] initWithDomain:@"KIFTest" code:KIFTestStepResultFailure userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Accessibility element with label \"%@\" is not tappable. It may be blocked by other views.", label], NSLocalizedDescriptionKey, nil]] autorelease];
}
return nil;
}
} else {
// If we don't require tappability, at least make sure it's not hidden
if ([view isHidden]) {
if (error) {
*error = [[[NSError alloc] initWithDomain:@"KIFTest" code:KIFTestStepResultFailure userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Accessibility element with label \"%@\" is hidden.", label], NSLocalizedDescriptionKey, nil]] autorelease];