Skip to content

Commit 3d51df2

Browse files
rohit-raokhandpur
authored andcommitted
UIWebView deprecation.
1 parent 7c7ecca commit 3d51df2

11 files changed

+80
-18
lines changed

EarlGrey/Action/GREYActions.m

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,12 @@ + (void)initialize {
240240
performBlock:^BOOL (id element, __strong NSError **errorOrNil) {
241241
NSString *textStr;
242242
if ([element grey_isWebAccessibilityElement]) {
243+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
243244
[GREYActions grey_setText:@"" onWebElement:element];
244245
return YES;
246+
#else
247+
return NO;
248+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
245249
} else if ([element isKindOfClass:gAccessibilityTextFieldElementClass]) {
246250
element = [element textField];
247251
} else if ([element respondsToSelector:@selector(text)]) {
@@ -298,8 +302,13 @@ + (void)initialize {
298302
// TODO: JS Errors should be propagated up.
299303
id<GREYMatcher> constraints =
300304
grey_allOf(grey_not(grey_systemAlertViewShown()),
301-
grey_anyOf(grey_kindOfClass([UIWebView class]),
302-
grey_kindOfClass([WKWebView class]), nil),
305+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
306+
grey_anyOf(
307+
grey_kindOfClass([UIWebView class]),
308+
grey_kindOfClass([WKWebView class]), nil),
309+
#else
310+
grey_kindOfClass([WKWebView class]),
311+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
303312
nil);
304313
BOOL (^performBlock)(id webView, __strong NSError **errorOrNil) = ^(
305314
id webView, __strong NSError **errorOrNil) {
@@ -320,7 +329,9 @@ + (void)initialize {
320329
*outResult = resultString;
321330
}
322331
return completionDone;
323-
} else if ([webView isKindOfClass:[UIWebView class]]) {
332+
}
333+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
334+
else if ([webView isKindOfClass:[UIWebView class]]) {
324335
UIWebView *uiWebView = webView;
325336
if (outResult) {
326337
*outResult = [uiWebView stringByEvaluatingJavaScriptFromString:js];
@@ -331,6 +342,7 @@ + (void)initialize {
331342
[[GREYUIThreadExecutor sharedInstance] drainForTime:0.5]; // Wait for actions to register.
332343
return YES;
333344
}
345+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
334346
return NO;
335347
};
336348
return [[GREYActionBlock alloc] initWithName:@"Execute JavaScript"
@@ -360,6 +372,7 @@ + (void)initialize {
360372

361373
#pragma mark - Private
362374

375+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
363376
/**
364377
* Sets WebView input text value.
365378
*
@@ -388,6 +401,7 @@ + (void)grey_setText:(NSString *)text onWebElement:(id)element {
388401
UIWebView *parentWebView = (UIWebView *)[element grey_viewContainingSelf];
389402
[parentWebView stringByEvaluatingJavaScriptFromString:jsForTitle];
390403
}
404+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
391405

392406
/**
393407
* Set the UITextField text value directly, bypassing the iOS keyboard.
@@ -410,7 +424,9 @@ + (void)grey_setText:(NSString *)text onWebElement:(id)element {
410424
constraints:constraints
411425
performBlock:^BOOL (id element, __strong NSError **errorOrNil) {
412426
if ([element grey_isWebAccessibilityElement]) {
427+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
413428
[GREYActions grey_setText:text onWebElement:element];
429+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
414430
} else {
415431
if ([element isKindOfClass:gAccessibilityTextFieldElementClass]) {
416432
element = [element textField];

EarlGrey/Action/GREYScrollAction.m

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@ - (instancetype)initWithDirection:(GREYDirection)direction
7575
NSString *name =
7676
[NSString stringWithFormat:@"Scroll %@ for %g", NSStringFromGREYDirection(direction), amount];
7777
self = [super initWithName:name
78-
constraints:grey_allOf(grey_anyOf(grey_kindOfClass([UIScrollView class]),
79-
grey_kindOfClass([UIWebView class]),
80-
nil),
81-
grey_not(grey_systemAlertViewShown()),
82-
nil)];
78+
constraints:grey_allOf(
79+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
80+
grey_anyOf(grey_kindOfClass([UIScrollView class]),
81+
grey_kindOfClass([UIWebView class]),
82+
nil),
83+
#else
84+
grey_kindOfClass([UIScrollView class]),
85+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
86+
grey_not(grey_systemAlertViewShown()),
87+
nil)];
8388
if (self) {
8489
_direction = direction;
8590
_amount = amount;
@@ -98,10 +103,13 @@ - (BOOL)perform:(id)element error:(__strong NSError **)errorOrNil {
98103
if (![self satisfiesConstraintsForElement:element error:errorOrNil]) {
99104
return NO;
100105
}
106+
107+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
101108
// To scroll UIWebView we must use the UIScrollView in its hierarchy and scroll it.
102109
if ([element isKindOfClass:[UIWebView class]]) {
103110
element = [(UIWebView *)element scrollView];
104111
}
112+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
105113

106114
CGFloat amountRemaining = _amount;
107115
BOOL success = YES;

EarlGrey/Action/GREYScrollToContentEdgeAction.m

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ - (instancetype)initWithEdge:(GREYContentEdge)edge startPointPercents:(CGPoint)s
5656
NSString *name =
5757
[NSString stringWithFormat:@"Scroll To %@ content edge", NSStringFromGREYContentEdge(edge)];
5858
self = [super initWithName:name
59-
constraints:grey_allOf(grey_anyOf(grey_kindOfClass([UIScrollView class]),
60-
grey_kindOfClass([UIWebView class]),
61-
nil),
62-
grey_not(grey_systemAlertViewShown()),
63-
nil)];
59+
constraints:grey_allOf(
60+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
61+
grey_anyOf(grey_kindOfClass([UIScrollView class]),
62+
grey_kindOfClass([UIWebView class]),
63+
nil),
64+
#else
65+
grey_kindOfClass([UIScrollView class]),
66+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
67+
grey_not(grey_systemAlertViewShown()),
68+
nil)];
6469
if (self) {
6570
_edge = edge;
6671
_startPointPercents = startPointPercents;
@@ -78,10 +83,12 @@ - (BOOL)perform:(UIScrollView *)element error:(__strong NSError **)errorOrNil {
7883
if (![self satisfiesConstraintsForElement:element error:errorOrNil]) {
7984
return NO;
8085
}
86+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
8187
// To scroll UIWebView we must use the UIScrollView in its hierarchy and scroll it.
8288
if ([element isKindOfClass:[UIWebView class]]) {
8389
element = [(UIWebView *)element scrollView];
8490
}
91+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
8592

8693
// Get the maximum scrollable amount in any direction and keep applying it until the edge
8794
// is reached.

EarlGrey/Additions/NSObject+GREYAdditions.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ - (NSString *)grey_recursiveDescription {
8787

8888
- (UIView *)grey_viewContainingSelf {
8989
if ([self grey_isWebAccessibilityElement]) {
90+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
9091
return [[self grey_containersAssignableFromClass:[UIWebView class]] firstObject];
92+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
93+
return nil;
9194
} else if ([self isKindOfClass:[UIView class]]) {
9295
return [self grey_container];
9396
} else if ([self respondsToSelector:@selector(accessibilityContainer)]) {

EarlGrey/Additions/UIWebView+GREYAdditions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#import <UIKit/UIKit.h>
1818

19+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
20+
1921
NS_ASSUME_NONNULL_BEGIN
2022

2123
/**
@@ -61,3 +63,5 @@ NS_ASSUME_NONNULL_BEGIN
6163
@end
6264

6365
NS_ASSUME_NONNULL_END
66+
67+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0

EarlGrey/Additions/UIWebView+GREYAdditions.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#import "Additions/UIWebView+GREYAdditions.h"
1818

19+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
20+
1921
#import <UIKit/UIKit.h>
2022
#include <objc/runtime.h>
2123

@@ -170,3 +172,5 @@ - (void)greyswizzled_setDelegate:(id<UIWebViewDelegate>)delegate {
170172
}
171173

172174
@end
175+
176+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0

EarlGrey/Delegate/GREYUIWebViewDelegate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#import <UIKit/UIKit.h>
1818

19+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
20+
1921
#import "Delegate/GREYSurrogateDelegate.h"
2022

2123
NS_ASSUME_NONNULL_BEGIN
@@ -41,3 +43,5 @@ NS_ASSUME_NONNULL_BEGIN
4143
@end
4244

4345
NS_ASSUME_NONNULL_END
46+
47+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0

EarlGrey/Delegate/GREYUIWebViewDelegate.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#import "Delegate/GREYUIWebViewDelegate.h"
1818

19+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
20+
1921
#import "Additions/UIWebView+GREYAdditions.h"
2022

2123
#import "Synchronization/GREYAppStateTracker.h"
@@ -148,3 +150,5 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
148150
}
149151

150152
@end
153+
154+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0

EarlGrey/Event/GREYTouchInjector.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@
3333
const NSTimeInterval kGREYTouchInjectionFrequency = 60.0;
3434

3535
/**
36-
* Maximum time to wait for UIWebView delegates to get called after the
37-
* last touch (i.e. @c isLastTouch is @c YES).
36+
* The time interval in seconds between each touch injection.
3837
*/
39-
static const NSTimeInterval kGREYMaxIntervalForUIWebViewResponse = 2.0;
38+
static const NSTimeInterval kGREYTouchInjectionInterval = 1.0 / kGREYTouchInjectionFrequency;
4039

40+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
4141
/**
42-
* The time interval in seconds between each touch injection.
42+
* Maximum time to wait for UIWebView delegates to get called after the
43+
* last touch (i.e. @c isLastTouch is @c YES).
4344
*/
44-
static const NSTimeInterval kGREYTouchInjectionInterval = 1.0 / kGREYTouchInjectionFrequency;
45+
static const NSTimeInterval kGREYMaxIntervalForUIWebViewResponse = 2.0;
46+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
4547

4648
@interface GREYTouchInjector() <GREYZeroToleranceTimerTarget>
4749
@end
@@ -282,6 +284,7 @@ - (void)grey_injectTouches:(GREYTouchInfo *)touchInfo {
282284
touchViewContainsWKWebView = YES;
283285
}
284286
if (touchInfo.phase == GREYTouchInfoPhaseTouchEnded) {
287+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
285288
UIWebView *touchWebView = nil;
286289
if ([currentTouchView isKindOfClass:[UIWebView class]]) {
287290
touchWebView = (UIWebView *)currentTouchView;
@@ -293,6 +296,7 @@ - (void)grey_injectTouches:(GREYTouchInfo *)touchInfo {
293296
}
294297
}
295298
[touchWebView grey_pendingInteractionForTime:kGREYMaxIntervalForUIWebViewResponse];
299+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
296300
}
297301
}
298302
} @catch (NSException *e) {

EarlGrey/Synchronization/GREYUIWebViewIdlingResource.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#import <UIKit/UIKit.h>
1818

19+
#if !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0
20+
1921
#import <EarlGrey/GREYIdlingResource.h>
2022

2123
NS_ASSUME_NONNULL_BEGIN
@@ -43,3 +45,5 @@ NS_ASSUME_NONNULL_BEGIN
4345
@end
4446

4547
NS_ASSUME_NONNULL_END
48+
49+
#endif // !defined(__IPHONE_12_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_12_0

0 commit comments

Comments
 (0)