Skip to content

Commit 75b8061

Browse files
Archit Pal Singh Sachdevafacebook-github-bot
authored andcommitted
Revert changes to visibility.
Summary: These changes to WDA broke visibility when keyboard is visible. Stuff which is visible is shown as not visible, and vice versa as well. Reviewed By: marekcirkos Differential Revision: D6484423 fbshipit-source-id: 3998e0bdee52fbfe7b302e0da53d822d18406bf0
1 parent 23091ef commit 75b8061

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99

1010
#import "XCUIElement+FBIsVisible.h"
1111

12+
#import "FBApplication.h"
1213
#import "FBConfiguration.h"
14+
#import "FBMathUtils.h"
1315
#import "FBXCodeCompatibility.h"
1416
#import "XCElementSnapshot+FBHelpers.h"
15-
#import "XCElementSnapshot+FBHitPoint.h"
16-
#import "XCTestPrivateSymbols.h"
1717
#import "XCUIElement+FBUtilities.h"
18+
#import "XCTestPrivateSymbols.h"
19+
#import <XCTest/XCUIDevice.h>
20+
#import "XCElementSnapshot+FBHitPoint.h"
1821

1922
@implementation XCUIElement (FBIsVisible)
2023

@@ -27,35 +30,35 @@ - (BOOL)fb_isVisible
2730

2831
@implementation XCElementSnapshot (FBIsVisible)
2932

30-
- (BOOL)fb_isVisibleInContainerWindow:(XCElementSnapshot *)window hierarchyIntersection:(nullable NSValue *)intersectionRectange appFrame:(CGRect)appFrame
31-
{
32-
CGRect currentRectangle = nil == intersectionRectange ? self.frame : [intersectionRectange CGRectValue];
33-
XCElementSnapshot *parent = self.parent;
34-
CGRect intersectionWithParent = CGRectIntersection(currentRectangle, parent.frame);
35-
if (CGRectIsEmpty(intersectionWithParent)) {
36-
return NO;
37-
}
38-
if (parent == window) {
39-
// Assume the element is visible if its root container is hittable and the frame is onscreen
40-
return CGRectContainsPoint(appFrame, self.fb_hitPoint);
41-
}
42-
return [parent fb_isVisibleInContainerWindow:window hierarchyIntersection:[NSValue valueWithCGRect:intersectionWithParent] appFrame:appFrame];
43-
}
44-
4533
- (BOOL)fb_isVisible
4634
{
47-
if (CGRectIsEmpty(self.frame)) {
35+
CGRect frame = self.frame;
36+
if (CGRectIsEmpty(frame)) {
4837
return NO;
4938
}
5039
if ([FBConfiguration shouldUseTestManagerForVisibilityDetection]) {
5140
return [(NSNumber *)[self fb_attributeValue:FB_XCAXAIsVisibleAttribute] boolValue];
5241
}
5342
CGRect appFrame = [self fb_rootElement].frame;
54-
XCElementSnapshot *containerWindow = [self fb_parentMatchingType:XCUIElementTypeWindow];
55-
if (nil != containerWindow) {
56-
return [self fb_isVisibleInContainerWindow:containerWindow hierarchyIntersection:nil appFrame:appFrame];
43+
CGSize screenSize = FBAdjustDimensionsForApplication(appFrame.size, (UIInterfaceOrientation)[XCUIDevice sharedDevice].orientation);
44+
CGRect screenFrame = CGRectMake(0, 0, screenSize.width, screenSize.height);
45+
if (!CGRectIntersectsRect(frame, screenFrame)) {
46+
return NO;
47+
}
48+
CGPoint midPoint = [self.suggestedHitpoints.lastObject CGPointValue];
49+
XCElementSnapshot *hitElement = [self hitTest:midPoint];
50+
if (self == hitElement || [self._allDescendants.copy containsObject:hitElement]) {
51+
return YES;
52+
}
53+
if (CGRectContainsPoint(appFrame, self.fb_hitPoint)) {
54+
return YES;
55+
}
56+
for (XCElementSnapshot *elementSnapshot in self.children.copy) {
57+
if (elementSnapshot.fb_isVisible) {
58+
return YES;
59+
}
5760
}
58-
return CGRectContainsPoint(appFrame, self.fb_hitPoint);
61+
return NO;
5962
}
6063

6164
@end

WebDriverAgentTests/IntegrationTests/FBElementVisibilityTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ - (void)testExtrasIconContent
5454
FBAssertWaitTillBecomesTrue(self.springboard.icons[@"Contacts"].fb_isVisible);
5555
NSArray *elements = self.springboard.pageIndicators.allElementsBoundByIndex;
5656
for (XCUIElement *element in elements) {
57-
XCTAssertTrue(element.fb_isVisible);
57+
XCTAssertFalse(element.fb_isVisible);
5858
}
5959
}
6060

WebDriverAgentTests/IntegrationTests/XCUIElementFBFindTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ - (void)setUp
321321

322322
- (void)testInvisibleDescendantWithXPathQuery
323323
{
324-
NSArray<XCUIElement *> *matchingSnapshots = [self.testedApplication fb_descendantsMatchingXPathQuery:@"//XCUIElementTypeWindow[@visible='false']" shouldReturnAfterFirstMatch:NO];
324+
NSArray<XCUIElement *> *matchingSnapshots = [self.testedApplication fb_descendantsMatchingXPathQuery:@"//XCUIElementTypePageIndicator[@visible='false']" shouldReturnAfterFirstMatch:NO];
325325
XCTAssertEqual(matchingSnapshots.count, 1);
326-
XCTAssertEqual(matchingSnapshots.lastObject.elementType, XCUIElementTypeWindow);
326+
XCTAssertEqual(matchingSnapshots.lastObject.elementType, XCUIElementTypePageIndicator);
327327
XCTAssertFalse(matchingSnapshots.lastObject.fb_isVisible);
328328
}
329329

0 commit comments

Comments
 (0)