nilal 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nilal.rb +1 -37
- data/lib/nilal/appium.rb +17 -0
- data/lib/nilal/capybara.rb +23 -0
- data/lib/nilal/chunky.rb +24 -16
- data/lib/nilal/firefox_driver.rb +26 -0
- metadata +5 -3
- data/lib/nilal/assert.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58b2c4f9082f68c0af2c4e03e1547adb83292dad
|
4
|
+
data.tar.gz: 199bf3f1628b1c2eeb814961886b2e786a18cd21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f31e0a058fe8d26c7366712d6466aa719c030473384ebd14fc6390cb950ab9ce9d88c87424af547283162ea3427550c1d41d6fd0c790ce681c5dd1940ce1ea77
|
7
|
+
data.tar.gz: 099a832d1bd3fbb751fd57cce9cb11e06a38ea8e26a7f0506a0a20144877e97959113b1692f4594d3094ee8e8b5257382eca306519f860522d689ea0959bf547
|
data/lib/nilal.rb
CHANGED
@@ -1,37 +1 @@
|
|
1
|
-
|
2
|
-
require 'nilal/chunky'
|
3
|
-
require 'nilal/assert'
|
4
|
-
|
5
|
-
module Nilal
|
6
|
-
def capture (element,file_name)
|
7
|
-
x = element.native.location.x
|
8
|
-
y = element.native.location.y
|
9
|
-
width = element.native.size.width
|
10
|
-
height = element.native.size.height
|
11
|
-
path = "#{Capybara.save_and_open_page_path}/#{file_name}.png"
|
12
|
-
touch_file Capybara.save_and_open_page_path,"#{file_name}.png"
|
13
|
-
script =
|
14
|
-
"var nilal_element = document.getElementById('nilal_client');
|
15
|
-
if (nilal_element == null){
|
16
|
-
nilal_element = document.createElement('nilal_client');
|
17
|
-
nilal_element.id = 'nilal_client';
|
18
|
-
}
|
19
|
-
nilal_element.setAttribute('x', #{x});
|
20
|
-
nilal_element.setAttribute('y', #{y});
|
21
|
-
nilal_element.setAttribute('width', #{width});
|
22
|
-
nilal_element.setAttribute('height',#{height} );
|
23
|
-
nilal_element.setAttribute('path', '#{path}');
|
24
|
-
document.documentElement.appendChild(nilal_element);
|
25
|
-
var evt = document.createEvent('Events');
|
26
|
-
evt.initEvent('CatchNilal', true, false);
|
27
|
-
nilal_element.dispatchEvent(evt); "
|
28
|
-
script.delete!("\n")
|
29
|
-
Capybara.page.execute_script(script)
|
30
|
-
end
|
31
|
-
|
32
|
-
def touch_file (folder,file)
|
33
|
-
FileUtils.mkdir_p folder unless File.exists? folder
|
34
|
-
FileUtils.touch "#{folder}/#{file}"
|
35
|
-
end
|
36
|
-
include AssertNilal
|
37
|
-
end
|
1
|
+
require_relative 'nilal/capybara'
|
data/lib/nilal/appium.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'chunky'
|
2
|
+
|
3
|
+
module Appium
|
4
|
+
|
5
|
+
should_match_previous_screen_capture do
|
6
|
+
capture_screen "second"
|
7
|
+
actual_file = "#{Dir.pwd}/second.png"
|
8
|
+
expexcted_file = "#{Dir.pwd}/first.png"
|
9
|
+
diff_file = "#{Dir.pwd}/diff.png"
|
10
|
+
Chunk.new.compare actual_file,expexcted_file,diff_file
|
11
|
+
end
|
12
|
+
|
13
|
+
def capture_screen file = "first"
|
14
|
+
#code to capture image
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'chunky'
|
2
|
+
require_relative 'firefox_driver'
|
3
|
+
|
4
|
+
module Nilal
|
5
|
+
module Capybara
|
6
|
+
extend RSpec::Matchers::DSL
|
7
|
+
|
8
|
+
matcher :match_image do |expexcted_file|
|
9
|
+
expexcted_file = File.absolute_path expexcted_file
|
10
|
+
actual_file = File.absolute_path "tmp/app_#{File.basename(expexcted_file)}"
|
11
|
+
diff_file = File.absolute_path "tmp/app_diff_#{File.basename(expexcted_file)}"
|
12
|
+
FileUtils.touch actual_file
|
13
|
+
match_for_should do |node|
|
14
|
+
FirefoxDriver.capture node,actual_file
|
15
|
+
Chunk.matches? actual_file,expexcted_file,diff_file
|
16
|
+
end
|
17
|
+
match_for_should_not do |node|
|
18
|
+
FirefoxDriver.capture node,actual_file
|
19
|
+
!Chunk.matches? actual_file,expexcted_file,diff_file
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/nilal/chunky.rb
CHANGED
@@ -1,31 +1,39 @@
|
|
1
1
|
require 'chunky_png'
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
|
3
|
+
module Chunk
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def matches? actual_file,expexcted_file,diff_file
|
5
7
|
images = [
|
6
8
|
ChunkyPNG::Image.from_file(actual_file),
|
7
9
|
ChunkyPNG::Image.from_file(expexcted_file)
|
8
10
|
]
|
11
|
+
return false unless images.first.height == images.last.height && images.first.width == images.last.width
|
12
|
+
image_diff_count = compute_image_difference images.first,images.last,diff_file
|
13
|
+
image_diff_count == 0
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
9
17
|
|
18
|
+
def compute_image_difference image1,image2,diff_image
|
10
19
|
diff = 0
|
11
|
-
|
12
|
-
|
13
|
-
r_diff = r(pixel) + r(
|
14
|
-
g_diff = g(pixel) + g(
|
15
|
-
b_diff = b(pixel) + b(
|
16
|
-
|
17
|
-
diff = r_diff + g_diff+b_diff
|
20
|
+
image1.height.times do |y|
|
21
|
+
image1.row(y).each_with_index do |pixel, x|
|
22
|
+
r_diff = r(pixel) + r(image2[x,y]) - 2 * [r(pixel), r(image2[x,y])].min
|
23
|
+
g_diff = g(pixel) + g(image2[x,y]) - 2 * [g(pixel), g(image2[x,y])].min
|
24
|
+
b_diff = b(pixel) + b(image2[x,y]) - 2 * [b(pixel), b(image2[x,y])].min
|
25
|
+
image2[x,y] = rgb(r_diff,g_diff,b_diff)
|
26
|
+
diff = diff + r_diff + g_diff+b_diff
|
18
27
|
end
|
19
28
|
end
|
20
|
-
|
21
|
-
diff
|
29
|
+
image2.save(diff_image)
|
30
|
+
return diff
|
22
31
|
end
|
23
|
-
|
24
|
-
private
|
32
|
+
|
25
33
|
def r (x)
|
26
34
|
ChunkyPNG::Color.r x
|
27
35
|
end
|
28
|
-
|
36
|
+
|
29
37
|
def g (x)
|
30
38
|
ChunkyPNG::Color.g x
|
31
39
|
end
|
@@ -33,7 +41,7 @@ class Chunk
|
|
33
41
|
def b (x)
|
34
42
|
ChunkyPNG::Color.b x
|
35
43
|
end
|
36
|
-
|
44
|
+
|
37
45
|
def rgb (r1,g1,b1)
|
38
46
|
ChunkyPNG::Color.rgb r1,g1,b1
|
39
47
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class FirefoxDriver
|
2
|
+
def self.capture element,file_name
|
3
|
+
x = element.native.location.x
|
4
|
+
y = element.native.location.y
|
5
|
+
width = element.native.size.width
|
6
|
+
height = element.native.size.height
|
7
|
+
script =
|
8
|
+
"var nilal_element = document.getElementById('nilal_client');
|
9
|
+
if (nilal_element == null){
|
10
|
+
nilal_element = document.createElement('nilal_client');
|
11
|
+
nilal_element.id = 'nilal_client';
|
12
|
+
}
|
13
|
+
nilal_element.setAttribute('x', #{x});
|
14
|
+
nilal_element.setAttribute('y', #{y});
|
15
|
+
nilal_element.setAttribute('width', #{width});
|
16
|
+
nilal_element.setAttribute('height',#{height} );
|
17
|
+
nilal_element.setAttribute('path', '#{file_name}');
|
18
|
+
document.documentElement.appendChild(nilal_element);
|
19
|
+
var evt = document.createEvent('Events');
|
20
|
+
evt.initEvent('CatchNilal', true, false);
|
21
|
+
nilal_element.dispatchEvent(evt); "
|
22
|
+
script.delete!("\n")
|
23
|
+
Capybara.page.execute_script(script)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nilal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- deepak p
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -117,8 +117,10 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- README.md
|
119
119
|
- lib/nilal.rb
|
120
|
-
- lib/nilal/
|
120
|
+
- lib/nilal/appium.rb
|
121
|
+
- lib/nilal/capybara.rb
|
121
122
|
- lib/nilal/chunky.rb
|
123
|
+
- lib/nilal/firefox_driver.rb
|
122
124
|
- lib/nilal/nilal.xpi
|
123
125
|
homepage: https://github.com/paramadeep/nilal_rb
|
124
126
|
licenses:
|
data/lib/nilal/assert.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module AssertNilal
|
2
|
-
extend RSpec::Matchers::DSL
|
3
|
-
|
4
|
-
matcher :match_image do |text|
|
5
|
-
match_for_should { |node|
|
6
|
-
capture node,text
|
7
|
-
compare_image text
|
8
|
-
}
|
9
|
-
match_for_should_not { |node|
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
def compare_image file_name
|
14
|
-
actual_file = "#{Dir.pwd}/features/images/#{file_name}.png"
|
15
|
-
expexcted_file = "#{Capybara.save_and_open_page_path}/#{file_name}.png"
|
16
|
-
diff_file = "#{Capybara.save_and_open_page_path}/#{file_name}_diff.png"
|
17
|
-
Chunk.new.compare actual_file,expexcted_file,diff_file
|
18
|
-
end
|
19
|
-
end
|