pixage 0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52d34826bb6e2ef1a6082661f16303ca8f46a8f3
4
+ data.tar.gz: 38dcd13502b36e1c36b04b6b3ce4c9722b52dc65
5
+ SHA512:
6
+ metadata.gz: 5b575bfbffeb7dbac743eb0f4ce04e072ba8369f6bea694266ffe4a74536fcf63c566a1b1a1b8f6b4485dea2c3968ee8970e74344c00533b0f0ce955c2df0bc9
7
+ data.tar.gz: edc6b627e69626ffaa78f69647ad732f4c88226c00bc2bb00406f535a61028ab0d08b4d512ca50f5f96ec06eed58208076e2ae7ca627358bdc0c5aaf7de13817
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015-2016 Kaushal Rupani
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,107 @@
1
+ # pixage
2
+
3
+ **PIX**el perfect application using visual regression testing with help of im**AGE**-magick gives birth to **PIXAGE**
4
+ Pixels + Image = Pixage
5
+
6
+ A utility which can be used manually or be integrated with an existing selenium-ruby or appium-ruby automation framework to perform __*visual regression testing*__ of screenshots.
7
+
8
+
9
+ ## Table of contents
10
+ - [Installation](#installation)
11
+ - [Install using gem command](#gem)
12
+ - [Install using bundler](#bundler)
13
+ - [Dependency](#dependency)
14
+ - [Usage](#usage)
15
+ - [CLI Usage](#cli)
16
+ - [Automation Usage](#automation)
17
+ - [Contributing](#contributing)
18
+ - [Issues](#issues)
19
+
20
+
21
+ ## Installation
22
+ There are multiple ways in which you can install and use pixage gem.
23
+ You must have Ruby installed before you can install this gem.
24
+
25
+ ### <a name="gem" /> 1. Install using gem command
26
+ Just use following command from you Terminal.
27
+ ```
28
+ gem install pixage
29
+ ```
30
+
31
+ ### <a name="bundler" /> 2. Install using bundler
32
+ You can include it in your Gemfile and run bundle install.
33
+ ```
34
+ gem 'pixage'
35
+ ```
36
+ then run following
37
+ ```
38
+ bundle install
39
+ ```
40
+
41
+ ## Dependency
42
+ This gem is dependent on ImageMagick. Please install latest verison of ImageMagick before you start using pixage.
43
+ To verify if imagemagick is successfully installed, please run the following command (After installaing pixage).
44
+ ```
45
+ pixage diagnosis
46
+ ```
47
+
48
+ ## Usage
49
+ There are 2 ways this gem can be used.
50
+ 1. CLI usage which can be really helpful for testers and designers to do visual regression testing manually.
51
+ 2. Can be integrated with automation suite to compare run time screenshots with pre-saved baseline images.
52
+
53
+ ### <a name="cli"></a> 1. CLI Usage
54
+ Following are the list of commands :
55
+
56
+ ![help, diagnosis, compare, resize_n_compare, version](https://github.com/krupani/pixage/blob/master/images/pixage_commands.png)
57
+
58
+ Basic usage in case of compare 2 images which are similar size and resolution:
59
+ ```
60
+ # Basic usage with default options
61
+ pixage compare images/expected.png images/actual.png
62
+
63
+ # Basic usage with custom options
64
+ pixage compare images/expected.png images/actual.png --threshold=1 --fuzz=25 --color=red
65
+
66
+ ```
67
+
68
+ For further commmand usage [documentation](https://github.com/krupani/pixage/wiki), please refer the [wiki](https://github.com/krupani/pixage/wiki) section.
69
+
70
+ ### <a name="automation"></a> 2. Automation Usage
71
+ Apart from CLI usage, pixage gem can also be integrated with automation suite be it a selenium-webdriver-ruby for web application or appium-ruby for mobile applications or just a ruby script acheieving some fine purpose.
72
+ Below is the code snippet to be used in case of automation integration:
73
+
74
+ ```
75
+ # First, as mentioned in installation step, include gem in Gemfile
76
+ gem 'pixage'    
77
+
78
+ # Next, require and include it in your project
79
+ require 'pixage'
80
+ include 'Pixage'    
81
+
82
+ # Finally use the commands in your code:
83
+ # Assuming you have your baseline/expected image previously stored
84
+ @driver.save_screenshot(actual.png)
85
+ resize_n_compare(expected.png, actual.png)
86
+
87
+ # Also you can compare 2 runtime images like:
88
+ @driver.save_screenshot(first.png)
89
+ @driver.save_screenshot(second.png)
90
+ compare(first.png, second.png)
91
+
92
+ ```
93
+
94
+ _NOTE: To see a working example on how to integrate pixage with a Ruby-Cucumber-Selenium tests, please see the examples directory. It also has a sample report stored for reference._
95
+
96
+ To execute the example, do the following:
97
+ - Clone the repo `git clone https://github.com/krupani/pixage.git`
98
+ - get into the examples folder `cd pixage/examples`
99
+ - install dependent gems or just run `bundle install`
100
+ - if you dont have bundler installed then first run `gem install bundler` and then repeat above step
101
+ - execute the tests `cucumber features BROWSER=chrome` , provided you have chromedriver in your PATH
102
+
103
+ ## Contributing
104
+ Ideas and suggestions are always always most welcome. Please fork this gem and feel free to add any updates, suggestions etc and create a pull request.
105
+
106
+ ## Issues
107
+ If you face any problem related to syntax, usability, documentation then please raise an [issue](https://github.com/krupani/pixage/issues)
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pixage/diagnosis"
4
+ require "pixage/cli"
5
+ include Pixage
6
+
7
+ def show_help
8
+ puts <<HELP
9
+
10
+ Commands :
11
+
12
+ help
13
+ ----
14
+ Description : Prints help information
15
+ Usage : pixage help
16
+
17
+
18
+ diagnosis
19
+ ---------
20
+ Description : Performs a check to see all dependecies match for smooth execution of pixage gem commands
21
+ Usage : pixage diagnosis
22
+
23
+
24
+ compare
25
+ -------
26
+ Description : Compares 2 images and generates diff (compares original images and just generates a diff image)
27
+ Usage : pixage compare <expected_image_path> <actual_image_path> <--option=value>
28
+ Options : 1. --threshold (optional) : maximum distortion allowed while matching (default = 1)
29
+ 2. --fuzz (optional) : fuzz distance between colours (default = 20)
30
+ 3. --color (optional) : highlight pixel difference with this color (default = blue)
31
+
32
+
33
+ resize_n_compare
34
+ ----------------
35
+ Description : Resizes the images and then compares (makes a copy of original images before resizing)
36
+ (By default the larger images is resized to the smaller image to avoid pixelating.)
37
+ Usage : pixage resize_n_compare <expected_image_path> <actual_image_path> <--option=value>
38
+ options : 1. --threshold (optional) : maximum distortion allowed while matching (default = 1)
39
+ 2. --fuzz (optional) : fuzz distance between colours (default = 20)
40
+ 3. --color (optional) : highlight pixel difference with this color (default = blue)
41
+ 4. --resize (optional) : a. desc (default) : for resizing larger image to smaller one
42
+ b. asc : for resizing smaller image to larger one (image can pixelate)
43
+ 5. --force (options) : force=true will ignore aspect ratio while resizing (default=false)
44
+
45
+
46
+ version
47
+ -------
48
+ Description : Shows the version of pixage gem
49
+ Usage : pixage version | pixage --version | pixage -v
50
+
51
+ HELP
52
+ end
53
+
54
+ def arg_to_hash(args)
55
+ arg_hash = {}
56
+ args.each do |arg|
57
+ arg_arr = arg.gsub("-","").split("=")
58
+ arg_hash[arg_arr.first.downcase.to_sym] = arg_arr.last.downcase
59
+ end
60
+ arg_hash
61
+ end
62
+
63
+
64
+ if ARGV.length == 0
65
+ show_help
66
+ else
67
+ cmd = ARGV.shift
68
+ case cmd
69
+
70
+ when 'version', '--version', '-v'
71
+ puts File.read(File.expand_path("../../lib/pixage/version", __FILE__))
72
+
73
+ when 'diagnosis'
74
+ Pixage::Diagnosis.new().perform_diagnosis
75
+
76
+ when 'compare'
77
+ if ARGV.size<2
78
+ show_help
79
+ elsif ARGV.size==2
80
+ compare(ARGV.shift, ARGV.shift)
81
+ else
82
+ compare(ARGV.shift, ARGV.shift, arg_to_hash(ARGV))
83
+ end
84
+
85
+ when 'resize_n_compare'
86
+ if ARGV.size<2
87
+ show_help
88
+ elsif ARGV.size==2
89
+ resize_n_compare(ARGV.shift, ARGV.shift)
90
+ else
91
+ resize_n_compare(ARGV.shift, ARGV.shift, arg_to_hash(ARGV))
92
+ end
93
+
94
+ else
95
+ show_help
96
+ end
97
+
98
+ end
99
+
100
+
101
+
102
+
103
+
104
+
@@ -0,0 +1,5 @@
1
+ :fuzz: 20
2
+ :threshold: 1
3
+ :color: "blue"
4
+ :resize: "desc"
5
+ :force: false
@@ -0,0 +1 @@
1
+ require 'pixage/cli'
@@ -0,0 +1,32 @@
1
+ require_relative 'params'
2
+ require_relative 'images/compare'
3
+
4
+ module Pixage
5
+
6
+ # @method compare(expected_image_file_path, actual_image_file_path, options={})
7
+ # @param expected_image_file_path [String]
8
+ # @param actual_image_file_path [String]
9
+ # @parm args [Hash]
10
+ # @return [String] -- file path of the diff.png file
11
+
12
+ def compare(expected, actual, args={})
13
+ images = manage_paths(expected,actual)
14
+ options = manage_options(args)
15
+ create_pixage_report_dir
16
+ Compare.new.compare_images(images,options)
17
+ end
18
+
19
+
20
+ # @method resize_n_compare(expected_image_file_path, actual_image_file_path, options={})
21
+ # @param expected_image_file_path [String]
22
+ # @param actual_image_file_path [String]
23
+ # @params args [Hash]
24
+ # @return [String] -- file path of the diff.png file
25
+
26
+ def resize_n_compare(expected, actual, args={})
27
+ images = manage_paths(expected,actual)
28
+ options = manage_options(args)
29
+ create_pixage_report_dir
30
+ Compare.new.resize_n_compare_images(images,options)
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ require 'logger'
2
+
3
+ module Pixage
4
+
5
+ class Diagnosis
6
+
7
+ def perform_diagnosis
8
+ check_image_magick_installation
9
+ # check_idevice_installation
10
+ # check_adb_installation
11
+ end
12
+
13
+ def check_image_magick_installation
14
+ puts "Checking ImageMagick installation.."
15
+ version = `magick -version | grep -i version`
16
+ if version.class == String and version.include?("ImageMagick")
17
+ console_log("ImageMagick is INSTALLED", :pass)
18
+ else
19
+ console_log("ImageMagick is NOT INSTALLED", :error)
20
+ end
21
+ end
22
+
23
+ private :check_image_magick_installation
24
+
25
+ end
26
+
27
+ end
28
+
29
+
@@ -0,0 +1,52 @@
1
+ require 'mini_magick'
2
+ require 'fileutils'
3
+ require 'pathname'
4
+ require_relative 'convert'
5
+ require_relative '../params'
6
+ require_relative '../logger'
7
+
8
+ module Pixage
9
+
10
+ class Compare
11
+
12
+ def compare_images(images,options)
13
+ convert = Convert.new()
14
+ if convert.check_sizes(images)
15
+ console_log("Warning: Image sizes are not equal, the generated diff might be misleading, please use : ", :warning)
16
+ console_log("pixage resize_n_compare\n", :pass)
17
+ end
18
+ execution_dir = Time.now.strftime("%d-%b-%y-%H-%M-%S")
19
+ create_compare_execution_dir(execution_dir)
20
+ cmd = "compare -dissimilarity-threshold #{options[:threshold]} -fuzz #{options[:fuzz]} -metric AE -highlight-color #{options[:color]} #{images[:expected]} #{images[:actual]} pixage_report/#{execution_dir}/diff.png"
21
+ execute_command(cmd)
22
+ Pathname.new("pixage_report/#{execution_dir}/diff.png").realpath.to_s
23
+ end
24
+
25
+ def resize_n_compare_images(images,options)
26
+ convert = Convert.new()
27
+ execution_dir = Time.now.strftime("%d-%b-%y-%H-%M-%S")
28
+ create_compare_execution_dir(execution_dir)
29
+ images = make_copies(images, "pixage_report/#{execution_dir}")
30
+ convert.resize_images(images,options)
31
+ cmd = "compare -dissimilarity-threshold #{options[:threshold]} -fuzz #{options[:fuzz]} -metric AE -highlight-color #{options[:color]} #{images[:expected]} #{images[:actual]} pixage_report/#{execution_dir}/diff.png"
32
+ execute_command(cmd)
33
+ Pathname.new("pixage_report/#{execution_dir}/diff.png").realpath.to_s
34
+ end
35
+
36
+ def execute_command(cmd)
37
+ require 'open3'
38
+ cmd_out = Open3.popen3(cmd)[2].read
39
+ end
40
+
41
+ def make_copies(images,path)
42
+ ts = Time.now.to_i
43
+ expected = Pathname.new(path+"/expected_#{ts}#{File.extname(images[:expected])}")
44
+ actual = Pathname.new(path+"/actual_#{ts}#{File.extname(images[:actual])}")
45
+ FileUtils.cp(images[:expected], expected)
46
+ FileUtils.cp(images[:actual], actual)
47
+ {:expected => expected.realpath, :actual => actual.realpath}
48
+ end
49
+
50
+ private :execute_command, :make_copies
51
+ end
52
+ end
@@ -0,0 +1,42 @@
1
+ require 'mini_magick'
2
+ require_relative '../logger'
3
+
4
+ module Pixage
5
+
6
+ class Convert
7
+
8
+ def check_sizes(images)
9
+ expected = MiniMagick::Image.new(images[:expected])
10
+ actual = MiniMagick::Image.new(images[:actual])
11
+ expected.dimensions != actual.dimensions
12
+ end
13
+
14
+ def resize_images(images,options={:resize => "desc", :force => "false"})
15
+ expected = MiniMagick::Image.new(images[:expected])
16
+ actual = MiniMagick::Image.new(images[:actual])
17
+ switch = 0
18
+ if options[:resize]=="desc"
19
+ switch = expected.dimensions <=> actual.dimensions
20
+ elsif options[:resize]=="asc"
21
+ switch = actual.dimensions <=> expected.dimensions
22
+ end
23
+
24
+ case switch
25
+ when 1
26
+ if options[:force]=="true"
27
+ expected.resize(actual.dimensions.join('x')+"!")
28
+ else
29
+ expected.resize(actual.dimensions.join('x'))
30
+ end
31
+ when -1
32
+ if options[:force]=="true"
33
+ actual.resize(expected.dimensions.join('x')+"!")
34
+ else
35
+ actual.resize(expected.dimensions.join('x'))
36
+ end
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,19 @@
1
+ require 'colorize'
2
+
3
+ module Pixage
4
+
5
+ def console_log(text, status, loud=false)
6
+ text=text.upcase if loud
7
+ case status.downcase.to_sym
8
+ when :warning
9
+ puts text.yellow
10
+ when :error, :exception
11
+ puts text.red
12
+ when :pass, :success
13
+ puts text.green
14
+ else
15
+ puts text
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,48 @@
1
+ require 'pathname'
2
+ require 'yaml'
3
+
4
+ module Pixage
5
+
6
+ def manage_paths(expected,actual)
7
+ images = {}
8
+ expected = Pathname.new(expected)
9
+ actual = Pathname.new(actual)
10
+ if expected.relative?
11
+ images[:expected] = expected.realpath
12
+ end
13
+ if actual.relative?
14
+ images[:actual] = actual.realpath
15
+ end
16
+ images
17
+ end
18
+
19
+ def manage_options(args={})
20
+ options = YAML.load_file(File.join(File.dirname(__FILE__) + "/../../data/defaults.yml"))
21
+ args.each do |key,val|
22
+ if key.downcase == :fuzz
23
+ options[:fuzz] = val.to_i
24
+ elsif key.downcase == :threshold
25
+ options[:threshold] = val.to_i
26
+ elsif key.downcase == :color
27
+ options[:color] = val.to_s.downcase
28
+ elsif key.downcase == :resize
29
+ options[:resize] = val.to_s.downcase
30
+ elsif key.downcase == :force
31
+ options[:force] = val.to_s.downcase
32
+ else
33
+ console_log("Unrecognised option `--#{key}=#{val}`, defaults will be applied.", :warning)
34
+ end
35
+ end
36
+ return options
37
+ end
38
+
39
+ def create_pixage_report_dir
40
+ Dir.mkdir("pixage_report") unless Dir.exists?("pixage_report")
41
+ end
42
+
43
+ def create_compare_execution_dir(dir_name)
44
+ create_pixage_report_dir
45
+ Dir.mkdir("pixage_report/#{dir_name}")
46
+ end
47
+
48
+ end
@@ -0,0 +1 @@
1
+ 0.1
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pixage
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Kaushal Rupani
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mini_magick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A visual regression utility with options to do single and bulk operations
42
+ both manually and integrable with Selenium automated tests in Ruby.
43
+ email:
44
+ - kushrupani@live.com
45
+ executables:
46
+ - pixage
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - LICENCE
51
+ - README.md
52
+ - bin/pixage
53
+ - data/defaults.yml
54
+ - lib/pixage.rb
55
+ - lib/pixage/cli.rb
56
+ - lib/pixage/diagnosis.rb
57
+ - lib/pixage/images/compare.rb
58
+ - lib/pixage/images/convert.rb
59
+ - lib/pixage/logger.rb
60
+ - lib/pixage/params.rb
61
+ - lib/pixage/version
62
+ homepage: https://github.com/krupani/pixage
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements:
81
+ - You must have ImageMagick installed on your system.
82
+ rubyforge_project:
83
+ rubygems_version: 2.6.12
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: A visual regression utility with options to do single and bulk operations
87
+ both manually and integrable with Selenium automated tests in Ruby.
88
+ test_files: []