Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add the ability to search by title

  • Loading branch information...
commit 1bdde7b64321472d590e425650be5aa1424a6e69 1 parent f475836
Josh Abernathy authored
3  Additions/AX/KIFElement.h
View
@@ -19,6 +19,9 @@
- (KIFElement *)immediateChildWithIdentifier:(NSString *)identifier; // only searches in the element's immediate children
- (KIFElement *)childWithPath:(NSString *)identifierPath;
+- (KIFElement *)childWithTitle:(NSString *)title; // breadth-first searches until it finds a match or runs out of children
+- (KIFElement *)immediateChildWithTitle:(NSString *)title; // only searches in the element's immediate children
+
- (void)performPressAction;
@property (nonatomic, assign, readonly) AXUIElementRef elementRef;
32 Additions/AX/KIFElement.m
View
@@ -70,7 +70,6 @@ - (KIFElement *)childWithIdentifier:(NSString *)identifier {
}
- (KIFElement *)immediateChildWithIdentifier:(NSString *)identifier {
- NSLog(@"%@, %@", self.children, identifier);
for(KIFElement *child in self.children) {
if([child.identifier isEqualToString:identifier]) {
return child;
@@ -80,6 +79,37 @@ - (KIFElement *)immediateChildWithIdentifier:(NSString *)identifier {
return nil;
}
+- (KIFElement *)childWithTitle:(NSString *)title {
+ NSMutableArray *parentsToInvestigate = [NSMutableArray array];
+ [parentsToInvestigate addObject:self];
+
+ while(parentsToInvestigate.count > 0) {
+ NSMutableArray *nextSetOfParents = [NSMutableArray array];
+ for(KIFElement *parent in parentsToInvestigate) {
+ KIFElement *match = [parent immediateChildWithTitle:title];
+ if(match != nil) {
+ return match;
+ } else {
+ [nextSetOfParents addObjectsFromArray:parent.children];
+ }
+ }
+
+ parentsToInvestigate = nextSetOfParents;
+ }
+
+ return nil;
+}
+
+- (KIFElement *)immediateChildWithTitle:(NSString *)title {
+ for(KIFElement *child in self.children) {
+ if([child.title isEqualToString:title]) {
+ return child;
+ }
+ }
+
+ return nil;
+}
+
- (KIFElement *)childWithPath:(NSString *)identifierPath {
NSArray *elementIdentifiers = [identifierPath componentsSeparatedByString:@"/"];
KIFElement *currentElement = self;
21 Classes/KIFTestStep-Mac.h
View
@@ -15,7 +15,7 @@
/*!
@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.
+ @discussion The view or accessibility element with the given identifier 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.
@@ -31,4 +31,23 @@
*/
+ (id)stepToClickViewWithAccessibilityIdentifier:(NSString *)identifier;
+/*!
+ @method stepToWaitForViewWithTitle:
+ @abstract A step that waits until a view or accessibility element is present.
+ @discussion The view or accessibility element with the given title 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 title of the element to wait for.
+ @result A configured test step.
+ */
++ (id)stepToWaitForViewWithTitle:(NSString *)title;
+
+/*!
+ @method stepToClickViewWithTitle:
+ @abstract A step that clicks a particular view in the view hierarchy.
+ @discussion The view or accessibility element with the given title 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 title of the element to click.
+ @result A configured test step.
+ */
++ (id)stepToClickViewWithTitle:(NSString *)title;
+
@end
28 Classes/KIFTestStep-Mac.m
View
@@ -22,7 +22,7 @@ + (id)stepToWaitForViewWithAccessibilityIdentifier:(NSString *)identifier {
}
+ (id)stepToClickViewWithAccessibilityIdentifier:(NSString *)identifier {
- NSString *description = [NSString stringWithFormat:@"Tap view with accessibility identifier \"%@\"", identifier];
+ NSString *description = [NSString stringWithFormat:@"Click view with accessibility identifier \"%@\"", identifier];
return [self stepWithDescription:description executionBlock:^KIFTestStepResult(KIFTestStep *step, NSError **error) {
KIFElement *element = [[KIFApplication currentApplication].mainWindow childWithIdentifier:identifier];
@@ -38,4 +38,30 @@ + (id)stepToClickViewWithAccessibilityIdentifier:(NSString *)identifier {
}];
}
++ (id)stepToWaitForViewWithTitle:(NSString *)title {
+ NSString *description = [NSString stringWithFormat:@"Wait for view with title \"%@\"", title];
+
+ return [self stepWithDescription:description executionBlock:^KIFTestStepResult(KIFTestStep *step, NSError **error) {
+ KIFElement *element = [[KIFApplication currentApplication].mainWindow childWithTitle:title];
+ return (element ? KIFTestStepResultSuccess : KIFTestStepResultWait);
+ }];
+}
+
++ (id)stepToClickViewWithTitle:(NSString *)title {
+ NSString *description = [NSString stringWithFormat:@"Click view with title \"%@\"", title];
+
+ return [self stepWithDescription:description executionBlock:^KIFTestStepResult(KIFTestStep *step, NSError **error) {
+ KIFElement *element = [[KIFApplication currentApplication].mainWindow childWithTitle:title];
+ if (!element) {
+ return KIFTestStepResultWait;
+ }
+
+ [element performPressAction];
+
+ CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
+
+ return KIFTestStepResultSuccess;
+ }];
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.