lineup 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9c1277997e4c9f112ae3a09071a8a54ff47ea66
4
- data.tar.gz: 91015501ca8250b834c1473b121546a632f0d0b5
3
+ metadata.gz: 2d9515daedfb284a4e7aedb97d26ba93c78c822b
4
+ data.tar.gz: ffc0a25a56227a60011a2c1af03ba1cd4907bc2d
5
5
  SHA512:
6
- metadata.gz: 20cf39c0e193c0c1672fc717bdb8c326b8bce914835c566c3e77545c575c083e4c6685c958040853d63cb0c411cccbc2d5dd1da36c2bcfa17225e2cac6d46929
7
- data.tar.gz: fc4a0df84e6779908648a52bd25e512c6ffe3d3c660079a61f9c28886cfbfbbdee0a949f08e0ba7227a5737f608efdb656f8007d99e8e4daefc6a4282c8579e5
6
+ metadata.gz: 6e8b81e43e1201d21b61b796d2578c40cb4cea33f2e051fad98b339caea33191b3d763b7c253b0536a97f1146973e8320657ace203efec29dbd95386c8a5677f
7
+ data.tar.gz: d0ed7dc370932a0f1e80eab7e3d0b907103ee813446e2d1bd1cfc7b4d09ec6b4a551ea4eb1c9329354ea5e58b610ed5aefd2789b22fa59c3a31b727d9800d2f3
data/bin/lineup CHANGED
@@ -1,7 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'lineup'
3
+ require '../lib/lineup'
4
4
 
5
- lineup = Lineup::Screenshot.new('otto.de')
6
- lineup.use_phantomjs false
5
+ puts("This is an example. And a benchmark.")
6
+
7
+ lineup = Lineup::Screenshot.new('https://uhr.ptb.de')
8
+ lineup.wait_for_asynchron_pages(1)
9
+ lineup.use_phantomjs true
10
+ start = Time.now
11
+ puts("Taking screenshots")
7
12
  lineup.record_screenshot('base')
13
+ screenshots = Time.now
14
+ sleep(2)
15
+ lineup.record_screenshot('nun')
16
+ screenshots2 = Time.now - 2
17
+ puts("Starting comparison")
18
+ lineup.compare('base', 'nun')
19
+ lineup.save_json(".")
20
+ compare = Time.now - 2
21
+
22
+ s_t = screenshots - start
23
+ puts("Screenshots first run took #{s_t} seconds")
24
+ s_t = screenshots2 - screenshots
25
+ puts("Screenshots second run took #{s_t} seconds")
26
+ c = compare - screenshots2
27
+ puts("Comparison took #{c} seconds")
28
+
29
+ puts("End")
@@ -17,11 +17,6 @@ class Comparer
17
17
  compare_images
18
18
  end
19
19
 
20
- def json(path)
21
- FileUtils.mkdir_p path
22
- generate_json(path)
23
- end
24
-
25
20
  private
26
21
 
27
22
  def compare_images
@@ -53,12 +48,12 @@ class Comparer
53
48
  )
54
49
  images.save_difference_image diff_name
55
50
  result = {
56
- url: url,
57
- width: width,
58
- difference: images.difference,
59
- base_file: base_name,
60
- new_file: new_name,
61
- difference_file: diff_name
51
+ url: url,
52
+ width: width,
53
+ difference: images.difference,
54
+ base_file: base_name,
55
+ new_file: new_name,
56
+ difference_file: diff_name
62
57
  }
63
58
  self.difference << result
64
59
  end
@@ -66,14 +61,4 @@ class Comparer
66
61
  end
67
62
  end
68
63
 
69
- def generate_json(path)
70
- json = difference.to_json
71
- file = File.open(
72
- "#{path}/log.json", "a+"
73
- )
74
- file.write(json)
75
- file.close
76
- end
77
-
78
-
79
64
  end
@@ -1,7 +1,7 @@
1
1
  module Lineup
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 4
4
+ MINOR = 5
5
5
  PATCH = 0
6
6
 
7
7
  class << self
data/lib/lineup.rb CHANGED
@@ -51,6 +51,8 @@ module Lineup
51
51
  # see more in according method below
52
52
 
53
53
  difference_path("#{Dir.pwd}/screenshots")
54
+
55
+ @comparer = []
54
56
  end
55
57
 
56
58
 
@@ -178,7 +180,7 @@ module Lineup
178
180
  # if it is not nil it has to be an array:
179
181
  if cookie
180
182
  # generate :symbol => "value" hash map from "symbol" => "value"
181
- cookie = cookie.inject({}){|element,(symbol,value)| element[symbol.to_sym] = value; element}
183
+ cookie = cookie.inject({}) { |element, (symbol, value)| element[symbol.to_sym] = value; element }
182
184
 
183
185
  #Validation
184
186
  (raise "Cookie must be a hash of format
@@ -265,7 +267,7 @@ module Lineup
265
267
  cookies(configuration["cookies"])
266
268
 
267
269
  if @cookies
268
- cookies_merged= @cookies.inject([]) { |a,element| a << element.dup }
270
+ cookies_merged= @cookies.inject([]) { |a, element| a << element.dup }
269
271
  else
270
272
  cookies_merged = []
271
273
  end
@@ -293,26 +295,32 @@ module Lineup
293
295
  # @screenshot_path
294
296
 
295
297
  if @cookies
296
- cookies_merged= @cookies.inject([]) { |a,element| a << element.dup }
298
+ cookies_merged= @cookies.inject([]) { |a, element| a << element.dup }
297
299
  else
298
300
  cookies_merged = []
299
301
  end
300
302
  if @cookie_for_experiment
301
303
  cookies_merged.push(@cookie_for_experiment)
302
304
  end
303
- browser = Browser.new(@baseurl, @urls, @resolutions, @screenshots_path, @headless, @wait_for_asynchron_pages, cookies_merged)
304
-
305
- # the only argument missing is if this is the "base" or "new" screenshot, this can be
306
- # passed as an argument. The value does not need to be "base" or "new", but can be anything
307
-
308
- browser.record(version)
309
305
 
310
- # this will close the browser and terminate the headless environment
311
-
312
- browser.end
306
+ threads = []
307
+ i=0
308
+ @urls.each { |url|
309
+ @resolutions.each { |resolution|
310
+ threads[i] = Thread.new {
311
+ browser = Browser.new(@baseurl, [url], [resolution], @screenshots_path, @headless, @wait_for_asynchron_pages, cookies_merged)
312
+ # the only argument missing is if this is the "base" or "new" screenshot, this can be
313
+ # passed as an argument. The value does not need to be "base" or "new", but can be anything
314
+ browser.record(version)
315
+ # this will close the browser and terminate the headless environment
316
+ browser.end
317
+ }
318
+ i+=1;
319
+ }
320
+ }
321
+ threads.each { |t| t.join }
313
322
 
314
323
  # this flag is set, so that parameters like resolution or urls cannot be changed any more
315
-
316
324
  @got_base_screenshots = true
317
325
  end
318
326
 
@@ -324,29 +332,36 @@ module Lineup
324
332
  # as "variable" in the method "record_screenshot"!
325
333
  # all other information are constants and are passed along
326
334
 
327
- @comparer = Comparer.new(base, new, @difference_path, @baseurl, @urls, @resolutions, @screenshots_path)
335
+ threads = []
336
+ i=0
337
+ @urls.each { |url|
338
+ @resolutions.each { |resolution|
339
+ threads[i] = Thread.new {
340
+ @comparer.push(Comparer.new(base, new, @difference_path, @baseurl, [url], [resolution], @screenshots_path))
341
+ }
342
+ i+=1;
343
+ }
344
+ }
345
+ threads.each { |t| t.join }
328
346
 
329
347
  # this gives back an array, which as one element for each difference image.
330
348
  # [ {diff_1}, {diff_2}, ...]
331
349
  # while each diff is a hash with keys:
332
350
  # {url: <url>, width: <width in px>, difference: <%of changed pixel>, base_file: <file path>, new_file: <file path>, diff_file: <file path>}
333
-
334
- @comparer.difference
351
+ @comparer.each { |c| c.difference }
335
352
  end
336
353
 
337
354
  def save_json(path)
338
355
 
339
356
  # json output can be saved if needed. A path is required to save the file
340
-
341
- raise "screenshots need to be compared before json output can be gernerated" unless @comparer
357
+ raise "screenshots need to be compared before json output can be generated" unless @comparer.count > 0
342
358
 
343
359
  # the array from @comparer.difference is saved as json
344
-
345
- @comparer.json(path)
360
+ save_comparer_log(path)
346
361
 
347
362
  end
348
363
 
349
- private
364
+ private
350
365
 
351
366
  def raise_base_screenshots_taken(value)
352
367
  if @got_base_screenshots
@@ -358,6 +373,19 @@ module Lineup
358
373
  urls.gsub(' ', '').gsub(';', ',')
359
374
  end
360
375
 
376
+ def save_comparer_log(path)
377
+ FileUtils.mkdir_p path
378
+
379
+ diff = []
380
+ @comparer.each { |c| diff += c.difference }
381
+ json = diff.to_json
382
+ file = File.open(
383
+ "#{path}/log.json", "w"
384
+ )
385
+ file.write(json)
386
+ file.close
387
+ end
388
+
361
389
  end
362
390
 
363
391
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lineup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Finn
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-06 00:00:00.000000000 Z
12
+ date: 2016-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec