snapshot 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fe56d81aa604485820010eadd10d664dc2e074b
4
- data.tar.gz: 0bf22a8fe033bf484bd05ea35524ce6ae549e157
3
+ metadata.gz: e7362693e9f1c922a699d79e0d24fc6f5ec122ff
4
+ data.tar.gz: ac6413d4502074b7ddd4fb140228cb97dc2cb7b3
5
5
  SHA512:
6
- metadata.gz: ba23be45519c941df5c1a9eeaf8376cda8afeb5a1caaefcc5faa9f6a7188c7be595ed3b55e57ab5cf16730e45b26bc1329f4d7aa9fc8c5083975476c61096957
7
- data.tar.gz: 70a024e17730c0ada7b14679b07de7bf3281257d776554a8c8509378b4edd922663c692b51054321f553aa8bb4e6c06864e507896d69d1dee34e2934bfb9ecde
6
+ metadata.gz: c0e83d4693307a5f46e9b7f120cc76c42ad7ee6aa7a3642db09b178c8bc756889b17565c93c2ce549311cd3a38b47ece61623bd9e17f9dea554d65c39190a6ff
7
+ data.tar.gz: 811d67b6f62e29423c84222269805b7e3e2effa328711933ab9447818aaa966fdd928be623199cf70542b966d132eda40e6d5ced86cdc439fbe38328aea3fb92
data/README.md CHANGED
@@ -225,6 +225,8 @@ js_file './path/file.js'
225
225
 
226
226
  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.
227
227
 
228
+ If you want to overwrite the JS path using environment variables, use `SNAPSHOT_JS_FILE`.
229
+
228
230
  ### Scheme
229
231
  To not be asked which scheme to use, just set it like this:
230
232
  ```ruby
@@ -252,15 +254,31 @@ I'll try to keep the script up to date. If you need to change the iOS version, y
252
254
  ios_version "9.0"
253
255
  ```
254
256
 
257
+ ### HTML Title
258
+
259
+ If you want to change the title of the generated HTML page, you can use:
260
+
261
+ ```ruby
262
+ html_title 'Example'
263
+ ```
264
+
255
265
  ### Custom Args for the build command
256
266
  Use the ```custom_args``` directive to prepend custom statements to the build command.
257
267
 
258
268
  Add a ```custom_build_args``` line to your ```Snapfile``` to add custom arguments to the build command.
259
269
 
260
- Here is an example for adding a preprocessor macro `SNAPSHOT` and a custom build setting `SNAPSHOT_ENABLE`.
270
+ Here is an example for adding a preprocessor macro `SNAPSHOT`:
261
271
 
262
272
  ```ruby
263
- custom_build_args "GCC_PREPROCESSOR_DEFINITIONS='$(inherited) SNAPSHOT=1' SNAPSHOT_ENABLE = YES"
273
+ custom_build_args "GCC_PREPROCESSOR_DEFINITIONS='$(inherited) SNAPSHOT=1'"
274
+ ```
275
+
276
+ In your Objective-C code, use the following code to detect the `snapshot` mode:
277
+
278
+ ```objective-c
279
+ #ifdef SNAPSHOT
280
+ // Your Code here
281
+ #endif
264
282
  ```
265
283
 
266
284
  ### Custom Args for the run command
@@ -286,6 +304,8 @@ This can be used to
286
304
  - Reset all user defaults
287
305
  - Pre-fill the database
288
306
 
307
+ The `setup_for_device_change` will be called **before** the app is installed on the simulator.
308
+
289
309
  To run a shell script, just use ```system('./script.sh')```.
290
310
  ```ruby
291
311
  setup_for_device_change do |device, udid, language|
@@ -299,8 +319,6 @@ teardown_device do |language, device|
299
319
  end
300
320
  ```
301
321
 
302
- If you want to run a script before each run of the app, it's enough to only implement the `setup_for_language_change` callback.
303
-
304
322
  ### Skip alpha removal from screenshots
305
323
  In case you want to skip this process, just add ```skip_alpha_removal``` to your ```Snapfile```.
306
324
 
@@ -345,6 +363,10 @@ You can use the environment variable `SNAPSHOT_FORCE_DELETE` to stop asking for
345
363
 
346
364
  ##### [Like this tool? Be the first to know about updates and new fastlane tools](https://tinyletter.com/krausefx)
347
365
 
366
+ ## Frame the screenshots
367
+
368
+ If you want to add frames around the screenshots and even put a title on top, check out [frameit](https://github.com/fastlane/frameit).
369
+
348
370
  ## Run in Continuous Integration
349
371
  If you want to run `snapshot` on your `Jenkins` machine (or any other CI-system), you might run into an `authorization` popup coming up.
350
372
 
@@ -405,6 +427,13 @@ Unfortunately, Xamarin command line tool is only available for Business Edition
405
427
 
406
428
  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```.
407
429
 
430
+ ### Simulator doesn't launch the application
431
+
432
+ When the app dies directly after the application is launched there might be 2 problems
433
+
434
+ - 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)
435
+ - You haven't enabled the correct architectures. Make sure you have the same architectures as in the example project of this repository.
436
+
408
437
  ## Determine language in UI Automation script
409
438
 
410
439
  To detect the currently used localization in your Javascript file, use the following code:
@@ -19,12 +19,12 @@ class SnapshotApplication
19
19
  program :help, 'Author', 'Felix Krause <snapshot@krausefx.com>'
20
20
  program :help, 'Website', 'https://fastlane.tools'
21
21
  program :help, 'GitHub', 'https://github.com/krausefx/snapshot'
22
- # program :help_formatter, :compact # https://github.com/commander-rb/commander/issues/12
22
+ program :help_formatter, :compact
23
23
 
24
24
  global_option '--snapfile PATH', String, 'Custom path for your Snapfile.'
25
25
  global_option '--nobuild', 'Skips the build process when running snapshot.'
26
26
  global_option '--noclean', 'Skips the clean process of the build command when running snapshot.'
27
- global_option('--verbose', 'Shows all output printed by Instruments.') { $verbose = true }
27
+ global_option('--verbose', 'Shows more output including all output printed by Instruments.') { $verbose = true }
28
28
 
29
29
  always_trace!
30
30
 
@@ -14,6 +14,11 @@ function wait_for_loading_indicator_to_be_finished()
14
14
  } catch (e) {}
15
15
  }
16
16
 
17
+ function isTablet()
18
+ {
19
+ return !(UIATarget.localTarget().model().match(/iPhone/))
20
+ }
21
+
17
22
  function captureLocalizedScreenshot(name) {
18
23
  wait_for_loading_indicator_to_be_finished();
19
24
 
@@ -38,7 +43,7 @@ function captureLocalizedScreenshot(name) {
38
43
  }
39
44
  else
40
45
  {
41
- model = "iOS-iPad";
46
+ model = "iPad";
42
47
  }
43
48
 
44
49
  var orientation = "portrait";
@@ -19,7 +19,7 @@ module Snapshot
19
19
  end
20
20
 
21
21
  def self.check_simulators
22
- Helper.log.debug "Found #{Simulators.available_devices.count} simulators."
22
+ Helper.log.debug "Found #{Simulators.available_devices.count} simulators." if $verbose
23
23
  if Simulators.available_devices.count < 1
24
24
  Helper.log.fatal '#############################################################'
25
25
  Helper.log.fatal "# You have to add new simulators using Xcode"
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>KrauseFx/snapshot</title>
4
+ <title><%= @title %></title>
5
5
  <meta charset="UTF-8">
6
6
  <style type="text/css">
7
7
  * {
@@ -83,10 +83,7 @@
83
83
  <% screens.each do |screen_path| %>
84
84
  <% next if screen_path.include?"_framed.png" %>
85
85
  <td>
86
- <% screen_size = FastImage.size(File.join(SnapshotConfig.shared_instance.screenshots_path, screen_path)) %>
87
- <% width = ((screen_size[0] / divide_size_by).round rescue 0) %>
88
- <% width = [width, max_width].min %>
89
- <% style = (width > 0 ? "width: #{width}px;" : '') %>
86
+ <% style = "width: 100%;" %>
90
87
  <% image_counter += 1 %>
91
88
  <a href="<%= screen_path %>" target="_blank" class="screenshotLink">
92
89
  <img class="screenshot"
@@ -136,7 +133,7 @@
136
133
  tmpImg.src = img.src;
137
134
  imageDisplay.style.height = 'auto';
138
135
  imageDisplay.style.width = 'auto';
139
- imageDisplay.style.paddingTop = '0px';
136
+ imageDisplay.style.paddingTop = '20px';
140
137
  if (window.innerHeight < tmpImg.height) {
141
138
  imageDisplay.style.height = document.documentElement.clientHeight+'px';
142
139
  } else if (window.innerWidth < tmpImg.width) {
@@ -182,7 +179,6 @@
182
179
  document.onkeypress = function(e) {
183
180
  e = e || window.event;
184
181
  var charCode = e.keyCode || e.which;
185
-
186
182
  switch(charCode) {
187
183
  case 27: // Esc
188
184
  overlay.style.display = "none";
@@ -4,8 +4,11 @@ require 'fastimage'
4
4
  module Snapshot
5
5
  class ReportsGenerator
6
6
  def generate
7
- screens_path = SnapshotConfig.shared_instance.screenshots_path
8
7
 
8
+ config = SnapshotConfig.shared_instance
9
+ screens_path = config.screenshots_path
10
+
11
+ @title = config.html_title
9
12
  @data = {}
10
13
 
11
14
  Dir["#{screens_path}/*"].sort.each do |language_path|
@@ -57,7 +60,8 @@ module Snapshot
57
60
  'iPhone6' => "iPhone 6",
58
61
  'iPhone5' => "iPhone 5",
59
62
  'iPhone4' => "iPhone 4",
60
- 'iOS-iPad' => "iPad"
63
+ 'iPad' => "iPad",
64
+ 'Mac' => "Mac"
61
65
  }
62
66
  end
63
67
  end
@@ -14,7 +14,10 @@ module Snapshot
14
14
  counter = 0
15
15
  errors = []
16
16
 
17
- FileUtils.rm_rf SnapshotConfig.shared_instance.screenshots_path if (SnapshotConfig.shared_instance.clear_previous_screenshots and take_snapshots)
17
+ if (SnapshotConfig.shared_instance.clear_previous_screenshots and take_snapshots)
18
+ path_to_clear = (SnapshotConfig.shared_instance.screenshots_path + "/*-*/*.png") # languages always contain a `-`
19
+ Dir[path_to_clear].each { |a| File.delete(a) } # no idea why rm_rf doesn't work
20
+ end
18
21
 
19
22
  SnapshotConfig.shared_instance.devices.each do |device|
20
23
  SnapshotConfig.shared_instance.languages.each do |language_item|
@@ -26,17 +29,20 @@ module Snapshot
26
29
  (language, locale) = language_item
27
30
  end
28
31
 
29
- reinstall_app(device, language, locale) unless ENV["SNAPSHOT_SKIP_UNINSTALL"]
30
32
 
31
33
  prepare_simulator(device, language)
34
+
35
+ reinstall_app(device, language, locale) unless ENV["SNAPSHOT_SKIP_UNINSTALL"]
32
36
 
33
37
  begin
34
38
  errors.concat(run_tests(device, language, locale))
35
- counter += copy_screenshots(language) if take_snapshots
36
39
  rescue => ex
37
40
  Helper.log.error(ex)
38
41
  end
39
42
 
43
+ # we also want to see the screenshots when something went wrong
44
+ counter += copy_screenshots(language) if take_snapshots
45
+
40
46
  teardown_simulator(device, language)
41
47
 
42
48
  break if errors.any? && ENV["SNAPSHOT_BREAK_ON_FIRST_ERROR"]
@@ -87,14 +93,15 @@ module Snapshot
87
93
  end
88
94
 
89
95
  def reinstall_app(device, language, locale)
96
+ Helper.log.info "Reinstalling app...".yellow unless $verbose
90
97
 
91
98
  app_identifier = ENV["SNAPSHOT_APP_IDENTIFIER"]
92
99
  app_identifier ||= @app_identifier
93
100
 
94
101
  def com(cmd)
95
- puts cmd.magenta
96
- result = `#{cmd}`
97
- puts result if result.to_s.length > 0
102
+ puts cmd.magenta if $verbose
103
+ result = `#{cmd} 2>&1` # to now show errors
104
+ puts result if (result.to_s.length > 0 and $verbose)
98
105
  end
99
106
 
100
107
  udid = udid_for_simulator(device)
@@ -161,7 +168,7 @@ module Snapshot
161
168
  end
162
169
 
163
170
  if retry_run
164
- Helper.log.error "Instruments tool failed again. Re-trying..."
171
+ Helper.log.error "Instruments tool failed again. Re-trying..." if $verbose
165
172
  sleep 2 # We need enough sleep... that's an instruments bug
166
173
  errors = run_tests(device, language, locale)
167
174
  end
@@ -173,16 +180,19 @@ module Snapshot
173
180
  # Determine the path to the actual app and not the WatchKit app
174
181
  build_dir = SnapshotConfig.shared_instance.build_dir || '/tmp/snapshot'
175
182
  Dir.glob("#{build_dir}/**/*.app/*.plist").each do |path|
176
- watchkit_enabled = `/usr/libexec/PlistBuddy -c 'Print WKWatchKitApp' '#{path}'`.strip
183
+ # `2>&1` to hide the error if it's not there: http://stackoverflow.com/a/4783536/445598
184
+ watchkit_enabled = `/usr/libexec/PlistBuddy -c 'Print WKWatchKitApp' '#{path}' 2>&1`.strip
177
185
  next if watchkit_enabled == 'true' # we don't care about WatchKit Apps
178
186
 
179
- app_identifier = `/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' '#{path}'`.strip
187
+ app_identifier = `/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' '#{path}' 2>&1`.strip
180
188
  if app_identifier and app_identifier.length > 0
181
189
  # This seems to be the valid Info.plist
182
190
  @app_identifier = app_identifier
183
191
  return File.expand_path("..", path) # the app
184
192
  end
185
193
  end
194
+
195
+ raise "Could not find app in '#{build_dir}'. Make sure you're following the README and set the build directory to the correct path.".red
186
196
  end
187
197
 
188
198
  def parse_test_line(line)
@@ -9,7 +9,7 @@ module Snapshot
9
9
 
10
10
  def flatten(path)
11
11
  Dir.glob([path, '/**/*.png'].join('/')).each do |file|
12
- Helper.log.info "Removing alpha channel from '#{file}'"
12
+ Helper.log.info "Removing alpha channel from '#{file}'" if $verbose
13
13
  `sips -s format bmp '#{file}' &> /dev/null ` # &> /dev/null because there is warning because of the extension
14
14
  `sips -s format png '#{file}'`
15
15
  end
@@ -11,7 +11,7 @@ module Snapshot
11
11
 
12
12
  def rotate(path)
13
13
  Dir.glob([path, '/**/*.png'].join('/')).each do |file|
14
- Helper.log.debug "Rotating '#{file}'"
14
+ Helper.log.debug "Rotating '#{file}'" if $verbose
15
15
 
16
16
  command = nil
17
17
  if file.end_with? "landscapeleft.png"
@@ -49,6 +49,8 @@ module Snapshot
49
49
  # @return (Hash) All the blocks, which are called on specific actions
50
50
  attr_accessor :blocks
51
51
 
52
+ attr_accessor :html_title
53
+
52
54
 
53
55
  # A shared singleton
54
56
  def self.shared_instance(path = nil)
@@ -62,7 +64,7 @@ module Snapshot
62
64
  set_defaults
63
65
 
64
66
  if File.exists?path
65
- Helper.log.info "Using '#{path}'".green
67
+ Helper.log.info "Using '#{path}'".green if $verbose
66
68
  self.snapshot_file = SnapshotFile.new(path, self)
67
69
 
68
70
  self.verify_devices
@@ -105,6 +107,9 @@ module Snapshot
105
107
  setup_for_language_change: empty,
106
108
  teardown_language: empty
107
109
  }
110
+
111
+ self.html_title = self.project_name || 'KrauseFx/snapshot'
112
+
108
113
  end
109
114
 
110
115
  # This has to be done after parsing the Snapfile (iOS version)
@@ -149,6 +154,8 @@ module Snapshot
149
154
 
150
155
  # The JavaScript UIAutomation file
151
156
  def js_file(ipad = false)
157
+ return ENV["SNAPSHOT_JS_FILE"] if ENV["SNAPSHOT_JS_FILE"]
158
+
152
159
  result = manual_js_file
153
160
 
154
161
  unless result
@@ -178,10 +185,11 @@ module Snapshot
178
185
  project_key = 'project'
179
186
  project_key = 'workspace' if project_path.end_with?'.xcworkspace'
180
187
  command = "xcodebuild -#{project_key} '#{project_path}' -list"
181
- Helper.log.debug command
188
+ Helper.log.debug command if $verbose
182
189
 
183
190
  schemes = `#{command}`.split("Schemes:").last.split("\n").each { |a| a.strip! }.delete_if { |a| a == '' }
184
- Helper.log.debug "Found available schemes: #{schemes}"
191
+
192
+ Helper.log.debug "Found available schemes: #{schemes}" if $verbose
185
193
 
186
194
  self.manual_scheme = schemes.first if schemes.count == 1
187
195
 
@@ -76,6 +76,9 @@ module Snapshot
76
76
  raise "#{method_sym} needs to have a block provided." unless block_given?
77
77
  Helper.log.warn("'setup_for_language_change' and 'teardown_language' are deprecated.".yellow) if [:setup_for_language_change, :teardown_language].include?method_sym
78
78
  @config.blocks[method_sym] = block
79
+ when :html_title
80
+ raise "html_title has to be an String".red unless value.kind_of?String
81
+ @config.html_title = value
79
82
  else
80
83
  Helper.log.error "Unknown method #{method_sym}"
81
84
  end
@@ -1,3 +1,3 @@
1
1
  module Snapshot
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Krause
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-03 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastimage
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.0
33
+ version: 0.7.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.0
40
+ version: 0.7.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement