nakal 0.0.7 → 0.1.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: 94bdb39bc573fb44a15573607687333b0c5a9d84
4
- data.tar.gz: 8e737f7832ab3efa90f91849e6a71625849a9ce1
3
+ metadata.gz: 2081d156847ef0890647c56f615825ab1c2f26d1
4
+ data.tar.gz: 2ef66d48ea906defc31b87d6304f047264c9ae02
5
5
  SHA512:
6
- metadata.gz: fdcef019fb259b6d895f3840de1622772c41b22202ac792556d0b2b8a02d8e2c831967ba0b14871a80708945e1cf35823effe1833fcf60c388701f703f6a6040
7
- data.tar.gz: b47b1087ff877b5aa4ebe3273884bd74d73e6439403bba15b87b4ef1c0d4da75f7ceed374eb580e8b841c4d17b22b1d38637ddbee310908beb7cd2a4d0abaf06
6
+ metadata.gz: 8226e331bf26bc2c99c518fd92dc4e7b9e25b8ccb6583f7a448192d33f639a00163279517b82b9618bd81f79d92c66ac6baf6e4fdbe3c09ffbfda1047d1e7e84
7
+ data.tar.gz: ae13c3bbdbd7b0303321a1ebbf61f50ebdfb9f12e92de3c13c84a485b40c2a49084569fc2a78de14f614a27427a8ac5c48d44aeee08dbbe4c2a8b439e656b88b
data/README.md CHANGED
@@ -40,17 +40,16 @@ Now, execute your test by passing env variable NAKAL_MODE=build to build the bas
40
40
  once baseline is built, next execution onwards, start using environment variable NAKAL_MODE=compare to compare against baseline.
41
41
  any difference will be put in the same directory with image file named "current_screen_name_diff.png"
42
42
 
43
- ## Important
43
+ If You want to organize baseline nicely, you can even specify sub-paths in #nakal_execute like this:
44
44
 
45
- * This works best when your tests are running against mocked data
46
- * If test data keeps changing for each test, use diff_metric (output of nakal_execute method above) to determine if the change is acceptable.
45
+ diff_metric = nakal_execute("feature/sub_feature/current_screen_name")
47
46
 
48
47
  For setting custom directory, use:
49
48
 
50
49
  Nakal.directory= "<desired_directory>"
51
50
  Nakal.device_name = "nexus7"
52
51
 
53
- For cropping the notification bar OR scroll bar, create a config/nakal.yml file in execution directory
52
+ For cropping the notification bar OR scroll bar, create a config/nakal.yml file in execution directory.
54
53
 
55
54
  eg:
56
55
 
@@ -61,6 +60,8 @@ put these contents in your nakal.yml file inside config/nakal.yml
61
60
  right: 18
62
61
  left: 0
63
62
  bottom: 0
63
+ screen_name_to_be_masked: {mask_region: [66,424,340,478]}
64
+ feature/sub_feature/current_screen_name: {mask_region_1: [66,424,340,478],mask_region_2: [76,524,440,578]}
64
65
 
65
66
  nexus7:
66
67
  top: 74
@@ -72,10 +73,25 @@ put these contents in your nakal.yml file inside config/nakal.yml
72
73
  top: 30
73
74
  right: 6
74
75
  left: 0
75
- bottom: 0
76
+ bottom: 0
77
+ screen_name_to_be_masked: {mask_region: [66,424,340,478]}
78
+ feature/sub_feature/current_screen_name: {mask_region_1: [66,424,340,478],mask_region_2: [76,524,440,578]}
76
79
 
77
- ## ToDo
78
- 1. Put a logic to wait for screen to load until it is matching the baseline. Timeout after certain time and fail.
80
+ ## Note
81
+ 1. There is implicit wait of 30 sec until current screen matches baseline. This timeout can be changed by setting:
82
+
83
+ Nakal.timeout = new_timeout_value
84
+
85
+
86
+ 2. you can specify the areas of a screen you want to mask/ignore while comparing in nakal.yml as below:
87
+
88
+ samsung_galaxy_s3:
89
+ top: 50
90
+ right: 18
91
+ left: 0
92
+ bottom: 0
93
+ screen_name_to_be_masked: {mask_region_1: [66,424,340,478],mask_region_2: [76,524,440,578]}
94
+
79
95
 
80
96
  ## Contributing
81
97
 
@@ -27,11 +27,25 @@ module Nakal
27
27
  end
28
28
 
29
29
  def compare screen
30
- diff_img, diff_metric = self.strip.compare_channel(screen.strip, Magick::RootMeanSquaredErrorMetric)
30
+ diff_img, diff_metric = self.apply_mask.strip.compare_channel(screen.apply_mask.strip, Magick::RootMeanSquaredErrorMetric)
31
31
  diff_screen = Nakal.current_platform::Screen.new("#{@name}_diff", :none, diff_img)
32
32
  return diff_screen, diff_metric
33
33
  end
34
34
 
35
+ def apply_mask
36
+ image_mask_params = Nakal.default_crop_params[Nakal.device_name][image_relative_path.gsub("_current", "")]
37
+ return self if image_mask_params.nil?
38
+ image_mask_params.each do |region, params|
39
+ gc = Magick::Draw.new.fill('black').rectangle(*params)
40
+ gc.draw @image
41
+ end
42
+ self
43
+ end
44
+
45
+ def image_relative_path
46
+ Nakal.image_relative_dir.eql?(".") ? @name : "#{Nakal.image_relative_dir}/#{@name}"
47
+ end
48
+
35
49
  def delete!
36
50
  FileUtils.rm "#{Nakal.image_location}/#{@name}.png"
37
51
  end
data/lib/nakal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nakal
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/nakal.rb CHANGED
@@ -12,14 +12,15 @@ module Nakal
12
12
 
13
13
  class<<self
14
14
  attr_accessor :device_name, :directory, :platform, :image_location, :default_crop_params
15
- attr_accessor :diff_screens, :embed_screenshot, :timeout
15
+ attr_accessor :diff_screens, :embed_screenshot, :timeout, :image_relative_dir
16
16
 
17
17
  def configure
18
18
  yield self
19
19
  end
20
20
 
21
- def create_image_dir dir
22
- @image_location = "#{@directory}/#{@device_name}/#{dir}"
21
+ def create_image_dir image_relative_dir
22
+ @image_relative_dir = image_relative_dir
23
+ @image_location = "#{@directory}/#{@device_name}/#{image_relative_dir}"
23
24
  FileUtils.mkdir_p @image_location unless File.directory?(@image_location)
24
25
  end
25
26
 
@@ -5,7 +5,7 @@ require 'nakal'
5
5
  Nakal.platform = :android
6
6
  Nakal.directory= "spec/resources/droid"
7
7
  Nakal.device_name = "samsung_galaxy_s3"
8
- Nakal.create_image_dir "xx"
8
+ Nakal.create_image_dir "feature"
9
9
 
10
10
  module Nakal::Android
11
11
  class Screen
@@ -71,13 +71,33 @@ describe Nakal::Android::Screen do
71
71
  describe "#compare" do
72
72
  it "compares two screens" do
73
73
  Nakal.default_crop_params = {"samsung_galaxy_s3" => {"top" => 50, "right" => 0, "left" => 0, "bottom" => 0}}
74
- changed_screen = Nakal::Android::Screen.new("changed_home_screen", :load)
74
+ changed_screen = Nakal::Android::Screen.new("home_screen_current", :load)
75
75
  diff_screen, diff_metric = @screen.compare(changed_screen)
76
76
  expect(diff_metric.round(6)).to eq 0.062555
77
77
  expect(diff_screen).to be_an_instance_of Nakal::Android::Screen
78
78
  expect(diff_screen.name).to eql "home_screen_diff"
79
79
  diff_screen.save
80
80
  end
81
+
82
+ it "compares two screens by ignoring specified region" do
83
+ Nakal.default_crop_params = {"samsung_galaxy_s3" => {"top" => 50, "right" => 0, "left" => 0, "bottom" => 0,
84
+ "feature/home_screen" => {"cam_icon1" => [66, 852, 206, 996]}}}
85
+ @screen = Nakal::Android::Screen.new("home_screen", :load)
86
+ changed_screen = Nakal::Android::Screen.new("home_screen_current", :capture)
87
+ diff_screen, diff_metric = @screen.compare(changed_screen)
88
+ expect(diff_metric.round(5)).to eq 0.05189
89
+ diff_screen.save
90
+ end
91
+
92
+ it "compares two screens by ignoring all specified region" do
93
+ Nakal.default_crop_params = {"samsung_galaxy_s3" => {"top" => 50, "right" => 0, "left" => 0, "bottom" => 0,
94
+ "feature/home_screen" => {"cam_icon1" => [66, 852, 206, 996], "cam_icon2" => [210, 228, 340, 392],"clock" => [364, 484, 672, 770]}}}
95
+ @screen = Nakal::Android::Screen.new("home_screen", :load)
96
+ changed_screen = Nakal::Android::Screen.new("home_screen_current", :capture)
97
+ diff_screen, diff_metric = @screen.compare(changed_screen)
98
+ expect(diff_metric).to eq 0.0
99
+ diff_screen.save
100
+ end
81
101
  end
82
102
 
83
103
  after(:all) do
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nakal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajdeep
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-30 00:00:00.000000000 Z
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
@@ -91,8 +91,9 @@ files:
91
91
  - lib/nakal/version.rb
92
92
  - nakal.gemspec
93
93
  - spec/nakal/android/screen_spec.rb
94
- - spec/resources/changed_home_screen.png
94
+ - spec/resources/.DS_Store
95
95
  - spec/resources/home_screen.png
96
+ - spec/resources/home_screen_current.png
96
97
  - spec/spec_helper.rb
97
98
  homepage: https://github.com/rajdeepv/nakal
98
99
  licenses:
@@ -114,13 +115,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  version: '0'
115
116
  requirements: []
116
117
  rubyforge_project:
117
- rubygems_version: 2.2.2
118
+ rubygems_version: 2.4.8
118
119
  signing_key:
119
120
  specification_version: 4
120
121
  summary: Automated visual regression testing of android and ios apps with appoum/calabash
121
122
  or any other tool
122
123
  test_files:
123
124
  - spec/nakal/android/screen_spec.rb
124
- - spec/resources/changed_home_screen.png
125
+ - spec/resources/.DS_Store
125
126
  - spec/resources/home_screen.png
127
+ - spec/resources/home_screen_current.png
126
128
  - spec/spec_helper.rb