Skip to content

Commit 9738c99

Browse files
authored
Merge pull request #227 from pennlabs/development
Update 5.1.1
2 parents b10f8ab + 7819149 commit 9738c99

48 files changed

Lines changed: 1593 additions & 384 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//
2+
// AutomatedScreenshotUITests.swift
3+
// AutomatedScreenshotUITests
4+
//
5+
// Created by Dominic Holmes on 2/23/19.
6+
// Copyright © 2019 PennLabs. All rights reserved.
7+
//
8+
9+
import XCTest
10+
import SimulatorStatusMagic
11+
12+
class AutomatedScreenshotUITests: XCTestCase {
13+
14+
let waitTime: Double = 5
15+
16+
override func setUp() {
17+
// Put setup code here. This method is called before the invocation of each test method in the class.
18+
19+
// In UI tests it is usually best to stop immediately when a failure occurs.
20+
continueAfterFailure = false
21+
22+
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
23+
//XCUIApplication().launch()
24+
25+
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
26+
27+
// Fastlane Setup
28+
let app = XCUIApplication()
29+
app.launchArguments = ["FASTLANE"]
30+
setupSnapshot(app)
31+
app.launch()
32+
33+
SDStatusBarManager.sharedInstance().carrierName = "AirPennNet"
34+
SDStatusBarManager.sharedInstance().timeString = "9:41"
35+
SDStatusBarManager.sharedInstance().bluetoothState = .hidden
36+
SDStatusBarManager.sharedInstance().batteryDetailEnabled = false
37+
SDStatusBarManager.sharedInstance().enableOverrides()
38+
}
39+
40+
override func tearDown() {
41+
// Put teardown code here. This method is called after the invocation of each test method in the class.
42+
SDStatusBarManager.sharedInstance().disableOverrides()
43+
}
44+
45+
func testExample() {
46+
// Use recording to get started writing UI tests.
47+
// Use XCTAssert and related functions to verify your tests produce the correct results.
48+
49+
// Home
50+
let app = XCUIApplication()
51+
app.buttons["CONTINUE AS GUEST"].tap()
52+
wait(for: 10.0)
53+
snapshot("01Home", timeWaitingForIdle: waitTime)
54+
55+
// Dining
56+
let tabBarsQuery = app.tabBars
57+
tabBarsQuery.children(matching: .other).element(boundBy: 1).tap()
58+
snapshot("02Dining", waitForLoadingIndicator: true)
59+
60+
// GSR
61+
tabBarsQuery.otherElements["GSR - tab - 3 of 5"].tap()
62+
// GSR takes a while, run with fast wifi to avoid loading indicators on the screenshots
63+
wait(for: 10.0)
64+
snapshot("03GSR", timeWaitingForIdle: waitTime)
65+
66+
// Laundry
67+
tabBarsQuery.otherElements["Laundry - tab - 4 of 5"].tap()
68+
// Laundry takes a while, run with fast wifi to avoid loading indicators on the screenshots
69+
70+
wait(for: 10.0)
71+
snapshot("04Laundry", timeWaitingForIdle: waitTime)
72+
73+
// More
74+
tabBarsQuery.otherElements["More - tab - 5 of 5"].tap()
75+
snapshot("05More", waitForLoadingIndicator: true)
76+
}
77+
78+
}
79+
80+
extension XCTestCase {
81+
82+
func wait(for duration: TimeInterval) {
83+
let waitExpectation = expectation(description: "Waiting")
84+
85+
let when = DispatchTime.now() + duration
86+
DispatchQueue.main.asyncAfter(deadline: when) {
87+
waitExpectation.fulfill()
88+
}
89+
90+
// We use a buffer here to avoid flakiness with Timer on CI
91+
waitForExpectations(timeout: duration + 0.5)
92+
}
93+
}

FastlaneUIAutomation/SnapshotHelper.swift renamed to AutomatedScreenshotUITests/SnapshotHelper.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import XCTest
1818
var deviceLanguage = ""
1919
var locale = ""
2020

21-
func setupSnapshot(_ app: XCUIApplication) {
22-
Snapshot.setupSnapshot(app)
21+
func setupSnapshot(_ app: XCUIApplication, waitForAnimations: Bool = true) {
22+
Snapshot.setupSnapshot(app, waitForAnimations: waitForAnimations)
2323
}
2424

2525
func snapshot(_ name: String, waitForLoadingIndicator: Bool) {
@@ -63,14 +63,16 @@ enum SnapshotError: Error, CustomDebugStringConvertible {
6363
@objcMembers
6464
open class Snapshot: NSObject {
6565
static var app: XCUIApplication?
66+
static var waitForAnimations = true
6667
static var cacheDirectory: URL?
6768
static var screenshotsDirectory: URL? {
6869
return cacheDirectory?.appendingPathComponent("screenshots", isDirectory: true)
6970
}
7071

71-
open class func setupSnapshot(_ app: XCUIApplication) {
72+
open class func setupSnapshot(_ app: XCUIApplication, waitForAnimations: Bool = true) {
7273

7374
Snapshot.app = app
75+
Snapshot.waitForAnimations = waitForAnimations
7476

7577
do {
7678
let cacheDir = try pathPrefix()
@@ -153,7 +155,9 @@ open class Snapshot: NSObject {
153155

154156
print("snapshot: \(name)") // more information about this, check out https://docs.fastlane.tools/actions/snapshot/#how-does-it-work
155157

156-
sleep(1) // Waiting for the animation to be finished (kind of)
158+
if Snapshot.waitForAnimations {
159+
sleep(1) // Waiting for the animation to be finished (kind of)
160+
}
157161

158162
#if os(OSX)
159163
guard let app = self.app else {
@@ -291,4 +295,4 @@ private extension CGFloat {
291295

292296
// Please don't remove the lines below
293297
// They are used to detect outdated configuration files
294-
// SnapshotHelperVersion [1.14]
298+
// SnapshotHelperVersion [1.15]

FastlaneUIAutomation/FastlaneUIAutomation.swift

Lines changed: 0 additions & 57 deletions
This file was deleted.

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ GEM
1818
unf (>= 0.0.5, < 1.0.0)
1919
dotenv (2.7.2)
2020
emoji_regex (1.0.1)
21-
excon (0.62.0)
21+
excon (0.64.0)
2222
faraday (0.15.4)
2323
multipart-post (>= 1.2, < 3)
2424
faraday-cookie_jar (0.0.6)
@@ -27,7 +27,7 @@ GEM
2727
faraday_middleware (0.13.1)
2828
faraday (>= 0.7.4, < 1.0)
2929
fastimage (2.1.5)
30-
fastlane (2.119.0)
30+
fastlane (2.121.1)
3131
CFPropertyList (>= 2.3, < 4.0.0)
3232
addressable (>= 2.3, < 3.0.0)
3333
babosa (>= 1.0.2, < 2.0.0)
@@ -105,7 +105,7 @@ GEM
105105
multipart-post (2.0.0)
106106
nanaimo (0.2.6)
107107
naturally (2.2.0)
108-
os (1.0.0)
108+
os (1.0.1)
109109
plist (3.5.0)
110110
public_suffix (2.0.5)
111111
representable (3.0.4)
@@ -135,7 +135,7 @@ GEM
135135
uber (0.1.0)
136136
unf (0.1.4)
137137
unf_ext
138-
unf_ext (0.0.7.5)
138+
unf_ext (0.0.7.6)
139139
unicode-display_width (1.5.0)
140140
word_wrap (1.0.0)
141141
xcodeproj (1.8.2)

PLabs-Using-Fastlane.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Using Fastlane
2+
Docs: [Setup - fastlane docs](https://docs.fastlane.tools/getting-started/ios/setup/)
3+
Contact **Dominic Holmes** with questions. Email:
4+
* hello [at] dominic [dot] land
5+
6+
### Lanes
7+
I made 3 lanes (specified in `fastlane/Fastfile`)
8+
1. **screenshots**
9+
* this generates screenshots for all of the devices listed in `Snapfile`, by using the UITest target `AutomatedScreenshotUITests`
10+
2. **frame**
11+
* this lane frames all screenshots in the`fastlane/screenshots/en-US/` folder with the configuration listed under **Framing Screenshots**
12+
3. **capture_and_frame**
13+
* this lane is basically just lane 1 + lane 2. It captures all new screenshots and frames them — takes about 9 minutes on a fast Mac.
14+
15+
### Getting started
16+
1. Make sure you’re on the `fastlane` branch and you have pulled all changes
17+
2. Run `pod install` and make sure the app launches normally
18+
3. Install fastlane by running `sudo gem install fastlane -NV`
19+
4. Run `sudo bundle update` & put in your password to make sure everything’s good
20+
5. We’re ready! Run fastlane with `bundle exec fastlane [lane]` or `bundle exec fastlane` to have all lanes shown
21+
6. You’ll need to follow the instructions under **Framing Screenshots** to get that lane to work.
22+
23+
### Framing Screenshots
24+
The framing step will fail if you don’t have this set up.
25+
Complete instructions here: [Screenshots - fastlane docs](https://docs.fastlane.tools/getting-started/ios/screenshots/#put-your-screenshots-into-device-frames)
26+
27+
1. Install imagemagick through homebrew: `brew install libpng jpeg imagemagick`
28+
2. I have framing installed in the lane already, but you may need to update the screenshot tags.
29+
* For every screenshot that fastlane takes in, it gives it a tag like “01Dining”. Change these in `AutomaticScreenshotUITests.swift`.
30+
* That tag is then used in `Framefile.json` to set parameters for each frame (such as color).
31+
* It is also used in `/screenshots/en-US/keyword.strings` and `/screenshots/en-US/title.strings` to define the titles and subtitles to go on the frame.
32+
* Additionally, the frame uses `background.png`, although this can be customized and set individually in `Framefile.json`
33+
* You can specify the devices in `Snapfile`
34+
35+
### Conditional Code
36+
I added a way for us to check if Fastlane is currently taking screenshots. This is needed for things like Laundry preferences -- we want to return real preferences when testing the app and in production -- but NOT when running the Fastlane UI automation. Otherwise, we would have to start up each simulator and select the same user preferences.
37+
38+
You can check for conditional code anytime by calling `UIApplication.isRunningFastlaneTest`. This just checkings for a launch argument ("FASTLANE") I pass in at the beginning of the test.
39+
40+
### Perfect Status Bar
41+
Last thing — I also installed PerfectStatusBar. It sets the time to be 9:41 and the battery to be full. The pod is only installed on the UITests target, so it doesn’t affect normal testing.
42+
43+
### Errors
44+
1. Make sure fastlane is up to date (especially if there have been new iOS versions or Xcode versions) with `[sudo] bundle update fastlane`
45+
2. If you encounter: _[!] Could not determine installed iOS SDK version. Try running the _xcodebuild_ command manually to ensure it works._
46+
* Try running the following: `sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer`
47+
3. If some of the screenshots have loading indicators, then you need to give each screen more time :( This makes the test take longer. Just increase the `waitTime` variable at the top of `AutomatedScreenshotUITests.swift`. This variable is in seconds.
48+
49+
Generally — just follow whatever instructions Fastlane gives you, or google them if you’re unclear (they have great docs).
50+
51+
### Running Time
52+
The following is the running time of screenshot capture + framing, in seconds, on a MBP 2018.
53+
54+
```
55+
+------+---------------------+-------------+
56+
| fastlane summary |
57+
+------+---------------------+-------------+
58+
| Step | Action | Time (in s) |
59+
+------+---------------------+-------------+
60+
| 1 | update_fastlane | 6 |
61+
| 2 | default_platform | 0 |
62+
| 3 | capture_screenshots | 224 |
63+
| 4 | frameit | 282 |
64+
+------+---------------------+-------------+
65+
```

0 commit comments

Comments
 (0)