Skip to content

Commit

Permalink
Fix ordering of wait to happen after the check for first responder-ness
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Paulson + Eric Firestone committed Sep 22, 2011
1 parent 8c17419 commit e52fd75
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions Classes/KIFTestStep.m
Expand Up @@ -257,38 +257,39 @@ + (id)stepToTapViewWithAccessibilityLabel:(NSString *)label value:(NSString *)va

return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {

KIFTestWaitCondition(!view || (([NSDate timeIntervalSinceReferenceDate] - quiesceStartTime) >= quiesceWaitInterval), error, @"Waiting for view to become the first responder.");
// 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;
}

if (!view) {
UIAccessibilityElement *element = [self _accessibilityElementWithLabel:label accessibilityValue:value tappable:YES traits:traits error:error];
if (!element) {
return KIFTestStepResultWait;
}
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);
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;
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];
CGRect elementFrame = [view.window convertRect:element.accessibilityFrame toView:view];
CGPoint tappablePointInElement = [view tappablePointInRect:elementFrame];

quiesceStartTime = [NSDate timeIntervalSinceReferenceDate];
KIFTestWaitCondition(NO, error, @"Waiting for the view to settle.");
}
// 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);

return KIFTestStepResultSuccess;
quiesceStartTime = [NSDate timeIntervalSinceReferenceDate];

KIFTestWaitCondition(NO, error, @"Waiting for the view to settle.");
}];
}

Expand Down

0 comments on commit e52fd75

Please sign in to comment.