Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1010 from banjun/ios11-find-tableviewcell-fix
Fix waitForView cannot find UITableViewCell or label, and results in UITableView on iOS 11
  • Loading branch information
justinseanmartin committed Sep 26, 2017
2 parents ff857fd + 07eaeaf commit 98e75d6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Additions/UIAccessibilityElement-KIFAdditions.m
Expand Up @@ -18,6 +18,11 @@

MAKE_CATEGORIES_LOADABLE(UIAccessibilityElement_KIFAdditions)

@interface UIAccessibilityElement (KIFAdditions_Private)

- (id)tableViewCell; // UITableViewCellAccessibilityElement

@end

@implementation UIAccessibilityElement (KIFAdditions)

Expand All @@ -26,7 +31,9 @@ + (UIView *)viewContainingAccessibilityElement:(UIAccessibilityElement *)element
while (element && ![element isKindOfClass:[UIView class]]) {
// Sometimes accessibilityContainer will return a view that's too far up the view hierarchy
// UIAccessibilityElement instances will sometimes respond to view, so try to use that and then fall back to accessibilityContainer
id view = [element respondsToSelector:@selector(view)] ? [(id)element view] : nil;
id view = [element respondsToSelector:@selector(view)] ? [(id)element view]
: [element respondsToSelector:@selector(tableViewCell)] ? [(id)element tableViewCell]
: nil;

if (view) {
element = view;
Expand Down
14 changes: 14 additions & 0 deletions KIF Tests/TableViewTests.m
Expand Up @@ -83,6 +83,20 @@ - (void)testTappingRowUnderToolbarByLabel
[tester tapViewWithAccessibilityLabel:@"Cell 32"];
}

- (void)testWaitingRowByLabel
{
UIView *v = [tester waitForViewWithAccessibilityLabel:@"First Cell"];
XCTAssertTrue([v isKindOfClass:[UITableViewCell class]] || [v isKindOfClass:NSClassFromString(@"UITableViewLabel")], @"actual: %@", [v class]);
}

- (void)testWaitingRowByLabelAfterTapping
{
// for view lookup changes caused by tapping rows
[tester tapViewWithAccessibilityLabel:@"First Cell"];
UIView *v = [tester waitForViewWithAccessibilityLabel:@"First Cell"];
XCTAssertTrue([v isKindOfClass:[UITableViewCell class]] || [v isKindOfClass:NSClassFromString(@"UITableViewLabel")], @"actual: %@", [v class]);
}

- (void)testMoveRowDown
{
[tester tapViewWithAccessibilityLabel:@"Edit"];
Expand Down
14 changes: 14 additions & 0 deletions KIF Tests/TableViewTests_ViewTestActor.m
Expand Up @@ -83,6 +83,20 @@ - (void)testTappingRowUnderToolbarByLabel
[[viewTester usingLabel:@"Cell 32"] tap];
}

- (void)testWaitingRowByLabel
{
UIView *v = [[viewTester usingLabel:@"First Cell"] waitForView];
XCTAssertTrue([v isKindOfClass:[UITableViewCell class]] || [v isKindOfClass:NSClassFromString(@"UITableViewLabel")], @"actual: %@", [v class]);
}

- (void)testWaitingRowByLabelAfterTapping
{
// for view lookup changes caused by tapping rows
[[viewTester usingLabel:@"First Cell"] tap];
UIView *v = [[viewTester usingLabel:@"First Cell"] waitForView];
XCTAssertTrue([v isKindOfClass:[UITableViewCell class]] || [v isKindOfClass:NSClassFromString(@"UITableViewLabel")], @"actual: %@", [v class]);
}

- (void)testMoveRowDown
{
[[viewTester usingLabel:@"Edit"] tap];
Expand Down

0 comments on commit 98e75d6

Please sign in to comment.