Skip to content

Commit

Permalink
Temporarily use UIAutomation to check visibility in non-portrait orie…
Browse files Browse the repository at this point in the history
…ntations. (refs #135)

As a workaround for the failure of our visibility routine.
  • Loading branch information
Jeff Wear committed Apr 20, 2014
1 parent 682f721 commit 2fb5334
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Integration Tests/Tests/SLElementVisibilityTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,25 @@ - (void)setUpTestCaseWithSelector:(SEL)testSelector {

if (testSelector == @selector(testCanDetermineVisibilityOfWebAccessibilityElements)) {
SLAssertTrueWithTimeout(SLAskAppYesNo(webViewDidFinishLoad), 5.0, @"Webview did not load test HTML.");
} else if ((testSelector == @selector(testViewIsVisibleInPortrait)) ||
(testSelector == @selector(testViewIsVisibleInPortraitUpsideDown)) ||
(testSelector == @selector(testViewIsVisibleInLandscapeLeft)) ||
(testSelector == @selector(testViewIsVisibleInLandscapeRight))) {
SLAskApp(showTestView);
}
}

- (void)tearDownTestCaseWithSelector:(SEL)testCaseSelector {
if ((testCaseSelector == @selector(testViewIsVisibleInPortrait)) ||
(testCaseSelector == @selector(testViewIsVisibleInPortraitUpsideDown)) ||
(testCaseSelector == @selector(testViewIsVisibleInLandscapeLeft)) ||
(testCaseSelector == @selector(testViewIsVisibleInLandscapeRight))) {
[[SLDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
}

[super tearDownTestCaseWithSelector:testCaseSelector];
}

#pragma mark - Test isVisible for elements that are views

- (void)testViewIsNotVisibleIfItIsHidden {
Expand Down Expand Up @@ -225,6 +241,26 @@ - (void)testViewIsVisibleIfItsCenterIsCoveredByClearRegion {
SLAssertTrue([_testElement isVisible], @"Subliminal should say that the element is visible.");
}

- (void)testViewIsVisibleInPortrait {
[[SLDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
SLAssertTrue([UIAElement(_testElement) isVisible], @"Button should be visible");
}

- (void)testViewIsVisibleInPortraitUpsideDown {
[[SLDevice currentDevice] setOrientation:UIDeviceOrientationPortraitUpsideDown];
SLAssertTrue([UIAElement(_testElement) isVisible], @"Button should be visible");
}

- (void)testViewIsVisibleInLandscapeLeft {
[[SLDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft];
SLAssertTrue([UIAElement(_testElement) isVisible], @"Button should be visible");
}

- (void)testViewIsVisibleInLandscapeRight {
[[SLDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeRight];
SLAssertTrue([UIAElement(_testElement) isVisible], @"Button should be visible");
}

#pragma mark - Test isVisible for elements that are not views

- (void)testAccessibilityElementIsNotVisibleIfContainerIsHidden {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ + (NSString *)nibNameForTestCase:(SEL)testCase {
(testCase == @selector(testIsInvalidOrInvisibleDoesNotThrowIfElementIsInvalid)) ||
(testCase == @selector(testIsInvalidOrInvisibleReturnsYESIfElementIsInvalidOrInvisible))) {
nibName = @"SLElementVisibilityTestHidden";
} else if ((testCase == @selector(testViewIsVisibleInPortrait)) ||
(testCase == @selector(testViewIsVisibleInPortraitUpsideDown)) ||
(testCase == @selector(testViewIsVisibleInLandscapeLeft)) ||
(testCase == @selector(testViewIsVisibleInLandscapeRight))) {
nibName = @"SLElementVisibilityTestHidden";
}
return nibName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ - (BOOL)isValid {
they will be visible, and must depend on UIAutomation to confirm visibility.
*/
- (BOOL)isVisible {
// Temporarily use UIAutomation to check visibility if the device is in a non-portrait orientation
// to work around https://github.com/inkling/Subliminal/issues/135
if ([UIDevice currentDevice].orientation != UIDeviceOrientationPortrait) {
return [super isVisible];
}

__block BOOL isVisible = NO;
__block BOOL matchedObjectOfUnknownClass = NO;
// isVisible evaluates the current state, no waiting to resolve the element
Expand Down

0 comments on commit 2fb5334

Please sign in to comment.