snapshot 0.10.2 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +92 -333
- data/bin/snapshot +11 -28
- data/lib/assets/SnapfileTemplate +14 -33
- data/lib/assets/SnapshotHelper.swift +50 -0
- data/lib/snapshot.rb +23 -4
- data/lib/snapshot/collector.rb +72 -0
- data/lib/snapshot/dependency_checker.rb +14 -26
- data/lib/snapshot/detect_values.rb +33 -0
- data/lib/snapshot/error_handler.rb +31 -0
- data/lib/snapshot/latest_ios_version.rb +9 -4
- data/lib/snapshot/options.rb +98 -0
- data/lib/snapshot/page.html.erb +1 -1
- data/lib/snapshot/reports_generator.rb +33 -37
- data/lib/snapshot/reset_simulators.rb +4 -4
- data/lib/snapshot/runner.rb +59 -246
- data/lib/snapshot/screenshot_flatten.rb +2 -2
- data/lib/snapshot/screenshot_rotate.rb +7 -9
- data/lib/snapshot/setup.rb +33 -0
- data/lib/snapshot/test_command_generator.rb +93 -0
- data/lib/snapshot/version.rb +2 -1
- metadata +83 -13
- data/lib/assets/SnapshotHelper.js +0 -63
- data/lib/assets/snapshot.js +0 -9
- data/lib/snapshot/builder.rb +0 -85
- data/lib/snapshot/simulators.rb +0 -40
- data/lib/snapshot/snapfile_creator.rb +0 -21
- data/lib/snapshot/snapshot_config.rb +0 -233
- data/lib/snapshot/snapshot_file.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 381f0307803a2986ffa1180564d412ef8b01fc98
|
4
|
+
data.tar.gz: 32ea6efaca1869852332c6c604615b8e368a6d9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 625796bbb9c58d0c0f6d3d432420d41356b1e2911df7d86484c0763e6eb20ff82c84a586edde06d6117e37d31da898ae1bc349d6b7a67cb148b3e83d436de143
|
7
|
+
data.tar.gz: 74696231f888a4895b614fb621fa93e7912e506889f3c8ef4f721dbffe45d821642e7b6377d60489874556cee88a645125a272ffdf2f4c99300118fc9b4788d7
|
data/README.md
CHANGED
@@ -11,18 +11,18 @@
|
|
11
11
|
<a href="https://github.com/KrauseFx/frameit">frameit</a> •
|
12
12
|
<a href="https://github.com/KrauseFx/PEM">PEM</a> •
|
13
13
|
<a href="https://github.com/KrauseFx/sigh">sigh</a> •
|
14
|
-
<a href="https://github.com/KrauseFx/produce">produce</a> •
|
15
|
-
<a href="https://github.com/KrauseFx/cert">cert</a> •
|
16
|
-
<a href="https://github.com/KrauseFx/codes">codes</a> •
|
14
|
+
<a href="https://github.com/KrauseFx/produce">produce</a> •
|
15
|
+
<a href="https://github.com/KrauseFx/cert">cert</a> •
|
17
16
|
<a href="https://github.com/fastlane/spaceship">spaceship</a> •
|
18
17
|
<a href="https://github.com/fastlane/pilot">pilot</a> •
|
19
18
|
<a href="https://github.com/fastlane/boarding">boarding</a> •
|
20
|
-
<a href="https://github.com/fastlane/gym">gym</a>
|
19
|
+
<a href="https://github.com/fastlane/gym">gym</a> •
|
20
|
+
<a href="https://github.com/fastlane/scan">scan</a>
|
21
21
|
</p>
|
22
22
|
-------
|
23
23
|
|
24
24
|
<p align="center">
|
25
|
-
|
25
|
+
<img src="assets/snapshot.png" height="110">
|
26
26
|
</p>
|
27
27
|
|
28
28
|
snapshot
|
@@ -34,13 +34,6 @@ snapshot
|
|
34
34
|
|
35
35
|
###### Automate taking localized screenshots of your iOS app on every device
|
36
36
|
|
37
|
-
You have an iPhone app. You support 20 languages. You updated the design. You want to release the update to the App Store.
|
38
|
-
What's missing?
|
39
|
-
|
40
|
-
**New Screenshots**
|
41
|
-
|
42
|
-
You want them to look **perfect** and **gorgeous**. They should show the same screens on all devices in all languages.
|
43
|
-
|
44
37
|
You have to manually create 20 (languages) x 5 (devices) x 5 (screenshots) = **500 screenshots**.
|
45
38
|
|
46
39
|
It's hard to get everything right!
|
@@ -49,19 +42,21 @@ It's hard to get everything right!
|
|
49
42
|
- No loading indicators
|
50
43
|
- Same content / screens
|
51
44
|
- [Clean Status Bar](#use-a-clean-status-bar)
|
52
|
-
- Uploading screenshots ([
|
45
|
+
- Uploading screenshots ([`deliver`](https://github.com/KrauseFx/deliver) is your friend)
|
53
46
|
|
54
|
-
|
47
|
+
More information about [creating perfect screenshots](https://krausefx.com/blog/creating-perfect-app-store-screenshots-of-your-ios-app).
|
48
|
+
|
49
|
+
`snapshot` runs completely in the background - you can do something else, while your computer takes the screenshots for you.
|
55
50
|
|
56
51
|
Get in contact with the developer on Twitter: [@KrauseFx](https://twitter.com/KrauseFx)
|
57
52
|
|
58
|
-
### Note:
|
53
|
+
### Note: New `snapshot` with UI Tests in Xcode 7
|
59
54
|
|
60
|
-
Apple announced a new version of Xcode with support for UI Tests built in right into Xcode. This technology allows `snapshot` to be even better: Instead of dealing with UI Automation Javascript code, you
|
55
|
+
Apple announced a new version of Xcode with support for UI Tests built in right into Xcode. This technology allows `snapshot` to be even better: Instead of dealing with UI Automation Javascript code, you are now be able to write the screenshot code in Swift or Objective C allowing you to use debugging features like breakpoints.
|
61
56
|
|
62
|
-
|
57
|
+
As a result, `snapshot` was completely rewritten from ground up without changing its public API.
|
63
58
|
|
64
|
-
|
59
|
+
Please check out the [MigrationGuide to 1.0](/MigrationGuide.md) :+1:
|
65
60
|
|
66
61
|
**Why change to UI Tests?**
|
67
62
|
|
@@ -75,10 +70,11 @@ As a result, `snapshot` will be completely rewritten from ground up without chan
|
|
75
70
|
<p align="center">
|
76
71
|
<a href="#features">Features</a> •
|
77
72
|
<a href="#installation">Installation</a> •
|
78
|
-
<a href="#ui-
|
73
|
+
<a href="#ui-tests">UI Tests</a> •
|
79
74
|
<a href="#quick-start">Quick Start</a> •
|
80
75
|
<a href="#usage">Usage</a> •
|
81
76
|
<a href="#tips">Tips</a> •
|
77
|
+
<a href="#how-does-it-work">How?</a> •
|
82
78
|
<a href="#need-help">Need help?</a>
|
83
79
|
</p>
|
84
80
|
|
@@ -86,42 +82,33 @@ As a result, `snapshot` will be completely rewritten from ground up without chan
|
|
86
82
|
|
87
83
|
<h5 align="center"><code>snapshot</code> is part of <a href="https://fastlane.tools">fastlane</a>: connect all deployment tools into one streamlined workflow.</h5>
|
88
84
|
|
89
|
-
|
90
|
-
|
91
85
|
# Features
|
92
86
|
- Create hundreds of screenshots in multiple languages on all simulators
|
93
87
|
- Configure it once, store the configuration in git
|
94
88
|
- Do something else, while the computer takes the screenshots for you
|
95
89
|
- Integrates with [`fastlane`](https://fastlane.tools) and [`deliver`](https://github.com/KrauseFx/deliver)
|
96
90
|
- Generates a beautiful web page, which shows all screenshots on all devices. This is perfect to send to Q&A or the marketing team
|
97
|
-
-
|
98
|
-
- Support for advanced configuration, like preprocess macros or [prefilling of data](#prefilling)
|
91
|
+
- `snapshot` automatically waits for network requests to be finished before taking a screenshot (we don't want loading images in the App Store screenshots)
|
99
92
|
|
100
93
|
##### [Like this tool? Be the first to know about updates and new fastlane tools](https://tinyletter.com/krausefx)
|
101
94
|
|
102
|
-
After
|
95
|
+
After `snapshot` successfully created new screenshots, it will generate a beautiful HTML file to get a quick overview of all screens:
|
103
96
|
|
104
97
|
![assets/htmlPagePreviewFade.jpg](assets/htmlPagePreviewFade.jpg)
|
105
98
|
|
106
99
|
## Why?
|
107
|
-
|
100
|
+
|
101
|
+
This tool automatically switches the language and device type and runs UI Tests for every combination.
|
108
102
|
|
109
103
|
### Why should I automate this process?
|
104
|
+
|
110
105
|
- It takes **hours** to take screenshots
|
106
|
+
- You get a great overview of all your screens, running on all available simulators without the need to manually start it hundreds of times
|
107
|
+
- Easy verification for translators (without an iDevice) that translations do make sense in real App context
|
108
|
+
- Easy verification that localizations fit into labels on all screen dimensions
|
111
109
|
- It is an integration test: You can test for UI elements and other things inside your scripts
|
112
110
|
- Be so nice, and provide new screenshots with every App Store update. Your customers deserve it
|
113
111
|
- You realise, there is a spelling mistake in one of the screens? Well, just correct it and re-run the script
|
114
|
-
- You get a great overview of all your screens, running on all available simulators without the need to manually start it hundreds of times
|
115
|
-
- Easy verification that localizations fit into labels on all screen dimensions
|
116
|
-
- Easy verification for translators (without an iDevice) that translations do make sense in real App context
|
117
|
-
|
118
|
-
###Why use ```snapshot``` instead of....
|
119
|
-
|
120
|
-
I've been using many other solutions out there. Unfortunately none of them were perfect. The biggest issue was random timeouts of ```Instruments``` when starting the script. This problem is solved with ```snapshot```
|
121
|
-
|
122
|
-
- **UI Automation in Instruments**: Instruments can only run your app on one device in one language. You have to manually switch it.
|
123
|
-
- **[ui-screen-shooter](https://github.com/jonathanpenn/ui-screen-shooter)**: This is the best alternative out there right now. It's based on AppleScript, you can not update it properly and there are quite some hacks in there. ```snapshot``` uses a very similar technique - just in a clean and maintainable Ruby gem.
|
124
|
-
- **[Subliminal](https://github.com/inkling/Subliminal)**: A good approach to write the interaction code in Objective C. Unfortunately the project seems to be dead and doesn't work with the latest version of Xcode yet. Also, it requires modifications of your Xcode project and schemes, which might break some other things.
|
125
112
|
|
126
113
|
# Installation
|
127
114
|
|
@@ -133,234 +120,134 @@ Make sure, you have the latest version of the Xcode command line tools installed
|
|
133
120
|
|
134
121
|
xcode-select --install
|
135
122
|
|
136
|
-
# UI
|
123
|
+
# UI Tests
|
137
124
|
|
138
125
|
## Getting started
|
139
|
-
This project uses Apple's
|
126
|
+
This project uses Apple's newly announced UI Tests. I will not go into detail on how to write scripts.
|
140
127
|
|
141
128
|
Here a few links to get started:
|
142
129
|
|
143
|
-
- [
|
144
|
-
- [
|
145
|
-
- [
|
146
|
-
|
130
|
+
- [WWDC 2015 Introduction to UI Tests](https://developer.apple.com/videos/play/wwdc2015-406/)
|
131
|
+
- [A first look into UI Tests](http://www.mokacoding.com/blog/xcode-7-ui-testing/)
|
132
|
+
- [UI Testing in Xcode 7](http://masilotti.com/ui-testing-xcode-7/)
|
133
|
+
|
134
|
+
**Note**: Since there is no official way to trigger a screenshot from UI Tests, `snapshot` uses a workaround (described in [How Does It Work?](#how-does-it-work)) to trigger a screenshot. If you feel like this should be done right, please duplicate radar [23062925](https://openradar.appspot.com/radar?id=5056366381105152).
|
147
135
|
|
148
136
|
# Quick Start
|
149
137
|
|
150
|
-
-
|
151
|
-
-
|
152
|
-
-
|
153
|
-
-
|
138
|
+
- Create a new UI Test target in your Xcode project ([top part of this article](https://krausefx.com/blog/run-xcode-7-ui-tests-from-the-command-line))
|
139
|
+
- Run `snapshot init` in your project folder
|
140
|
+
- Add the ./SnapshotHelper.swift to your UI Test target (You can move the file anywhere you want)
|
141
|
+
- In your UI Test class, click the `Record` button on the bottom left and record your interaction
|
142
|
+
- Add `snapshot("01LoginScreen")` method calls inbetween your interactions to take new screenshots
|
143
|
+
- Add the following code to your `setUp()` method
|
144
|
+
|
145
|
+
```swift
|
146
|
+
let app = XCUIApplication()
|
147
|
+
setLanguage(app)
|
148
|
+
app.launch()
|
149
|
+
```
|
154
150
|
|
155
|
-
Here is a nice gif, that shows ```snapshot``` in action:
|
156
151
|
![assets/snapshot.gif](assets/snapshot.gif)
|
157
152
|
|
158
153
|
You can take a look at the example project to play around with it.
|
159
154
|
|
160
|
-
## Start ```snapshot```
|
161
|
-
|
162
|
-
- ```cd [your_project_folder]```
|
163
|
-
- ```snapshot```
|
164
|
-
|
165
|
-
Your screenshots will be stored in ```./screenshots/``` by default.
|
166
|
-
|
167
|
-
From now on, you can run ```snapshot``` to create new screenshots of your app.
|
168
|
-
|
169
|
-
|
170
155
|
# Usage
|
171
156
|
|
172
|
-
```
|
157
|
+
```sh
|
173
158
|
snapshot
|
174
159
|
```
|
175
160
|
|
176
|
-
|
177
|
-
```
|
178
|
-
snapshot --noclean
|
179
|
-
```
|
180
|
-
|
181
|
-
To only run tests (i.e. don't actually take any screenshots):
|
182
|
-
```
|
183
|
-
snapshot test
|
184
|
-
```
|
185
|
-
|
161
|
+
Your screenshots will be stored in the `./screenshots/` folder by default (or `./fastlane/screenshots` if you're using [fastlane](https://fastlane.tools))
|
186
162
|
|
187
163
|
If any error occurs while running the snapshot script on a device, that device will not have any screenshots, and `snapshot` will continue with the next device or language. To stop the flow after the first error, run
|
188
164
|
|
189
|
-
|
190
|
-
SNAPSHOT_BREAK_ON_FIRST_ERROR=1 snapshot
|
191
|
-
```
|
192
|
-
|
165
|
+
Also by default, `snapshot` will open the HTML after all is done. This can be skipped with the following command
|
193
166
|
|
194
|
-
By default, `snapshot` will re-install the app, to make sure it's in a clean state. In case you don't want this run
|
195
167
|
|
196
|
-
```
|
197
|
-
|
168
|
+
```sh
|
169
|
+
snapshot --stop_after_first_error --skip_open_summary
|
198
170
|
```
|
199
171
|
|
172
|
+
There are a lot of options available that define how to build your app, for example
|
200
173
|
|
201
|
-
|
174
|
+
```sh
|
175
|
+
snapshot --scheme "UITests" --configuration "Release" --sdk "iphonesimulator"
|
176
|
+
```
|
202
177
|
|
203
|
-
|
204
|
-
|
178
|
+
For a list for all available options run
|
179
|
+
|
180
|
+
```sh
|
181
|
+
snapshot --help
|
205
182
|
```
|
206
183
|
|
207
184
|
## Snapfile
|
208
185
|
|
209
|
-
|
186
|
+
All of the available options can also be stored in a configuration file called the `Snapfile`. Since most values will not change often for your project, it is recommended to store them there:
|
210
187
|
|
211
|
-
|
188
|
+
First make sure to have a `Snapfile` (you get it for free when running `snapshot init`)
|
212
189
|
|
213
|
-
|
214
|
-
Once you created your configuration, just run ```snapshot```.
|
190
|
+
The `Snapfile` can contain all the options that are also available on `snapshot --help`
|
215
191
|
|
216
|
-
The ```Snapfile``` may contain the following information (all are optional):
|
217
192
|
|
218
|
-
### Simulator Types
|
219
193
|
```ruby
|
194
|
+
scheme "UITests"
|
195
|
+
|
220
196
|
devices([
|
221
197
|
"iPhone 6",
|
222
198
|
"iPhone 6 Plus",
|
223
199
|
"iPhone 5",
|
224
|
-
"iPhone 4s"
|
225
|
-
"iPad Air"
|
200
|
+
"iPhone 4s"
|
226
201
|
])
|
227
|
-
```
|
228
|
-
|
229
|
-
### Languages
|
230
202
|
|
231
|
-
```ruby
|
232
203
|
languages([
|
233
204
|
"en-US",
|
234
205
|
"de-DE",
|
235
|
-
"es-ES"
|
236
|
-
["cmn-Hans", "cmn-Hans_CN"] # you can specify a locale if needed
|
206
|
+
"es-ES"
|
237
207
|
])
|
238
|
-
```
|
239
|
-
|
240
|
-
### JavaScript file
|
241
|
-
Usually ```snapshot``` automatically finds your JavaScript file. If that's not the case, you can pass the path
|
242
|
-
to your test file.
|
243
|
-
```ruby
|
244
|
-
js_file './path/file.js'
|
245
|
-
```
|
246
|
-
|
247
|
-
You can add a custom script for iPads: `./path/file-iPad.js` and it will automatically be used if found. Just append the `-iPad` to your existing file.
|
248
|
-
|
249
|
-
If you want to overwrite the JS path using environment variables, use `SNAPSHOT_JS_FILE`.
|
250
|
-
|
251
|
-
### Scheme
|
252
|
-
To not be asked which scheme to use, just set it like this:
|
253
|
-
```ruby
|
254
|
-
scheme "Name"
|
255
|
-
```
|
256
|
-
You can also use the environment variable ```SNAPSHOT_SCHEME```.
|
257
208
|
|
258
|
-
|
259
|
-
|
260
|
-
```ruby
|
261
|
-
screenshots_path './screenshots'
|
262
|
-
```
|
263
|
-
You can also use the environment variable ```SNAPSHOT_SCREENSHOTS_PATH```.
|
209
|
+
# The directory in which the screenshots should be stored
|
210
|
+
output_directory './screenshots'
|
264
211
|
|
265
|
-
|
266
|
-
By default, ```snapshot``` will look for your project in the current directory. If it is located somewhere else, pass your custom path:
|
267
|
-
```ruby
|
268
|
-
project_path "./my_project/Project.xcworkspace"
|
269
|
-
```
|
270
|
-
|
271
|
-
### iOS Version
|
272
|
-
I'll try to keep the script up to date. If you need to change the iOS version, you can do it like this:
|
273
|
-
|
274
|
-
```ruby
|
275
|
-
ios_version "9.0"
|
212
|
+
clear_previous_screenshots true
|
276
213
|
```
|
277
214
|
|
278
|
-
###
|
279
|
-
|
280
|
-
If you want to change the title of the generated HTML page, you can use:
|
281
|
-
|
282
|
-
```ruby
|
283
|
-
html_title 'Example'
|
284
|
-
```
|
285
|
-
|
286
|
-
### Custom Args for the build command
|
287
|
-
Use the ```custom_args``` directive to prepend custom statements to the build command.
|
288
|
-
|
289
|
-
Add a ```custom_build_args``` line to your ```Snapfile``` to add custom arguments to the build command.
|
290
|
-
|
291
|
-
Here is an example for adding a preprocessor macro `SNAPSHOT`:
|
292
|
-
|
293
|
-
```ruby
|
294
|
-
custom_build_args "GCC_PREPROCESSOR_DEFINITIONS='$(inherited) SNAPSHOT=1'"
|
295
|
-
```
|
215
|
+
### Completely reset all simulators
|
296
216
|
|
297
|
-
|
217
|
+
You can run this command in the terminal to delete and re-create all iOS simulators:
|
298
218
|
|
299
|
-
```objective-c
|
300
|
-
#ifdef SNAPSHOT
|
301
|
-
// Your Code here
|
302
|
-
#endif
|
303
219
|
```
|
304
|
-
|
305
|
-
### Custom Args for the run command
|
306
|
-
Add a ```custom_run_args``` line to your ```Snapfile``` to add custom arguments to the run command (i.e. the invocation of `instruments`. You can use this to set the value of a specific `NSUserDefaults` key, for example
|
307
|
-
|
308
|
-
```ruby
|
309
|
-
custom_run_args "-DidViewOnboarding YES"
|
220
|
+
snapshot reset_simulators
|
310
221
|
```
|
311
222
|
|
312
|
-
|
313
|
-
If for some reason, the default build command does not work for your project, you can pass your own build script. The script will be executed **once** before the tests are being run.
|
314
|
-
|
315
|
-
**Make sure** you are setting the output path to ```/tmp/snapshot``` or specify a custom ```build_dir``` on your ```Snapfile```.
|
316
|
-
|
317
|
-
```ruby
|
318
|
-
build_command "xcodebuild DSTROOT='/tmp/snapshot' OBJROOT='/tmp/snapshot' SYMROOT='/tmp/snapshot' ... "
|
319
|
-
```
|
223
|
+
**Warning**: This will delete **all** your simulators and replace by new ones! This is useful, if you run into weird `Instruments` problems when running `snapshot`.
|
320
224
|
|
321
|
-
|
322
|
-
Run your own script when ```snapshot``` switches the simulator type or the language.
|
323
|
-
This can be used to
|
324
|
-
- Logout the user
|
325
|
-
- Reset all user defaults
|
326
|
-
- Pre-fill the database
|
225
|
+
You can use the environment variable `SNAPSHOT_FORCE_DELETE` to stop asking for confirmation before deleting.
|
327
226
|
|
328
|
-
|
227
|
+
# How does it work?
|
329
228
|
|
330
|
-
|
331
|
-
```ruby
|
332
|
-
setup_for_device_change do |device, udid, language|
|
333
|
-
puts "Running #{language} on #{device}"
|
334
|
-
system("./populateDatabase.sh")
|
335
|
-
end
|
336
|
-
|
337
|
-
teardown_device do |language, device|
|
338
|
-
puts "Finished with #{language} on #{device}"
|
339
|
-
system("./cleanup.sh")
|
340
|
-
end
|
341
|
-
```
|
229
|
+
The easiest solution would be to just render the UIWindow into a file. That's not possible because UI Tests don't run on a main thread. So `snapshot` uses a different approach:
|
342
230
|
|
343
|
-
|
344
|
-
In case you want to skip this process, just add ```skip_alpha_removal``` to your ```Snapfile```.
|
231
|
+
When you run unit tests in Xcode, the reporter generates a plist file, documenting all events that occured during the tests ([More Information](http://michele.io/test-logs-in-xcode)). Additionally, Xcode generates screenshots before, duing and after each of these events. There seems to be no way to manually trigger a screenshot event. The screenshots and the plist files are stored in the DerivedData directory, which `snapshot` stores in a temporary folder.
|
345
232
|
|
346
|
-
|
233
|
+
When the user calls `snapshot(...)` in the UI Tests (Swift or Objective C) the script actually just does a swipe gesture outside of the screen bounds which doesn't make any sense. It has no effect to the application and is not something you would do in your tests. The goal was to find *some* event that a user would never trigger, so that we know it's from `snapshot`.
|
347
234
|
|
348
|
-
|
235
|
+
`snapshot` then iterates through all test events and check where we did this weird gesture. Once `snapshot` has all events triggered by `snapshot` it collects a ordered list of all the file names of the actual screenshots of the application.
|
349
236
|
|
350
|
-
|
351
|
-
clear_previous_screenshots
|
352
|
-
```
|
237
|
+
In the test output, the Swift `snapshot` function will print out something like this
|
353
238
|
|
354
|
-
|
239
|
+
snapshot: [some random text here]
|
355
240
|
|
356
|
-
|
241
|
+
`snapshot` finds all these entries using a regex. The number of `snapshot` outputs in the terminal and the number of `snapshot` events in the plist file should be the same. Knowing that, `snapshot` automatically matches these 2 lists to identify the name of each of these screenshots. They are then copied over to the output directory and separated by language and device.
|
357
242
|
|
358
|
-
|
243
|
+
2 thing have to be passed on from `snapshot` to the `xcodebuild` command line tool:
|
359
244
|
|
360
|
-
|
245
|
+
- The device type is passed via the `destination` parameter of the `xcodebuild` parameter
|
246
|
+
- The language is passed via a temporary file which is written by `snapshot` before running the tests and read by the UI Tests when launching the application
|
361
247
|
|
362
|
-
|
248
|
+
If you find a better way to do any of this, please submit an issue on GitHub or even a pull request :+1:
|
363
249
|
|
250
|
+
Also, feel free to duplicate radar [23062925](https://openradar.appspot.com/radar?id=5056366381105152).
|
364
251
|
|
365
252
|
# Tips
|
366
253
|
|
@@ -373,11 +260,11 @@ You can use the environment variable `SNAPSHOT_FORCE_DELETE` to stop asking for
|
|
373
260
|
- [`sigh`](https://github.com/KrauseFx/sigh): Because you would rather spend your time building stuff than fighting provisioning
|
374
261
|
- [`produce`](https://github.com/KrauseFx/produce): Create new iOS apps on iTunes Connect and Dev Portal using the command line
|
375
262
|
- [`cert`](https://github.com/KrauseFx/cert): Automatically create and maintain iOS code signing certificates
|
376
|
-
- [`codes`](https://github.com/KrauseFx/codes): Create promo codes for iOS Apps using the command line
|
377
263
|
- [`spaceship`](https://github.com/fastlane/spaceship): Ruby library to access the Apple Dev Center and iTunes Connect
|
378
264
|
- [`pilot`](https://github.com/fastlane/pilot): The best way to manage your TestFlight testers and builds from your terminal
|
379
265
|
- [`boarding`](https://github.com/fastlane/boarding): The easiest way to invite your TestFlight beta testers
|
380
266
|
- [`gym`](https://github.com/fastlane/gym): Building your iOS apps has never been easier
|
267
|
+
- [`scan`](https://github.com/fastlane/scan): The easiest way to run tests of your iOS and Mac app
|
381
268
|
|
382
269
|
##### [Like this tool? Be the first to know about updates and new fastlane tools](https://tinyletter.com/krausefx)
|
383
270
|
|
@@ -385,98 +272,6 @@ You can use the environment variable `SNAPSHOT_FORCE_DELETE` to stop asking for
|
|
385
272
|
|
386
273
|
If you want to add frames around the screenshots and even put a title on top, check out [frameit](https://github.com/fastlane/frameit).
|
387
274
|
|
388
|
-
## Prefilling
|
389
|
-
|
390
|
-
Usually you want to mock your screenshot data to show the same content for all screenshots.
|
391
|
-
|
392
|
-
There are 2 ways of doing this:
|
393
|
-
|
394
|
-
#### Preprocessor macro
|
395
|
-
Use the preprocessor macro `SNAPSHOT` to check if `snapshot` is currently running in your code. This enables you to add checks like this:
|
396
|
-
|
397
|
-
```objective-c
|
398
|
-
#ifdef SNAPSHOT
|
399
|
-
// Your Code here
|
400
|
-
#endif
|
401
|
-
```
|
402
|
-
|
403
|
-
Open your `Snapfile` and add `custom_build_args "GCC_PREPROCESSOR_DEFINITIONS='$(inherited) SNAPSHOT=1'"` to it.
|
404
|
-
|
405
|
-
#### By pre-filling data/documents in the bundle
|
406
|
-
|
407
|
-
As used by [MindNode](https://github.com/fastlane/examples/blob/master/MindNode/Snapfile) you can fill your bundle after building with demo data using your `Snapfile` to use it on run-time.
|
408
|
-
|
409
|
-
```ruby
|
410
|
-
example_files = './ExampleDocuments'
|
411
|
-
folder_name = "ExampleDocuments"
|
412
|
-
|
413
|
-
setup_for_device_change do |device, udid, language|
|
414
|
-
# This will make sure, all example documents are installed on the simulator
|
415
|
-
|
416
|
-
puts "Copying example files to .app"
|
417
|
-
|
418
|
-
app_path = "/tmp/snapshot/build/MindNode.app/"
|
419
|
-
|
420
|
-
FileUtils.mkdir_p(File.join(app_path, folder_name))
|
421
|
-
|
422
|
-
Dir.glob(File.join(example_files, '*.mindnode')).each do |example_path|
|
423
|
-
puts "Copying '#{example_path}' to .app container"
|
424
|
-
FileUtils.cp_r(example_path, File.join(app_path, folder_name)) rescue nil # in case the file already exists
|
425
|
-
end
|
426
|
-
end
|
427
|
-
```
|
428
|
-
|
429
|
-
This is simple Ruby that gets executed **after** the app was built and **before** it is installed on the simulator.
|
430
|
-
|
431
|
-
In your `Objective-C` code you can now load the documents from your bundle and copy them over to your `Documents` folder (if necessary).
|
432
|
-
|
433
|
-
```objective-c
|
434
|
-
#ifdef SNAPSHOT
|
435
|
-
/** This method will take care of copying over the example documents from the app's bundle into the `Documents` directory */
|
436
|
-
+ (void)load
|
437
|
-
{
|
438
|
-
static NSString *exampleFolderName = @"ExampleDocuments";
|
439
|
-
if ([[NSBundle mainBundle] pathForResource:exampleFolderName ofType:@""]) {
|
440
|
-
NSArray *filesToCopy = @[@"File1",
|
441
|
-
@"File2"];
|
442
|
-
NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
|
443
|
-
|
444
|
-
for (NSString *currentFile in filesToCopy) {
|
445
|
-
NSString *from = [[NSBundle mainBundle] pathForResource:currentFile ofType:@"filetype" inDirectory:exampleFolderName];
|
446
|
-
if (from && documents) {
|
447
|
-
NSError *error = nil;
|
448
|
-
NSString *resultingFileName = [NSString stringWithFormat:@"%@.filetype", currentFile];
|
449
|
-
[[NSFileManager defaultManager] copyItemAtPath:from
|
450
|
-
toPath:[documents stringByAppendingPathComponent:resultingFileName]
|
451
|
-
error:&error];
|
452
|
-
|
453
|
-
if (error) {
|
454
|
-
NSLog(@"Error copying the example MindNode file: %@", error);
|
455
|
-
}
|
456
|
-
}
|
457
|
-
}
|
458
|
-
}
|
459
|
-
}
|
460
|
-
|
461
|
-
```
|
462
|
-
|
463
|
-
## Run in Continuous Integration System
|
464
|
-
If you want to run `snapshot` on your `Jenkins` machine (or any other CI-system), you might run into an `authorization` popup coming up.
|
465
|
-
|
466
|
-
You can disable this dialog, running the following command:
|
467
|
-
```
|
468
|
-
security authorizationdb read system.privilege.taskport > /tmp/system.privilege.taskport.plist
|
469
|
-
/usr/libexec/PlistBuddy -c "Set :allow-root true" /tmp/system.privilege.taskport.plist
|
470
|
-
sudo security authorizationdb write system.privilege.taskport < /tmp/system.privilege.taskport.plist
|
471
|
-
```
|
472
|
-
I found this solution in the [`Subliminal` wiki](https://github.com/inkling/Subliminal/wiki/Continuous-Integration#faq).
|
473
|
-
|
474
|
-
## Specify a custom ```Snapfile```
|
475
|
-
|
476
|
-
snapshot --snapfile ./SpecialSnapfile
|
477
|
-
|
478
|
-
Be aware: The file will be executed from the current directory, not the location of the ```Snapfile```. That means: ```./screenshots``` will export the screenshots to the current directory of your terminal session.
|
479
|
-
|
480
275
|
## Available language codes
|
481
276
|
```ruby
|
482
277
|
ALL_LANGUAGES = ["da", "de-DE", "el", "en-AU", "en-CA", "en-GB", "en-US", "es-ES", "es-MX", "fi", "fr-CA", "fr-FR", "id", "it", "ja", "ko", "ms", "nl", "no", "pt-BR", "pt-PT", "ru", "sv", "th", "tr", "vi", "zh-Hans", "zh-Hant"]
|
@@ -485,64 +280,28 @@ ALL_LANGUAGES = ["da", "de-DE", "el", "en-AU", "en-CA", "en-GB", "en-US", "es-ES
|
|
485
280
|
## Use a clean status bar
|
486
281
|
You can use [SimulatorStatusMagic](https://github.com/shinydevelopment/SimulatorStatusMagic) to clean up the status bar.
|
487
282
|
|
488
|
-
|
489
|
-
Change syntax highlighting to *Ruby*.
|
490
|
-
|
491
|
-
## Instruments is not responding
|
492
|
-
Unfortunately ```Instruments``` sometimes decides, to not respond to anything. Which means, neither the ```Instruments``` application, nor the ```instruments``` command line work. Killing the process doesn't help.
|
493
|
-
|
494
|
-
The only way to fix this, is a restart of the Mac.
|
283
|
+
If you enable a clean status bar, you have to remove the `waitForLoadingIndicatorToDisappear` from the `SnapshotHelper.swift` code, as it doesn't detect when the loading indicator disappears.
|
495
284
|
|
496
|
-
##
|
497
|
-
|
498
|
-
|
499
|
-
### RubyMotion
|
500
|
-
|
501
|
-
Add to your ```Snapfile```:
|
502
|
-
|
503
|
-
```ruby
|
504
|
-
build_dir 'build/iPhoneSimulator-7.0-Development'
|
505
|
-
build_command 'rake build:simulator'
|
506
|
-
```
|
507
|
-
|
508
|
-
### Xamarin
|
509
|
-
|
510
|
-
Add to your ```Snapfile```:
|
511
|
-
|
512
|
-
```ruby
|
513
|
-
build_dir 'YourProject/bin/iPhoneSimulator'
|
514
|
-
build_command '/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool -v build "--configuration:Debug|iPhoneSimulator" YourProject.sln'
|
515
|
-
```
|
516
|
-
|
517
|
-
Unfortunately, Xamarin command line tool is only available for Business Edition licenses. For Indie licenses you can build the app using Xamarin Studio and use the ```--nobuild``` option.
|
518
|
-
|
519
|
-
### Skip building
|
520
|
-
|
521
|
-
If building via command-line doesn't work for your project or you don't want to build every time, you can run the tool with ```snapshot --nobuild``` to skip the build process and use a pre-built ```.app``` under your ```build_dir```.
|
285
|
+
## Editing the `Snapfile`
|
286
|
+
Change syntax highlighting to *Ruby*.
|
522
287
|
|
523
288
|
### Simulator doesn't launch the application
|
524
289
|
|
525
290
|
When the app dies directly after the application is launched there might be 2 problems
|
526
291
|
|
527
292
|
- The simulator is somehow in a broken state and you need to re-create it. You can use `snapshot reset_simulators` to reset all simulators (this will remove all installed apps)
|
528
|
-
-
|
529
|
-
|
530
|
-
### Snapshot throws an `Instruments Usage Error: Timed out waiting for device to boot: ...` error
|
531
|
-
|
532
|
-
This can happen when you launch `fastlane` or `snapshot` inside of a tool like `tmux`. Thankfully, Chris Johnsen wrote a fix to help us out, which you can find [here](https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard). Just follow the instructions at his repository, and launching the Simulator from `tmux` will work!
|
293
|
+
- A restart helps very often
|
533
294
|
|
534
|
-
## Determine language
|
295
|
+
## Determine language
|
535
296
|
|
536
|
-
To detect the currently used localization in your
|
297
|
+
To detect the currently used localization in your tests, use the following code:
|
537
298
|
|
538
299
|
```javascript
|
539
|
-
|
540
|
-
var language = result.stdout.substring(0, result.stdout.length - 1);
|
300
|
+
You can access the language using the `deviceLanguage` variable.
|
541
301
|
```
|
542
302
|
|
543
303
|
# Need help?
|
544
|
-
|
545
|
-
- I'm available for contract work - drop me an email: snapshot@krausefx.com
|
304
|
+
Please submit an issue on GitHub and provide information about your setup
|
546
305
|
|
547
306
|
# License
|
548
307
|
This project is licensed under the terms of the MIT license. See the LICENSE file.
|