diff --git a/EarlGrey/Action/GREYActions.m b/EarlGrey/Action/GREYActions.m index 92e0fb14b..30b0e6e04 100644 --- a/EarlGrey/Action/GREYActions.m +++ b/EarlGrey/Action/GREYActions.m @@ -240,8 +240,12 @@ + (void)initialize { performBlock:^BOOL (id element, __strong NSError **errorOrNil) { NSString *textStr; if ([element grey_isWebAccessibilityElement]) { +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 [GREYActions grey_setText:@"" onWebElement:element]; return YES; +#else + return NO; +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 } else if ([element isKindOfClass:gAccessibilityTextFieldElementClass]) { element = [element textField]; } else if ([element respondsToSelector:@selector(text)]) { @@ -298,8 +302,13 @@ + (void)initialize { // TODO: JS Errors should be propagated up. id constraints = grey_allOf(grey_not(grey_systemAlertViewShown()), - grey_anyOf(grey_kindOfClass([UIWebView class]), - grey_kindOfClass([WKWebView class]), nil), +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + grey_anyOf( + grey_kindOfClass([UIWebView class]), + grey_kindOfClass([WKWebView class]), nil), +#else + grey_kindOfClass([WKWebView class]), +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 nil); BOOL (^performBlock)(id webView, __strong NSError **errorOrNil) = ^( id webView, __strong NSError **errorOrNil) { @@ -320,7 +329,9 @@ + (void)initialize { *outResult = resultString; } return completionDone; - } else if ([webView isKindOfClass:[UIWebView class]]) { + } +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + else if ([webView isKindOfClass:[UIWebView class]]) { UIWebView *uiWebView = webView; if (outResult) { *outResult = [uiWebView stringByEvaluatingJavaScriptFromString:js]; @@ -331,6 +342,7 @@ + (void)initialize { [[GREYUIThreadExecutor sharedInstance] drainForTime:0.5]; // Wait for actions to register. return YES; } +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 return NO; }; return [[GREYActionBlock alloc] initWithName:@"Execute JavaScript" @@ -360,6 +372,7 @@ + (void)initialize { #pragma mark - Private +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 /** * Sets WebView input text value. * @@ -388,6 +401,7 @@ + (void)grey_setText:(NSString *)text onWebElement:(id)element { UIWebView *parentWebView = (UIWebView *)[element grey_viewContainingSelf]; [parentWebView stringByEvaluatingJavaScriptFromString:jsForTitle]; } +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 /** * Set the UITextField text value directly, bypassing the iOS keyboard. @@ -410,7 +424,9 @@ + (void)grey_setText:(NSString *)text onWebElement:(id)element { constraints:constraints performBlock:^BOOL (id element, __strong NSError **errorOrNil) { if ([element grey_isWebAccessibilityElement]) { +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 [GREYActions grey_setText:text onWebElement:element]; +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 } else { if ([element isKindOfClass:gAccessibilityTextFieldElementClass]) { element = [element textField]; diff --git a/EarlGrey/Action/GREYScrollAction.m b/EarlGrey/Action/GREYScrollAction.m index 014f8cb5a..c5a308f35 100644 --- a/EarlGrey/Action/GREYScrollAction.m +++ b/EarlGrey/Action/GREYScrollAction.m @@ -75,11 +75,16 @@ - (instancetype)initWithDirection:(GREYDirection)direction NSString *name = [NSString stringWithFormat:@"Scroll %@ for %g", NSStringFromGREYDirection(direction), amount]; self = [super initWithName:name - constraints:grey_allOf(grey_anyOf(grey_kindOfClass([UIScrollView class]), - grey_kindOfClass([UIWebView class]), - nil), - grey_not(grey_systemAlertViewShown()), - nil)]; + constraints:grey_allOf( +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + grey_anyOf(grey_kindOfClass([UIScrollView class]), + grey_kindOfClass([UIWebView class]), + nil), +#else + grey_kindOfClass([UIScrollView class]), +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + grey_not(grey_systemAlertViewShown()), + nil)]; if (self) { _direction = direction; _amount = amount; @@ -98,10 +103,13 @@ - (BOOL)perform:(id)element error:(__strong NSError **)errorOrNil { if (![self satisfiesConstraintsForElement:element error:errorOrNil]) { return NO; } + +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 // To scroll UIWebView we must use the UIScrollView in its hierarchy and scroll it. if ([element isKindOfClass:[UIWebView class]]) { element = [(UIWebView *)element scrollView]; } +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 CGFloat amountRemaining = _amount; BOOL success = YES; diff --git a/EarlGrey/Action/GREYScrollToContentEdgeAction.m b/EarlGrey/Action/GREYScrollToContentEdgeAction.m index 876a4f24a..fd873222c 100644 --- a/EarlGrey/Action/GREYScrollToContentEdgeAction.m +++ b/EarlGrey/Action/GREYScrollToContentEdgeAction.m @@ -56,11 +56,16 @@ - (instancetype)initWithEdge:(GREYContentEdge)edge startPointPercents:(CGPoint)s NSString *name = [NSString stringWithFormat:@"Scroll To %@ content edge", NSStringFromGREYContentEdge(edge)]; self = [super initWithName:name - constraints:grey_allOf(grey_anyOf(grey_kindOfClass([UIScrollView class]), - grey_kindOfClass([UIWebView class]), - nil), - grey_not(grey_systemAlertViewShown()), - nil)]; + constraints:grey_allOf( +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + grey_anyOf(grey_kindOfClass([UIScrollView class]), + grey_kindOfClass([UIWebView class]), + nil), +#else + grey_kindOfClass([UIScrollView class]), +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + grey_not(grey_systemAlertViewShown()), + nil)]; if (self) { _edge = edge; _startPointPercents = startPointPercents; @@ -78,10 +83,12 @@ - (BOOL)perform:(UIScrollView *)element error:(__strong NSError **)errorOrNil { if (![self satisfiesConstraintsForElement:element error:errorOrNil]) { return NO; } +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 // To scroll UIWebView we must use the UIScrollView in its hierarchy and scroll it. if ([element isKindOfClass:[UIWebView class]]) { element = [(UIWebView *)element scrollView]; } +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 // Get the maximum scrollable amount in any direction and keep applying it until the edge // is reached. diff --git a/EarlGrey/Additions/NSObject+GREYAdditions.m b/EarlGrey/Additions/NSObject+GREYAdditions.m index 2a8ccab64..4144ace92 100644 --- a/EarlGrey/Additions/NSObject+GREYAdditions.m +++ b/EarlGrey/Additions/NSObject+GREYAdditions.m @@ -87,7 +87,10 @@ - (NSString *)grey_recursiveDescription { - (UIView *)grey_viewContainingSelf { if ([self grey_isWebAccessibilityElement]) { +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 return [[self grey_containersAssignableFromClass:[UIWebView class]] firstObject]; +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + return nil; } else if ([self isKindOfClass:[UIView class]]) { return [self grey_container]; } else if ([self respondsToSelector:@selector(accessibilityContainer)]) { diff --git a/EarlGrey/Additions/UIWebView+GREYAdditions.h b/EarlGrey/Additions/UIWebView+GREYAdditions.h index 824c48ad5..90a87656f 100644 --- a/EarlGrey/Additions/UIWebView+GREYAdditions.h +++ b/EarlGrey/Additions/UIWebView+GREYAdditions.h @@ -16,6 +16,8 @@ #import +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + NS_ASSUME_NONNULL_BEGIN /** @@ -61,3 +63,5 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 diff --git a/EarlGrey/Additions/UIWebView+GREYAdditions.m b/EarlGrey/Additions/UIWebView+GREYAdditions.m index 8750ecda7..36400f0aa 100644 --- a/EarlGrey/Additions/UIWebView+GREYAdditions.m +++ b/EarlGrey/Additions/UIWebView+GREYAdditions.m @@ -16,6 +16,8 @@ #import "Additions/UIWebView+GREYAdditions.h" +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + #import #include @@ -170,3 +172,5 @@ - (void)greyswizzled_setDelegate:(id)delegate { } @end + +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 diff --git a/EarlGrey/Delegate/GREYUIWebViewDelegate.h b/EarlGrey/Delegate/GREYUIWebViewDelegate.h index 0d22da51a..a6b4c7d2d 100644 --- a/EarlGrey/Delegate/GREYUIWebViewDelegate.h +++ b/EarlGrey/Delegate/GREYUIWebViewDelegate.h @@ -16,6 +16,8 @@ #import +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + #import "Delegate/GREYSurrogateDelegate.h" NS_ASSUME_NONNULL_BEGIN @@ -41,3 +43,5 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 diff --git a/EarlGrey/Delegate/GREYUIWebViewDelegate.m b/EarlGrey/Delegate/GREYUIWebViewDelegate.m index 60bde2e8a..293ecea06 100644 --- a/EarlGrey/Delegate/GREYUIWebViewDelegate.m +++ b/EarlGrey/Delegate/GREYUIWebViewDelegate.m @@ -16,6 +16,8 @@ #import "Delegate/GREYUIWebViewDelegate.h" +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + #import "Additions/UIWebView+GREYAdditions.h" #import "Synchronization/GREYAppStateTracker.h" @@ -148,3 +150,5 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { } @end + +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 diff --git a/EarlGrey/Event/GREYTouchInjector.m b/EarlGrey/Event/GREYTouchInjector.m index 978b7db35..5efc7c4fb 100644 --- a/EarlGrey/Event/GREYTouchInjector.m +++ b/EarlGrey/Event/GREYTouchInjector.m @@ -33,15 +33,17 @@ const NSTimeInterval kGREYTouchInjectionFrequency = 60.0; /** - * Maximum time to wait for UIWebView delegates to get called after the - * last touch (i.e. @c isLastTouch is @c YES). + * The time interval in seconds between each touch injection. */ -static const NSTimeInterval kGREYMaxIntervalForUIWebViewResponse = 2.0; +static const NSTimeInterval kGREYTouchInjectionInterval = 1.0 / kGREYTouchInjectionFrequency; +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 /** - * The time interval in seconds between each touch injection. + * Maximum time to wait for UIWebView delegates to get called after the + * last touch (i.e. @c isLastTouch is @c YES). */ -static const NSTimeInterval kGREYTouchInjectionInterval = 1.0 / kGREYTouchInjectionFrequency; +static const NSTimeInterval kGREYMaxIntervalForUIWebViewResponse = 2.0; +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 @interface GREYTouchInjector() @end @@ -282,6 +284,7 @@ - (void)grey_injectTouches:(GREYTouchInfo *)touchInfo { touchViewContainsWKWebView = YES; } if (touchInfo.phase == GREYTouchInfoPhaseTouchEnded) { +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 UIWebView *touchWebView = nil; if ([currentTouchView isKindOfClass:[UIWebView class]]) { touchWebView = (UIWebView *)currentTouchView; @@ -293,6 +296,7 @@ - (void)grey_injectTouches:(GREYTouchInfo *)touchInfo { } } [touchWebView grey_pendingInteractionForTime:kGREYMaxIntervalForUIWebViewResponse]; +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 } } } @catch (NSException *e) { diff --git a/EarlGrey/Synchronization/GREYUIWebViewIdlingResource.h b/EarlGrey/Synchronization/GREYUIWebViewIdlingResource.h index 4a695bdb5..d27ed9feb 100644 --- a/EarlGrey/Synchronization/GREYUIWebViewIdlingResource.h +++ b/EarlGrey/Synchronization/GREYUIWebViewIdlingResource.h @@ -16,6 +16,8 @@ #import +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + #import NS_ASSUME_NONNULL_BEGIN @@ -43,3 +45,5 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 diff --git a/EarlGrey/Synchronization/GREYUIWebViewIdlingResource.m b/EarlGrey/Synchronization/GREYUIWebViewIdlingResource.m index a594358e8..c5f66795c 100644 --- a/EarlGrey/Synchronization/GREYUIWebViewIdlingResource.m +++ b/EarlGrey/Synchronization/GREYUIWebViewIdlingResource.m @@ -16,6 +16,8 @@ #import "Synchronization/GREYUIWebViewIdlingResource.h" +#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0 + #import "Additions/UIWebView+GREYAdditions.h" #import "Assertion/GREYAssertionDefines.h" #import "Common/GREYDefines.h" @@ -209,3 +211,5 @@ - (NSString *)grey_evaluateAndAssertNoErrorsJavaScriptInString:(NSString *)jsStr } @end + +#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0