Skip to content
Browse files

simple implementations for Mac

  • Loading branch information...
1 parent 5ed7295 commit 5f651e4399b7028b9b8acef0ecad60e85f904288 @joshaber committed
Showing with 44 additions and 0 deletions.
  1. +19 −0 Classes/KIFTestStep-Mac.h
  2. +25 −0 Classes/KIFTestStep-Mac.m
View
19 Classes/KIFTestStep-Mac.h
@@ -12,4 +12,23 @@
@interface KIFTestStep (Mac)
+/*!
+ @method stepToWaitForViewWithAccessibilityIdentifier:
+ @abstract A step that waits until a view or accessibility element is present.
+ @discussion The view or accessibility element with the given label is found in the view heirarchy. If the element isn't found, then the step will attempt to wait until it is. Note that the view does not necessarily have to be visible on the screen, and may be behind another view or offscreen. Views with their hidden property set to YES are ignored.
+
+ @param identifier The accessibility identifier of the element to wait for.
+ @result A configured test step.
+ */
++ (id)stepToWaitForViewWithAccessibilityIdentifier:(NSString *)identifier;
+
+/*!
+ @method stepToClickViewWithAccessibilityIdentifier:
+ @abstract A step that clicks a particular view in the view hierarchy.
+ @discussion The view or accessibility element with the given identifier is searched for in the view hierarchy. If the element isn't found or isn't currently clickable, then the step will attempt to wait until it is. Once the view is present and clickable, a click event is simulated in the center of the view or element.
+ @param label The accessibility identifier of the element to click.
+ @result A configured test step.
+ */
++ (id)stepToClickViewWithAccessibilityIdentifier:(NSString *)identifier;
+
@end
View
25 Classes/KIFTestStep-Mac.m
@@ -7,10 +7,35 @@
//
#import "KIFTestStep-Mac.h"
+#import "KIFApplication.h"
@implementation KIFTestStep (Mac)
++ (id)stepToWaitForViewWithAccessibilityIdentifier:(NSString *)identifier {
+ NSString *description = [NSString stringWithFormat:@"Wait for view with accessibility identifier \"%@\"", identifier];
+
+ return [self stepWithDescription:description executionBlock:^KIFTestStepResult(KIFTestStep *step, NSError **error) {
+ KIFElement *element = [[KIFApplication currentApplication].mainWindow childWithIdentifier:identifier];
+ return (element ? KIFTestStepResultSuccess : KIFTestStepResultWait);
+ }];
+}
++ (id)stepToClickViewWithAccessibilityIdentifier:(NSString *)identifier {
+ NSString *description = [NSString stringWithFormat:@"Tap view with accessibility identifier \"%@\"", identifier];
+
+ return [self stepWithDescription:description executionBlock:^KIFTestStepResult(KIFTestStep *step, NSError **error) {
+ KIFElement *element = [[KIFApplication currentApplication].mainWindow childWithIdentifier:identifier];
+ if (!element) {
+ return KIFTestStepResultWait;
+ }
+
+ [element performPressAction];
+
+ CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
+
+ return KIFTestStepResultSuccess;
+ }];
+}
@end

0 comments on commit 5f651e4

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