Skip to content

Commit

Permalink
Merge branch 'ellipse-text'
Browse files Browse the repository at this point in the history
  • Loading branch information
joemasilotti committed Feb 18, 2016
2 parents 8bc0c4a + 25b27e7 commit 14e4e39
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 50 deletions.
22 changes: 20 additions & 2 deletions App/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="1mP-Cv-U3U">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="1mP-Cv-U3U">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -301,6 +301,24 @@
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="IIo-Vp-H6m" style="IBUITableViewCellStyleDefault" id="TUh-f4-5gi">
<rect key="frame" x="0.0" y="264" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="TUh-f4-5gi" id="wTY-vZ-BqQ">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="IIo-Vp-H6m">
<rect key="frame" x="15" y="0.0" width="570" height="43"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<string key="text">Adolph Blaine Charles David Earl Frederick Gerald Hubert Irvin John Kenneth Lloyd Martin Nero Oliver Paul Quincy Randolph Sherman Thomas Uncas Victor William Xerxes Yancy Wolfeschlegelsteinhausenbergerdorff, Senior</string>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
Expand Down
43 changes: 26 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ The included Xcode 7 project highlights working code with a simple Test Host. Th

## Contents

- [Basic Functionality](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#basic-functionality)
- [Testing if an element exists](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#testing-if-an-element-exists)
- [Waiting for an element to appear](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#waiting-for-an-element-to-appear)
- [Interacting with System Controls](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#interacting-with-system-controls)
- [Tapping buttons](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#tapping-buttons)
- [Typing text](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#typing-text)
- [Dismissing alerts](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#dismissing-alerts)
- [Handling system alerts](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#handling-system-alerts)
- [Sliding sliders](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#sliding-sliders)
- [Interacting with pickers](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#interacting-with-pickers)
- [Tapping links in web views](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#tapping-links-in-web-views)
- [Interactions](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#interactions)
- [Verifying the current controller's title](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#verifying-the-current-controllers-title)
- [Reordering table cells](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#reordering-table-cells)
- [Pull to refresh](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#pull-to-refresh)
- [Pushing and popping view controllers](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet#pushing-and-popping-view-controllers)
- [Basic Functionality](#basic-functionality)
- [Testing if an element exists](#testing-if-an-element-exists)
- [Testing if text with an ellipse exists](#testing-if-text-with-an-ellipse-exists)
- [Waiting for an element to appear](#waiting-for-an-element-to-appear)
- [Interacting with System Controls](#interacting-with-system-controls)
- [Tapping buttons](#tapping-buttons)
- [Typing text](#typing-text)
- [Dismissing alerts](#dismissing-alerts)
- [Handling system alerts](#handling-system-alerts)
- [Sliding sliders](#sliding-sliders)
- [Interacting with pickers](#interacting-with-pickers)
- [Tapping links in web views](#tapping-links-in-web-views)
- [Interactions](#interactions)
- [Verifying the current controller's title](#verifying-the-current-controllers-title)
- [Reordering table cells](#reordering-table-cells)
- [Pull to refresh](#pull-to-refresh)
- [Pushing and popping view controllers](#pushing-and-popping-view-controllers)

## Basic Functionality

Expand All @@ -34,6 +35,14 @@ XCTAssert(app.staticTexts["Welcome"].exists)
### Waiting for an element to appear
Set up an expectation to use with `XCTest`. The predicate will wait until the element's `-exist` property is true.

### Testing if text with an ellipse exists
A full text match will find an element even if the displayed text has an ellipse due to truncation.

````swift
let longNameCell = app.staticTexts["Adolph Blaine Charles David Earl Frederick Gerald Hubert Irvin John Kenneth Lloyd Martin Nero Oliver Paul Quincy Randolph Sherman Thomas Uncas Victor William Xerxes Yancy Wolfeschlegelsteinhausenbergerdorff, Senior"]
XCTAssert(longNameCell.exists) // displayed text is "Adolph Blaine Charles David Earl Freder..."
````

````swift
let goLabel = self.app.staticTexts["Go!"]
XCTAssertFalse(goLabel.exists)
Expand Down Expand Up @@ -161,4 +170,4 @@ Pop a view controller by tapping the back button in the navigation bar and asser
```swift
app.navigationBars.buttons.elementBoundByIndex(0).tap()
XCTAssert(app.navigationBars["Volley"].exists)
```
```
14 changes: 9 additions & 5 deletions UI Testing Cheat Sheet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
objects = {

/* Begin PBXBuildFile section */
8409D7A51BA4A45E00D49AAF /* ManageTeamViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8409D7A41BA4A45E00D49AAF /* ManageTeamViewController.swift */; settings = {ASSET_TAGS = (); }; };
8409D7A81BA4AF5E00D49AAF /* ScheduleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8409D7A71BA4AF5E00D49AAF /* ScheduleViewController.swift */; settings = {ASSET_TAGS = (); }; };
848766091B9E0DBB0031C38D /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848766081B9E0DBB0031C38D /* WebViewController.swift */; settings = {ASSET_TAGS = (); }; };
848DA01A1BA1D8F3006CC527 /* ManageRosterTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848DA0191BA1D8F3006CC527 /* ManageRosterTableViewController.swift */; settings = {ASSET_TAGS = (); }; };
8409D7A51BA4A45E00D49AAF /* ManageTeamViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8409D7A41BA4A45E00D49AAF /* ManageTeamViewController.swift */; };
8409D7A81BA4AF5E00D49AAF /* ScheduleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8409D7A71BA4AF5E00D49AAF /* ScheduleViewController.swift */; };
848766091B9E0DBB0031C38D /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848766081B9E0DBB0031C38D /* WebViewController.swift */; };
848DA01A1BA1D8F3006CC527 /* ManageRosterTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848DA0191BA1D8F3006CC527 /* ManageRosterTableViewController.swift */; };
849FEBEA1C7644EF008804F4 /* UITestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849FEBE91C7644EF008804F4 /* UITestCase.swift */; };
84E1B43B1B9DC34200453BB1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E1B43A1B9DC34200453BB1 /* AppDelegate.swift */; };
84E1B4401B9DC34200453BB1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84E1B43E1B9DC34200453BB1 /* Main.storyboard */; };
84E1B4451B9DC34200453BB1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84E1B4431B9DC34200453BB1 /* LaunchScreen.storyboard */; };
84E1B4501B9DC34200453BB1 /* UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E1B44F1B9DC34200453BB1 /* UITests.swift */; };
84E1B4871B9DC5CE00453BB1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 84E1B4861B9DC5CE00453BB1 /* Assets.xcassets */; settings = {ASSET_TAGS = (); }; };
84E1B4871B9DC5CE00453BB1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 84E1B4861B9DC5CE00453BB1 /* Assets.xcassets */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -33,6 +34,7 @@
8409D7A71BA4AF5E00D49AAF /* ScheduleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScheduleViewController.swift; sourceTree = "<group>"; };
848766081B9E0DBB0031C38D /* WebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = "<group>"; };
848DA0191BA1D8F3006CC527 /* ManageRosterTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManageRosterTableViewController.swift; sourceTree = "<group>"; };
849FEBE91C7644EF008804F4 /* UITestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITestCase.swift; sourceTree = "<group>"; };
84E1B4371B9DC34200453BB1 /* Volley.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Volley.app; sourceTree = BUILT_PRODUCTS_DIR; };
84E1B43A1B9DC34200453BB1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
84E1B43F1B9DC34200453BB1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -108,6 +110,7 @@
isa = PBXGroup;
children = (
84E1B4511B9DC34200453BB1 /* Info.plist */,
849FEBE91C7644EF008804F4 /* UITestCase.swift */,
84E1B44F1B9DC34200453BB1 /* UITests.swift */,
);
path = UITests;
Expand Down Expand Up @@ -227,6 +230,7 @@
buildActionMask = 2147483647;
files = (
84E1B4501B9DC34200453BB1 /* UITests.swift in Sources */,
849FEBEA1C7644EF008804F4 /* UITestCase.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
35 changes: 35 additions & 0 deletions UITests/UITestCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// UITestCase.swift
// UI Testing Cheat Sheet
//
// Created by Joe Masilotti on 2/18/16.
// Copyright © 2016 Masilotti.com. All rights reserved.
//
import XCTest

class UITestCase: XCTestCase {
let app = XCUIApplication()

override func setUp() {
super.setUp()
continueAfterFailure = false
app.launch()
}

override func tearDown() {
super.tearDown()
app.terminate()
}

func waitForElementToAppear(element: XCUIElement, file: String = __FILE__, line: UInt = __LINE__) {
let existsPredicate = NSPredicate(format: "exists == true")
expectationForPredicate(existsPredicate, evaluatedWithObject: element, handler: nil)

waitForExpectationsWithTimeout(5) { (error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after 5 seconds."
self.recordFailureWithDescription(message, inFile: file, atLine: line, expected: true)
}
}
}
}
34 changes: 8 additions & 26 deletions UITests/UITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,7 @@

import XCTest

class UITests: XCTestCase {
let app = XCUIApplication()

override func setUp() {
super.setUp()
continueAfterFailure = false
app.launch()
}

override func tearDown() {
super.tearDown()
app.terminate()
}

class UITests: UITestCase {
func testRefreshControl() {
app.staticTexts["Manage Roster"].tap()

Expand All @@ -43,6 +30,13 @@ class UITests: XCTestCase {
XCTAssert(label.exists)
}

func testElementWithEllipseExists() {
app.staticTexts["Manage Roster"].tap()

let longNameCell = app.staticTexts["Adolph Blaine Charles David Earl Frederick Gerald Hubert Irvin John Kenneth Lloyd Martin Nero Oliver Paul Quincy Randolph Sherman Thomas Uncas Victor William Xerxes Yancy Wolfeschlegelsteinhausenbergerdorff, Senior"]
XCTAssert(longNameCell.exists)
}

func testTappingAButton() {
app.buttons["More Info"].tap()
XCTAssert(app.navigationBars["Volleyball?"].exists)
Expand Down Expand Up @@ -156,16 +150,4 @@ class UITests: XCTestCase {
app.navigationBars.buttons.elementBoundByIndex(0).tap()
XCTAssert(app.navigationBars["Volley"].exists)
}

private func waitForElementToAppear(element: XCUIElement, file: String = __FILE__, line: UInt = __LINE__) {
let existsPredicate = NSPredicate(format: "exists == true")
expectationForPredicate(existsPredicate, evaluatedWithObject: element, handler: nil)

waitForExpectationsWithTimeout(5) { (error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after 5 seconds."
self.recordFailureWithDescription(message, inFile: file, atLine: line, expected: true)
}
}
}
}

0 comments on commit 14e4e39

Please sign in to comment.