Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Integration Tests/Tests/SLNavigationBarTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SLNavigationBarTests.m
// Subliminal
//
// Created by Jordan Zucker on 4/4/14.
// Copyright (c) 2014 Inkling. All rights reserved.
//

#import "SLIntegrationTest.h"

@interface SLNavigationBarTests : SLIntegrationTest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Test" please.

@end

@implementation SLNavigationBarTests

+ (NSString *)testCaseViewControllerClassName {
return @"SLNavigationBarTestsViewController";
}

- (void)testRightButtonBroadMatching {
SLButton *rightButton = [SLButton elementWithAccessibilityLabel:@"Right"];
SLAssertTrue([UIAElement(rightButton) isValidAndVisible], @"Right button didn't appear");

[UIAElement(rightButton) tap];
}

- (void)testRightButtonWithNewMethod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like "AsChildElement" will hold up better than "WithNewMethod" over time.

{
SLNavigationBar *navBar = [SLNavigationBar elementWithAccessibilityIdentifier:@"NavigationBar"];
SLLogAsync(@"navBar is %@", navBar);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use SLLog--it's ok to block the thread because tests run in the background, and it would help debugging to have the log appear "in order" if a subsequent assertion happened to fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm not sure what the log messages are meant to show here?

SLAssertTrue([UIAElement(navBar) isValidAndVisible], @"Couldn't find nav bar matching specifications");
SLButton *rightButton = [navBar childElementMatching:[SLButton elementWithAccessibilityLabel:@"Right"]];
SLAssertTrue([UIAElement(rightButton) isValidAndVisible], @"Couldn't find right button bar");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that there's a way we could test that we've matched the nav bar button in particular? Like maybe there's another button labeled "Right", but the nav bar button has a value that says "nav bar right button".


[UIAElement(rightButton) tap];
}

- (void)testTitleLabel
{
SLNavigationBar *navBar = [SLNavigationBar elementWithAccessibilityIdentifier:@"NavigationBar"];
SLLogAsync(@"navBar is %@", navBar);
SLAssertTrue([UIAElement(navBar) isValidAndVisible], @"Couldn't find nav bar matching specifications");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract this assertion into its own test case, please? It would be nice to know whether or not SLNavigationBar worked independently of whether it could be used to match child elements.

SLElement *title = [navBar childElementMatching:[SLElement elementWithAccessibilityLabel:@"Testing" value:nil traits:UIAccessibilityTraitStaticText]];
SLAssertTrue([UIAElement(title) isValidAndVisible], @"title isn't valid and visible");
SLLogAsync(@"title is %@", title.label);
SLAssertTrue([UIAElement(title.label) isEqualToString:@"Testing"], @"title doesn't match expected string");
}

@end
67 changes: 67 additions & 0 deletions Integration Tests/Tests/SLNavigationBarTestsViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// SLNavigationBarTestsViewController.m
// Subliminal
//
// Created by Jordan Zucker on 4/4/14.
// Copyright (c) 2014 Inkling. All rights reserved.
//

#import "SLTestCaseViewController.h"

#import <Subliminal/SLTestController+AppHooks.h>

@interface SLNavigationBarTestsViewController : SLTestCaseViewController

@end

@interface SLNavigationBarTestsViewController ()
// Connect IBOutlets here.
@property (nonatomic, weak) IBOutlet UINavigationBar *navBar;
@end

@implementation SLNavigationBarTestsViewController

+ (NSString *)nibNameForTestCase:(SEL)testCase {
return @"SLNavigationBarTestsViewController";
}

- (void)viewDidLoad {
[super viewDidLoad];

// Do any additional setup after loading the view from its nib.
// Test case specific configuration is best done using app hooks
// triggered from -[SLNavigationBarTests setUpTestCaseWithSelector:].
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Right" style:UIBarButtonItemStylePlain target:self action:@selector(tapRightButton:)];
rightButton.accessibilityLabel = @"Right";
_navBar.topItem.rightBarButtonItem = rightButton;

_navBar.accessibilityIdentifier = @"NavigationBar";

_navBar.topItem.title = @"Testing";
_navBar.topItem.title.isAccessibilityElement = YES;
_navBar.topItem.title.accessibilityLabel = _navBar.topItem.title;
}

- (IBAction)tapRightButton:(id)sender
{
NSLog(@"hey");
}

- (instancetype)initWithTestCaseWithSelector:(SEL)testCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you delete the template comments/code in the file please if unused?

self = [super initWithTestCaseWithSelector:testCase];
if (self) {
// Register for app hooks, e.g.
// [[SLTestController sharedTestController] registerTarget:<#(id)#> forAction:<#(SEL)#>];
}
return self;
}

// Deregister for app hooks, if any
//- (void)dealloc {
// [[SLTestController sharedTestController] deregisterTarget:self];
//}

//#pragma mark - App hooks
// Put any app hooks below here

@end
33 changes: 33 additions & 0 deletions Integration Tests/Tests/SLNavigationBarTestsViewController.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="5053" systemVersion="13C64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment defaultVersion="1296" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="SLNavigationBarTestsViewController">
<connections>
<outlet property="navBar" destination="XyI-Mm-oWe" id="HZw-AF-YMG"/>
<outlet property="view" destination="1" id="3"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="1">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<navigationBar contentMode="scaleToFill" barStyle="black" translucent="NO" id="XyI-Mm-oWe">
<rect key="frame" x="0.0" y="231" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<items>
<navigationItem title="Title" id="sQ4-XS-fGb"/>
</items>
</navigationBar>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
</view>
</objects>
</document>
144 changes: 144 additions & 0 deletions Integration Tests/Tests/SLTableViewCellChildElementsTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
//
// SLTableViewCellChildElementsTest.m
// Subliminal
//
// Created by Jordan Zucker on 3/20/14.
// Copyright (c) 2014 Inkling. All rights reserved.
//

#import "SLIntegrationTest.h"

@interface SLTableViewCellChildElementsTest : SLIntegrationTest

@end

@implementation SLTableViewCellChildElementsTest

+ (NSString *)testCaseViewControllerClassName {
return @"SLTableViewCellChildElementsTestViewController";
}

- (void)testTapBroadMatchingTableViewCellButton {
[[SLDevice currentDevice] captureScreenshotWithFilename:@"start"];

SLButton *favoriteButton = [SLButton elementWithAccessibilityLabel:@"Favorite"];
SLAssertTrue([UIAElement(favoriteButton.value) isEqualToString:@"off"], @"favorite button is not originally off");
SLAssertTrue([UIAElement(favoriteButton) isValidAndVisible], @"Favorite button is not valid and visible");
[favoriteButton captureScreenshotWithFilename:@"fb: starting"];

[UIAElement(favoriteButton) tap];

[self wait:1];
[[SLDevice currentDevice] captureScreenshotWithFilename:@"after tap"];
[favoriteButton captureScreenshotWithFilename:@"fb: after first tap"];

SLAssertTrue([UIAElement(favoriteButton) isValidAndVisible], @"favorite button is not valid and visible after first time tapping");
SLAssertTrue([UIAElement(favoriteButton.value) isEqualToString:@"on"], @"Favorite button does not has ax value of on");
[UIAElement(favoriteButton) tap];

[self wait:1];

SLAssertTrue([UIAElement(favoriteButton.value) isEqualToString:@"off"], @"favorite button is not off at end of test");
SLAssertTrue([UIAElement(favoriteButton) isValidAndVisible], @"Favorite button is not valid and visible");
[favoriteButton captureScreenshotWithFilename:@"fb: ending"];


[[SLDevice currentDevice] captureScreenshotWithFilename:@"end of test"];
}

- (void)testMatchingTableViewCellByMatchingTableViewCellAndTableView
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like maybe this test case was designed to debug the child-element method? Like it's verifying the accessibility hierarchy more than testing a particular Subliminal API?

{
[[SLDevice currentDevice] captureScreenshotWithFilename:@"start"];
SLButton *favoriteButton = [SLButton elementMatching:^BOOL(NSObject *obj) {

if ([obj.accessibilityLabel isEqualToString:@"Favorite"]) {

id accessibilityParent = [obj slAccessibilityParent];

while (accessibilityParent && ![[accessibilityParent accessibilityLabel] isEqualToString:@"Cell 2"]) {

accessibilityParent = [accessibilityParent slAccessibilityParent];

}


id doubleAccessibilityParent = [accessibilityParent slAccessibilityParent];

while (doubleAccessibilityParent && ![doubleAccessibilityParent isKindOfClass:[UITableView class]]) {
doubleAccessibilityParent = [doubleAccessibilityParent slAccessibilityParent];
}

if (doubleAccessibilityParent) {
return YES;
}
else {
return NO;
}


}

return NO;

} withDescription:@"searching for favoritebutton"];

SLAssertTrue([UIAElement(favoriteButton.value) isEqualToString:@"off"], @"favorite button is not originally off");
SLAssertTrue([UIAElement(favoriteButton) isValidAndVisible], @"Favorite button is not valid and visible");
[favoriteButton captureScreenshotWithFilename:@"fb: starting"];

[UIAElement(favoriteButton) tap];

[self wait:1];
[[SLDevice currentDevice] captureScreenshotWithFilename:@"after tap"];
[favoriteButton captureScreenshotWithFilename:@"fb: after first tap"];

SLAssertTrue([UIAElement(favoriteButton) isValidAndVisible], @"favorite button is not valid and visible after first time tapping");
SLAssertTrue([UIAElement(favoriteButton.value) isEqualToString:@"on"], @"Favorite button does not has ax value of on");
[UIAElement(favoriteButton) tap];

[self wait:1];

SLAssertTrue([UIAElement(favoriteButton.value) isEqualToString:@"off"], @"favorite button is not off at end of test");
SLAssertTrue([UIAElement(favoriteButton) isValidAndVisible], @"Favorite button is not valid and visible");
[favoriteButton captureScreenshotWithFilename:@"fb: ending"];


[[SLDevice currentDevice] captureScreenshotWithFilename:@"end of test"];
}

- (void)testMatchingTableViewCellWithAccessibilityContainerMethod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "AsChildElement" is slightly more to-the-point.

{
[[SLDevice currentDevice] captureScreenshotWithFilename:@"start"];
SLTableViewCell *tableViewCell = [SLTableViewCell elementWithAccessibilityLabel:@"Cell 2"];
SLAssertTrue([UIAElement(tableViewCell) isValidAndVisible], @"table view cell matching cell 2 not valid and visible");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract this into a test case that SLTableViewCell works (independent of being used to construct child elements)?

SLButton *favoriteButton = [tableViewCell childElementMatching:[SLButton elementWithAccessibilityLabel:@"Favorite"]];

SLLogAsync(@"favoriteButton.value is %@", UIAElement(favoriteButton.value));

SLAssertTrue([UIAElement(favoriteButton.value) isEqualToString:@"off"], @"favorite button is not originally off");
SLAssertTrue([UIAElement(favoriteButton) isValidAndVisible], @"Favorite button is not valid and visible");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that there's a way we could test that we've matched the child of Cell 2 in particular? Like maybe each button has the same label but a cell-specific value ("Favorite 2", "Favorite 3", etc.).

[favoriteButton captureScreenshotWithFilename:@"fb: starting"];

[UIAElement(favoriteButton) tap];

[self wait:1];
[[SLDevice currentDevice] captureScreenshotWithFilename:@"after tap"];
[favoriteButton captureScreenshotWithFilename:@"fb: after first tap"];

[UIAElement(favoriteButton) isValidAndVisible];

SLAssertTrue([UIAElement(favoriteButton) isValidAndVisible], @"favorite button is not valid and visible after first time tapping");
SLAssertTrue([UIAElement(favoriteButton.value) isEqualToString:@"on"], @"Favorite button does not has ax value of on");
[UIAElement(favoriteButton) tap];

[self wait:1];

SLAssertTrue([UIAElement(favoriteButton.value) isEqualToString:@"off"], @"favorite button is not off at end of test");
SLAssertTrue([UIAElement(favoriteButton) isValidAndVisible], @"Favorite button is not valid and visible");
[favoriteButton captureScreenshotWithFilename:@"fb: ending"];


[[SLDevice currentDevice] captureScreenshotWithFilename:@"end of test"];
}

@end
Loading