From 25fecde4dfd8285aa4c0be7089c6c04d3897d21b Mon Sep 17 00:00:00 2001 From: Brian Gorby Date: Wed, 8 Feb 2012 15:04:42 -0800 Subject: [PATCH] Before searching for a tappable point on a rect, ensure the rect has been converted in the coordinate-space of a window with an identity transform. --- Classes/KIFTestStep.m | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Classes/KIFTestStep.m b/Classes/KIFTestStep.m index 5e260337e..104201642 100644 --- a/Classes/KIFTestStep.m +++ b/Classes/KIFTestStep.m @@ -278,7 +278,24 @@ + (id)stepToTapViewWithAccessibilityLabel:(NSString *)label value:(NSString *)va return KIFTestStepResultWait; } - CGRect elementFrame = [view.window convertRect:element.accessibilityFrame toView:view]; + // Need to convert the element's accessibilityFrame in the coordinate-space of a window with an identity transform. This allows for discovery of a tappable point in an UIAlertView button when the current orientation is not portrait, since UIAlertViews are presented in a separate window with an applied CGAffineTransform based on device rotation. + UIWindow *identityTransformWindow = nil; + if (CGAffineTransformIsIdentity(view.window.transform)) { + identityTransformWindow = view.window; + } + else { + for (UIWindow *window in [[[UIApplication sharedApplication] windows] reverseObjectEnumerator]) { + if (CGAffineTransformIsIdentity(window.transform)){ + identityTransformWindow = window; + break; + } + } + } + + KIFTestWaitCondition(identityTransformWindow, error, @"Failed to find window with level UIWindowLevelNormal"); + + CGRect elementFrame = [identityTransformWindow convertRect:element.accessibilityFrame toView:view]; + CGPoint tappablePointInElement = [view tappablePointInRect:elementFrame]; // This is mostly redundant of the test in _accessibilityElementWithLabel: