dotdiff 1.2.1 → 2.0.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: 88c24a6cd7b8664be57c3969cde582e2cac5c25c
4
- data.tar.gz: 94542a6d703ee8fb50dcee720c116d2dad4a8cd0
3
+ metadata.gz: 6c8aaffec17072161e9ad80103b90391e0eb415e
4
+ data.tar.gz: 29653119f66174a464a698ce08f9a2fef3b8a587
5
5
  SHA512:
6
- metadata.gz: cc886b3a9d07766a64b0b7ee564447fbe629c37402e344c9138707ceabdc80110d62abc1d3b32138e9fc3b7d92e9dbb20089da0a93f60fbf7dc784cb978d0e86
7
- data.tar.gz: ca193151f90733ab22239d964798f6c34f165fb441d8201fba3f3e2d5700f3b817777108e4359771e4ef9a86b18f896612846cff1ed118cd9b5420b573337e39
6
+ metadata.gz: c610941e322c2953bc4a7eccede499acd536a24833062098d1d2238b82572d47ed587fb832aa3d0d3ab05050a9efe70000d5f9d93e133edcfa024d154263ac92
7
+ data.tar.gz: eee9149c62f98364f31b17d67f5a1189193646bcee64b568dc9a8f0e5467cfe26c61a7a09253cf99313e6a46d70624bcabdcd2525c521f9246610d160b2a9a1d
data/README.md CHANGED
@@ -1,10 +1,14 @@
1
1
  # Dotdiff
2
2
 
3
- Dotdiff is a very basic wrapper around [perceptual-diff](http://pdiff.sourceforge.net/) which works with both Capybara and RSpec to capture and compare the images with a simple rspec matcher.
3
+ Dotdiff is a very basic wrapper around imåge magick compare program which works with both Capybara
4
+ and RSpec to capture and compare the images with a simple rspec matcher.
4
5
 
5
- It is now also possible to snapshot a particular element on the page just by using the standard capybara finders - which once the element is found will query the browser for its dimensions and placement on the page and use that metadata to crop using chunky_png from a full page snapshot.
6
+ It is now also possible to snapshot a particular element on the page just by using the standard
7
+ capybara finders - which once the element is found will query the browser for its dimensions and
8
+ placement on the page and use that metadata to crop using chunky_png from a full page snapshot.
6
9
 
7
- It can also hide certain elements via executing javascript for elements which can change with different display suchas username or user specific details, but only for full page screenshots.
10
+ It can also hide certain elements via executing javascript for elements which can change with
11
+ different display suchas username or user specific details, but only for full page screenshots.
8
12
 
9
13
  ## Installation
10
14
 
@@ -26,7 +30,7 @@ Or install it yourself as:
26
30
  ## Usage
27
31
 
28
32
  ### Dependencies
29
- First ensure to install perceptualdiff binary which is available via apt-get and brew or via http://pdiff.sourceforge.net/
33
+ First ensure to install image magick binary which is available via apt-get or brew
30
34
 
31
35
  In your spec/spec_helper
32
36
  ```
@@ -43,7 +47,9 @@ In an initializer you can configure certain options example shown below within D
43
47
 
44
48
  ```ruby
45
49
  DotDiff.configure do |config|
46
- config.perceptual_diff_bin = `which perceptualdiff`.strip
50
+ config.image_magick_diff_bin = `which compare`
51
+ config.pixel_threshold = 120
52
+ config.image_magick_options = '-metric AE'
47
53
  config.image_store_path = File.join('/home', 'user', 'images')
48
54
  config.xpath_elements_to_hide = ["id('main')"]
49
55
  config.failure_image_path = File.join('/home', 'user', 'failure_comparisions')
@@ -71,12 +77,13 @@ The only difference for the element specific is passing a specific element in th
71
77
 
72
78
  | Config | Description | Example | Default | Required |
73
79
  |------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------|--------------------------------|----------|
74
- | perceptual_diff_bin | Location of the perceptual diff binary file | `which perceptualdiff`.strip | N/A | Yes |
80
+ | image_magick_diff_bin | Location of the image magick compare binary file | `which compare` | N/A | Yes |
75
81
  | image_store_path | The root path to store the base images | File.join('/home', 'user','images') | nil | Yes |
76
82
  | xpath_elements_to_hide | When taking full page screenshots it will hide elements specified that might change each time and re-shows them after the screenshot. It doesn't use this option for taking screenshots of specific elements. | ["id('main')", "//div[contains(@class, 'formy'])[1]"] | [] | No |
77
83
  | failure_image_path | When a comparison occurs and the perceptual_diff binary returns a failure with the message. It will dump the new image taken for comparison to this directory. If not supplied it will not move the images from the temporary location that it is generated at. | File.join('/home', 'user','failures') | nil | No |
78
84
  | max_wait_time | This is similar to the Capybara#default_max_wait_time if you have a high value such as 10, as its possible that the global xpath_elements_to_hide might not always exist it will wait the full time - therefore you can drop it for the hiding and showing of the elements. In this example it would wait up 20 seconds in total 10 for hiding and 10 seconds for re-showing - that is if the element isn't even going to be present on the page. | 2 | Capybara#default_max_wait_time | No |
79
-
85
+ | pixel_threshold | This validates the output from compare is within your specified threshold | 120 | 100 | No |
86
+ | image_magick_options | This allows you to pass some custom options to image magick | '-fuzz 10% -metric RSME' | '-fuzz 5% -metric AE' | No |
80
87
  ## Contributing
81
88
 
82
89
  Bug reports and pull requests are welcome on GitHub at https://github.com/jnormington/dotdiff.
data/lib/dotdiff.rb CHANGED
@@ -13,22 +13,36 @@ require 'dotdiff/snapshot'
13
13
  require 'dotdiff/comparer'
14
14
 
15
15
  module DotDiff
16
- class << self
17
- attr_accessor :perceptual_diff_bin, :resave_base_image, :failure_image_path,
18
- :image_store_path, :overwrite_on_resave, :xpath_elements_to_hide,
19
- :max_wait_time
20
-
21
- def configure
22
- yield self
23
- end
24
-
25
- def resave_base_image
26
- @resave_base_image ||= false
27
- end
28
-
29
- def xpath_elements_to_hide
30
- @xpath_elements_to_hide ||= []
31
- end
16
+ class << self
17
+ attr_accessor :resave_base_image, :failure_image_path,
18
+ :image_store_path, :overwrite_on_resave, :xpath_elements_to_hide,
19
+ :max_wait_time
20
+
21
+ attr_writer :image_magick_options, :pixel_threshold, :image_magick_diff_bin
22
+
23
+ def configure
24
+ yield self
25
+ end
26
+
27
+ def resave_base_image
28
+ @resave_base_image ||= false
29
+ end
30
+
31
+ def xpath_elements_to_hide
32
+ @xpath_elements_to_hide ||= []
33
+ end
34
+
35
+ def image_magick_options
36
+ @image_magick_options ||= '-fuzz 5% -metric AE'
37
+ end
38
+
39
+ def image_magick_diff_bin
40
+ @image_magick_diff_bin.to_s.strip
41
+ end
42
+
43
+ def pixel_threshold
44
+ @pixel_threshold ||= 100
45
+ end
32
46
 
33
47
  def max_wait_time
34
48
  @max_wait_time || Capybara.default_max_wait_time
@@ -4,16 +4,23 @@ module DotDiff
4
4
  class CommandWrapper
5
5
  attr_reader :message
6
6
 
7
- def run(base_image, new_image)
8
- output = `#{command(base_image, new_image)}`
7
+ def run(base_image, new_image, diff_image_path)
8
+ output = run_command(base_image, new_image, diff_image_path)
9
9
 
10
10
  @ran_checks = true
11
11
 
12
- if output.include?('PASS:')
13
- @failed = false
14
- else
12
+ begin
13
+ pixels = Float(output)
14
+
15
+ if pixels && pixels <= DotDiff.pixel_threshold
16
+ @failed = false
17
+ else
18
+ @failed = true
19
+ @message = "Images are #{pixels} pixels different"
20
+ end
21
+ rescue ArgumentError => e
15
22
  @failed = true
16
- @message = output.split("\n").join(' ')
23
+ @message = output
17
24
  end
18
25
  end
19
26
 
@@ -31,9 +38,15 @@ module DotDiff
31
38
 
32
39
  private
33
40
 
34
- def command(base_image, new_image)
35
- "#{DotDiff.perceptual_diff_bin} #{Shellwords.escape(base_image)} "\
36
- "#{Shellwords.escape(new_image)} -verbose"
41
+ # For the tests
42
+ def run_command(base_image, new_image, diff_image_path)
43
+ `#{command(base_image, new_image, diff_image_path)}`.strip
44
+ end
45
+
46
+ def command(base_image, new_image, diff_image_path)
47
+ "#{DotDiff.image_magick_diff_bin} #{DotDiff.image_magick_options} " \
48
+ "#{Shellwords.escape(base_image)} #{Shellwords.escape(new_image)} " \
49
+ "#{Shellwords.escape(diff_image_path)} 2>&1"
37
50
  end
38
51
  end
39
52
  end
@@ -45,11 +45,11 @@ module DotDiff
45
45
 
46
46
  def compare(compare_to_image)
47
47
  result = CommandWrapper.new
48
- result.run(snapshot.basefile, compare_to_image)
48
+ result.run(snapshot.basefile, compare_to_image, snapshot.diff_file)
49
49
 
50
50
  if result.failed? && DotDiff.failure_image_path
51
51
  FileUtils.mkdir_p(snapshot.failure_path)
52
- FileUtils.mv(compare_to_image, snapshot.failure_file, force: true)
52
+ FileUtils.mv(compare_to_image, snapshot.new_file, force: true)
53
53
  end
54
54
 
55
55
  [result.passed?, result.message]
@@ -2,7 +2,7 @@ module DotDiff
2
2
  class Snapshot
3
3
  include Image::Cropper
4
4
 
5
- attr_reader :base_filename, :subdir, :rootdir, :page
5
+ attr_reader :base_filename, :subdir, :rootdir, :page, :use_custom_screenshot
6
6
 
7
7
  IMAGE_EXT = 'png'.freeze
8
8
 
@@ -12,6 +12,8 @@ module DotDiff
12
12
  @subdir = opts[:subdir].to_s
13
13
  @rootdir = opts[:rootdir].to_s
14
14
  @page = opts[:page]
15
+ @fullscreen = opts[:fullscreen_file]
16
+ @use_custom_screenshot = opts[:use_custom_screenshot]
15
17
  end
16
18
 
17
19
  def fullscreen_file
@@ -41,14 +43,20 @@ module DotDiff
41
43
  end
42
44
 
43
45
  def failure_path
44
- File.join(DotDiff.failure_image_path, subdir)
46
+ File.join(DotDiff.failure_image_path.to_s, subdir)
45
47
  end
46
48
 
47
- def failure_file
49
+ def new_file
48
50
  File.join(failure_path, "#{base_filename(false)}.new.#{IMAGE_EXT}" )
49
51
  end
50
52
 
53
+ def diff_file
54
+ File.join(failure_path, "#{base_filename(false)}.diff.#{IMAGE_EXT}")
55
+ end
56
+
51
57
  def capture_from_browser(hide_and_show = true, element_handler = ElementHandler.new(page))
58
+ return fullscreen_file if use_custom_screenshot
59
+
52
60
  if hide_and_show
53
61
  element_handler.hide
54
62
  page.save_screenshot(fullscreen_file)
@@ -1,3 +1,3 @@
1
1
  module DotDiff
2
- VERSION = "1.2.1"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotdiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Normington
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-12 00:00:00.000000000 Z
11
+ date: 2016-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick