watchdoge 0.0.3 → 0.0.4
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 +4 -4
- data/.gitignore +2 -0
- data/lib/watchdoge/compare/dsl.rb +53 -0
- data/lib/watchdoge/compare/utils.rb +34 -0
- data/lib/watchdoge/compare.rb +76 -0
- data/lib/watchdoge/configuration.rb +31 -3
- data/lib/watchdoge/image_diff.rb +10 -7
- data/lib/watchdoge/install.rb +2 -4
- data/lib/watchdoge/rails/generator.rb +23 -0
- data/lib/watchdoge/rails/railtie.rb +22 -0
- data/lib/watchdoge/version.rb +1 -1
- data/lib/watchdoge/worker.rb +3 -3
- data/lib/watchdoge.rb +3 -0
- data/watchdoge.gemspec +1 -1
- metadata +6 -2
- data/watchdoge-0.0.2.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71714f5bc076271d8af037b38803c0cf9a9c7cd6e5c175797f745dc2fd252a23
|
4
|
+
data.tar.gz: ec97e6dc2ee067065bc421381494053f60a8cee1b2045555149638f1dc1c5da9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aef4519d9442b54a1bf4f80ac7bb18423e65989be58007bcc591fe8db556676423c4c14e834f05c80bab2aac8eeda360ef70e1f0a3102912d2d027b34ba77ad
|
7
|
+
data.tar.gz: 8710792cc8b2d9cad0bd75be198dfda0c87a16d754a31abd4bffaed3bbc811149bea92b7b566136debec686d60ac2c1039e69f0ac8cc9f353fed44f6a254cab0
|
data/.gitignore
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
module WatchDoge
|
2
|
+
module Compare
|
3
|
+
module DSL
|
4
|
+
def use browser
|
5
|
+
puts "[use] browser #{browser}"
|
6
|
+
@worker.close
|
7
|
+
@worker = WatchDoge::Worker.new @scenario_name, browser: browser
|
8
|
+
end
|
9
|
+
|
10
|
+
def sign_in_as resoruce
|
11
|
+
puts "[sign_in_as] #{resoruce}"
|
12
|
+
sign_in_proc.call(@worker, resoruce)
|
13
|
+
yield(@worker)
|
14
|
+
puts "sign_out #{resoruce}"
|
15
|
+
sign_out_proc.call(@worker, resoruce)
|
16
|
+
end
|
17
|
+
|
18
|
+
def compare path, **kwargs
|
19
|
+
path = URI.join(WatchDoge.configuration.compare_host, path).to_s
|
20
|
+
@reference_file_name =
|
21
|
+
if kwargs[:with]
|
22
|
+
kwargs[:with]
|
23
|
+
else
|
24
|
+
path.gsub(/^.*(\\|\/)/, '')
|
25
|
+
end
|
26
|
+
|
27
|
+
puts "[compare] #{path} #{'[with]'+ @reference_file_name if kwargs[:with] }"
|
28
|
+
|
29
|
+
@setup_proc.call if @setup_proc
|
30
|
+
|
31
|
+
args = {
|
32
|
+
before: nil
|
33
|
+
}.merge(kwargs)
|
34
|
+
|
35
|
+
args[:before].call if args[:before]
|
36
|
+
|
37
|
+
@worker.goto path
|
38
|
+
|
39
|
+
@compare_proc.call(@worker)
|
40
|
+
|
41
|
+
@teardown_proc.call if @teardown_proc
|
42
|
+
end
|
43
|
+
|
44
|
+
def setup
|
45
|
+
@setup_proc = -> { yield }
|
46
|
+
end
|
47
|
+
|
48
|
+
def teardown
|
49
|
+
@teardown_proc = -> { yield }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module WatchDoge
|
4
|
+
module Compare
|
5
|
+
module Utils
|
6
|
+
def load_png input
|
7
|
+
raise 'Invalid Input' unless input.respond_to? :length
|
8
|
+
|
9
|
+
png_magic = ["89", "50", "4E", "47"]
|
10
|
+
|
11
|
+
is_png_blob =
|
12
|
+
(input.length > 3 && input[0..3].each_byte.map {|t| t.to_s(16).upcase} == png_magic)
|
13
|
+
|
14
|
+
if is_png_blob
|
15
|
+
ChunkyPNG::Image.from_blob input
|
16
|
+
else
|
17
|
+
ChunkyPNG::Image.from_file input
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def compare_dir
|
22
|
+
WatchDoge.configuration.compare_dir
|
23
|
+
end
|
24
|
+
|
25
|
+
def scenarios_dir
|
26
|
+
"#{compare_dir}/scenarios"
|
27
|
+
end
|
28
|
+
|
29
|
+
def reference_dir
|
30
|
+
"#{compare_dir}/reference"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module WatchDoge
|
2
|
+
module Compare
|
3
|
+
Dir["#{File.expand_path File.dirname(__FILE__)}/compare/*.rb"].each {|file| require file }
|
4
|
+
|
5
|
+
class Manager
|
6
|
+
extend WatchDoge::Compare::Utils
|
7
|
+
include WatchDoge::Compare::DSL
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def compare_reference
|
11
|
+
@@compare_flag = :compare_reference
|
12
|
+
run_all_scenarios
|
13
|
+
end
|
14
|
+
def make_reference
|
15
|
+
@@compare_flag = :make_reference
|
16
|
+
run_all_scenarios
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def run_all_scenarios
|
22
|
+
Dir["#{scenarios_dir}/*"].each do |scenario_path|
|
23
|
+
mgr = self.new scenario_path
|
24
|
+
mgr.eval_scenario
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize scenario_path
|
30
|
+
@scenario_path = scenario_path
|
31
|
+
@scenario_name = File.basename scenario_path, '.rb'
|
32
|
+
|
33
|
+
case @@compare_flag
|
34
|
+
when :make_reference
|
35
|
+
@compare_proc = -> (worker) {
|
36
|
+
puts " -> with make reference on worker #{worker}"
|
37
|
+
worker.fullpage_screenshot.save reference_image
|
38
|
+
}
|
39
|
+
when :compare_reference
|
40
|
+
@compare_proc = -> (worker) {
|
41
|
+
puts " -> with co,pare reference on worker #{worker}"
|
42
|
+
reference_image = self.class.load_png self.reference_image
|
43
|
+
cycle_image = self.class.load_png worker.fullpage_screenshot.png
|
44
|
+
diff = WatchDoge::ImageDiff.diff(cycle_image, reference_image)
|
45
|
+
WatchDoge::Notification.push diff if diff
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
@setup_proc = nil
|
50
|
+
@teardown_proc = nil
|
51
|
+
|
52
|
+
@worker = WatchDoge::Worker.new @scenario_name
|
53
|
+
@_authorized = false
|
54
|
+
end
|
55
|
+
|
56
|
+
def eval_scenario
|
57
|
+
puts "scenario: #{@scenario_name} begin"
|
58
|
+
eval File.read(@scenario_path)
|
59
|
+
@worker.close
|
60
|
+
puts "scenario: #{@scenario_name} end\n"
|
61
|
+
puts ""
|
62
|
+
end
|
63
|
+
|
64
|
+
def sign_in_proc
|
65
|
+
WatchDoge.configuration.user_authentication[:sign_in]
|
66
|
+
end
|
67
|
+
def sign_out_proc
|
68
|
+
WatchDoge.configuration.user_authentication[:sign_out]
|
69
|
+
end
|
70
|
+
|
71
|
+
def reference_image
|
72
|
+
self.class.reference_dir + "/#{@scenario_name}/#{@reference_file_name}.png"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -3,21 +3,33 @@ require 'watir'
|
|
3
3
|
module WatchDoge
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :base_dir
|
6
|
+
|
6
7
|
attr_accessor :web_drivers_dir
|
7
8
|
attr_accessor :engine
|
9
|
+
attr_accessor :browser
|
8
10
|
attr_accessor :cookie_pool
|
11
|
+
|
9
12
|
attr_accessor :notifications
|
10
13
|
|
14
|
+
attr_accessor :compare_host
|
15
|
+
attr_accessor :compare_dir
|
16
|
+
attr_accessor :user_authentication
|
17
|
+
|
11
18
|
def initialize
|
12
|
-
@base_dir =
|
19
|
+
@base_dir =
|
20
|
+
if defined?(Rails)
|
21
|
+
Rails.root.to_s
|
22
|
+
else
|
23
|
+
Dir.pwd
|
24
|
+
end
|
13
25
|
|
14
26
|
@web_drivers_dir = @base_dir + "/.webdrivers"
|
27
|
+
@engine = Watir::Browser
|
28
|
+
@browser = :firefox
|
15
29
|
|
16
30
|
# cuurently using local fs, probably support NoSQL also maybe?
|
17
31
|
@cookie_pool = @base_dir + '/.doge_cookie'
|
18
32
|
|
19
|
-
@engine = Watir::Browser
|
20
|
-
|
21
33
|
@notifications = {
|
22
34
|
# slack: {
|
23
35
|
# incoming_url: SLACK_WEBHOOK
|
@@ -33,6 +45,22 @@ module WatchDoge
|
|
33
45
|
# auth_token: 'AUTH_TOKEN'
|
34
46
|
# }
|
35
47
|
}
|
48
|
+
|
49
|
+
@compare_host = ''
|
50
|
+
|
51
|
+
@compare_dir =
|
52
|
+
if defined?(Rails)
|
53
|
+
@base_dir + "/test/watchdoge"
|
54
|
+
else
|
55
|
+
@base_dir + "/watchdoge"
|
56
|
+
end
|
57
|
+
|
58
|
+
@user_authentication = {
|
59
|
+
sign_in: -> (worker, resource) {
|
60
|
+
},
|
61
|
+
sign_out: -> (worker, resource) {
|
62
|
+
}
|
63
|
+
}
|
36
64
|
end
|
37
65
|
end
|
38
66
|
end
|
data/lib/watchdoge/image_diff.rb
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
module WatchDoge
|
2
2
|
module ImageDiff
|
3
|
-
OPACITY = 0.
|
3
|
+
OPACITY = 0.7
|
4
4
|
HIGHLIGHT_COLOR = "#F163FF#{(OPACITY * 256).to_i.to_s(16).upcase}"
|
5
5
|
|
6
6
|
class << self
|
7
|
-
def diff input_image,
|
8
|
-
return nil if input_image.pixels.hash ==
|
7
|
+
def diff input_image, reference_image
|
8
|
+
return nil if input_image.pixels.hash == reference_image.pixels.hash
|
9
9
|
|
10
10
|
input_image.height.times do |y|
|
11
11
|
pixels = input_image.row(y)
|
12
12
|
|
13
|
-
if y >=
|
13
|
+
if y >= reference_image.height
|
14
14
|
pixels.each_with_index do |pixel, x|
|
15
15
|
input_image.compose_pixel(x, y, HIGHLIGHT_COLOR)
|
16
16
|
end
|
17
17
|
else
|
18
|
-
|
18
|
+
reference_pixels = reference_image.row(y)
|
19
19
|
|
20
|
-
next if (pixels.hash ==
|
20
|
+
next if (pixels.hash == reference_pixels.hash)
|
21
21
|
|
22
22
|
pixels.each_with_index do |pixel, x|
|
23
|
-
|
23
|
+
if pixels[x] != reference_pixels[x]
|
24
|
+
input_image.compose_pixel(x, y, reference_pixels[x])
|
25
|
+
input_image.compose_pixel(x, y, HIGHLIGHT_COLOR)
|
26
|
+
end
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
data/lib/watchdoge/install.rb
CHANGED
@@ -3,13 +3,11 @@ require 'webdrivers'
|
|
3
3
|
|
4
4
|
module WatchDoge
|
5
5
|
class << self
|
6
|
-
def
|
6
|
+
def install_webdriver
|
7
7
|
Webdrivers.install_dir = configuration.web_drivers_dir
|
8
8
|
|
9
|
-
# TODO: Support other browser maybe?
|
10
9
|
Webdrivers::Geckodriver.update
|
11
|
-
|
12
|
-
Dir.mkdir configuration.cookie_pool unless File.directory? configuration.cookie_pool
|
10
|
+
Webdrivers::Chromedriver.update
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module WatchDoge
|
2
|
+
class WatchDogeGenerator < Rails::Generators::Base
|
3
|
+
namespace 'watchdoge'
|
4
|
+
argument :secenario
|
5
|
+
|
6
|
+
def create_watchdoge_file
|
7
|
+
configuration = WatchDoge.configuration
|
8
|
+
create_file "#{configuration.cookie_pool}/.placeholder"
|
9
|
+
|
10
|
+
create_file "#{configuration.compare_dir}/scenarios/#{secenario}.rb", <<~DSL
|
11
|
+
# compare 'some url'
|
12
|
+
# compare 'some url', with: 'some'
|
13
|
+
|
14
|
+
# sign_in_as 'resource' do
|
15
|
+
# compare 'some url', with: 'test'
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
DSL
|
19
|
+
|
20
|
+
create_file "#{configuration.compare_dir}/reference/#{secenario}/.placeholder"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "rails"
|
2
|
+
|
3
|
+
module WatchDoge
|
4
|
+
class WatchDogeTask < Rails::Railtie
|
5
|
+
rake_tasks do
|
6
|
+
namespace :watchdoge do
|
7
|
+
desc "install web drivers"
|
8
|
+
task :install_webdrivers => :environment do
|
9
|
+
WatchDoge.install_webdriver
|
10
|
+
end
|
11
|
+
desc "generating reference images"
|
12
|
+
task :make_reference => :environment do
|
13
|
+
WatchDoge::Compare::Manager.make_reference
|
14
|
+
end
|
15
|
+
desc "scrap screenshots and compare with reference images"
|
16
|
+
task :compare => :environment do
|
17
|
+
WatchDoge::Compare::Manager.compare_reference
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/watchdoge/version.rb
CHANGED
data/lib/watchdoge/worker.rb
CHANGED
@@ -26,10 +26,10 @@ module WatchDoge
|
|
26
26
|
default_opt = {
|
27
27
|
width: 1024,
|
28
28
|
height: 768,
|
29
|
-
headless: true
|
29
|
+
headless: true,
|
30
|
+
browser: WatchDoge.configuration.browser
|
30
31
|
}.merge(opt)
|
31
|
-
|
32
|
-
@core = WatchDoge.configuration.engine.new :firefox, default_opt
|
32
|
+
@core = WatchDoge.configuration.engine.new default_opt[:browser], default_opt
|
33
33
|
|
34
34
|
# for generate uri hash
|
35
35
|
@landed_page = nil
|
data/lib/watchdoge.rb
CHANGED
@@ -6,6 +6,9 @@ require 'watchdoge/cookie_pool'
|
|
6
6
|
require 'watchdoge/worker'
|
7
7
|
require 'watchdoge/notification'
|
8
8
|
require 'watchdoge/image_diff'
|
9
|
+
require 'watchdoge/compare'
|
10
|
+
require 'watchdoge/rails/railtie' if defined?(Rails)
|
11
|
+
require 'watchdoge/rails/generator' if defined?(Rails)
|
9
12
|
|
10
13
|
module WatchDoge
|
11
14
|
class << self
|
data/watchdoge.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watchdoge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shen Lee
|
@@ -112,6 +112,9 @@ extra_rdoc_files: []
|
|
112
112
|
files:
|
113
113
|
- ".gitignore"
|
114
114
|
- lib/watchdoge.rb
|
115
|
+
- lib/watchdoge/compare.rb
|
116
|
+
- lib/watchdoge/compare/dsl.rb
|
117
|
+
- lib/watchdoge/compare/utils.rb
|
115
118
|
- lib/watchdoge/configuration.rb
|
116
119
|
- lib/watchdoge/cookie_pool.rb
|
117
120
|
- lib/watchdoge/image_diff.rb
|
@@ -119,9 +122,10 @@ files:
|
|
119
122
|
- lib/watchdoge/notification.rb
|
120
123
|
- lib/watchdoge/notification/matter_most.rb
|
121
124
|
- lib/watchdoge/notification/slack.rb
|
125
|
+
- lib/watchdoge/rails/generator.rb
|
126
|
+
- lib/watchdoge/rails/railtie.rb
|
122
127
|
- lib/watchdoge/version.rb
|
123
128
|
- lib/watchdoge/worker.rb
|
124
|
-
- watchdoge-0.0.2.gem
|
125
129
|
- watchdoge.gemspec
|
126
130
|
homepage:
|
127
131
|
licenses:
|
data/watchdoge-0.0.2.gem
DELETED
Binary file
|