watchdoge 0.0.22 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/watchdoge/configuration.rb +31 -11
- data/lib/watchdoge/install.rb +32 -5
- data/lib/watchdoge/notification.rb +2 -6
- data/lib/watchdoge/rails/generator.rb +4 -3
- data/lib/watchdoge/rails/railtie.rb +3 -3
- data/lib/watchdoge/{compare → regression}/dsl.rb +9 -5
- data/lib/watchdoge/{compare → regression}/utils.rb +5 -5
- data/lib/watchdoge/{compare.rb → regression.rb} +23 -24
- data/lib/watchdoge/version.rb +1 -1
- data/lib/watchdoge/worker.rb +4 -3
- data/lib/watchdoge.rb +6 -4
- data/watchdoge.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72caecca4e8bfaadd19424e647b0ddc3ff408b7d44b6f50c3941cd15fc2efcf5
|
4
|
+
data.tar.gz: df63f75a199c4840f3c5e8b175c264c11210952ec608a7b1397494c33f0a124f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2da1305c69374b490a4f7e06a8055e4994bfd9651263aba4e764eb9454027ce318673c531e031a2f6858623981d3e8cc059937fa8e4fa76616766017a86c2266
|
7
|
+
data.tar.gz: f53c2328b8479be6dd9e0379dc6deb47d2b40b7699970eaa62b5fe198929771bcefbb95322c2951e165e84c301c90daff5be8302e9290b5744492071062db294
|
@@ -2,6 +2,24 @@ require 'watir'
|
|
2
2
|
|
3
3
|
module WatchDoge
|
4
4
|
class Configuration
|
5
|
+
class Hooks
|
6
|
+
attr_accessor :sign_in
|
7
|
+
attr_accessor :sign_out
|
8
|
+
attr_accessor :before_regression
|
9
|
+
attr_accessor :after_regression
|
10
|
+
attr_accessor :before_scenario
|
11
|
+
attr_accessor :after_scenario
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@sign_in = -> (worker, resource) {}
|
15
|
+
@sign_out = -> (worker, resource) {}
|
16
|
+
@before_regression = -> {}
|
17
|
+
@after_regression = -> {}
|
18
|
+
@before_scenario = -> {}
|
19
|
+
@after_scenario = -> {}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
5
23
|
attr_accessor :base_dir
|
6
24
|
|
7
25
|
attr_accessor :web_drivers_dir
|
@@ -12,9 +30,13 @@ module WatchDoge
|
|
12
30
|
|
13
31
|
attr_accessor :notifications
|
14
32
|
|
15
|
-
attr_accessor :
|
16
|
-
attr_accessor :
|
17
|
-
|
33
|
+
attr_accessor :host
|
34
|
+
attr_accessor :regression_dir
|
35
|
+
|
36
|
+
attr_accessor :hooks
|
37
|
+
|
38
|
+
attr_accessor :chrome_version
|
39
|
+
attr_accessor :firefox_version
|
18
40
|
|
19
41
|
def initialize
|
20
42
|
@base_dir = Dir.pwd
|
@@ -44,21 +66,19 @@ module WatchDoge
|
|
44
66
|
# }
|
45
67
|
}
|
46
68
|
|
47
|
-
@
|
69
|
+
@host = ''
|
48
70
|
|
49
|
-
@
|
71
|
+
@regression_dir =
|
50
72
|
if defined?(Rails)
|
51
73
|
@base_dir + "/test/watchdoge"
|
52
74
|
else
|
53
75
|
@base_dir + "/watchdoge"
|
54
76
|
end
|
55
77
|
|
56
|
-
@
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
}
|
61
|
-
}
|
78
|
+
@hooks = WatchDoge::Configuration::Hooks.new
|
79
|
+
|
80
|
+
@chrome_version = nil
|
81
|
+
@firefox_version = nil
|
62
82
|
end
|
63
83
|
end
|
64
84
|
end
|
data/lib/watchdoge/install.rb
CHANGED
@@ -2,12 +2,39 @@ require 'net_http_ssl_fix'
|
|
2
2
|
require 'webdrivers'
|
3
3
|
|
4
4
|
module WatchDoge
|
5
|
-
class
|
6
|
-
|
7
|
-
|
5
|
+
class InstallManager
|
6
|
+
attr_reader :driver
|
7
|
+
attr_reader :install_version
|
8
|
+
attr_reader :install_path
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
def initialize browser
|
11
|
+
@driver =
|
12
|
+
case browser
|
13
|
+
when :chrome
|
14
|
+
Webdrivers::Chromedriver
|
15
|
+
when :firefox
|
16
|
+
Webdrivers::Geckodriver
|
17
|
+
end
|
18
|
+
|
19
|
+
@install_version = (eval "WatchDoge.configuration.#{browser}_version") || @driver.latest_version.to_s
|
20
|
+
|
21
|
+
@install_path = "#{WatchDoge.configuration.web_drivers_dir}/#{browser}/#{@install_version}/"
|
22
|
+
Webdrivers.install_dir = @install_path
|
23
|
+
|
24
|
+
@driver.required_version = @install_version
|
25
|
+
|
26
|
+
@driver.update
|
27
|
+
|
28
|
+
klass = "Selenium::WebDriver::#{browser.to_s.split('_').collect(&:capitalize).join}::Service".constantize
|
29
|
+
binary =
|
30
|
+
case browser
|
31
|
+
when :chrome
|
32
|
+
"chromedriver"
|
33
|
+
when :firefox
|
34
|
+
"geckodriver"
|
35
|
+
end
|
36
|
+
|
37
|
+
klass.driver_path = "#{@install_path}/#{binary}"
|
11
38
|
end
|
12
39
|
end
|
13
40
|
end
|
@@ -18,12 +18,8 @@ module WatchDoge
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def get_source_class source_sym
|
21
|
-
|
22
|
-
|
23
|
-
WatchDoge::Notification::Slack
|
24
|
-
when :matter_most
|
25
|
-
WatchDoge::Notification::MatterMost
|
26
|
-
end
|
21
|
+
klass = source_sym.to_s.split('_').collect(&:capitalize).join
|
22
|
+
"WatchDoge::Notification::#{klass}".constantize
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
@@ -3,11 +3,12 @@ module WatchDoge
|
|
3
3
|
namespace 'watchdoge'
|
4
4
|
argument :secenario
|
5
5
|
|
6
|
+
|
6
7
|
def create_watchdoge_file
|
7
8
|
configuration = WatchDoge.configuration
|
8
|
-
|
9
|
+
empty_directory "#{configuration.cookie_pool}"
|
9
10
|
|
10
|
-
create_file "#{configuration.
|
11
|
+
create_file "#{configuration.regression_dir}/scenarios/#{secenario}.rb", <<~DSL
|
11
12
|
# use :chrome
|
12
13
|
|
13
14
|
# compare 'some url'
|
@@ -19,7 +20,7 @@ module WatchDoge
|
|
19
20
|
#
|
20
21
|
DSL
|
21
22
|
|
22
|
-
|
23
|
+
empty_directory "#{configuration.regression_dir}/reference/#{secenario}"
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -10,11 +10,11 @@ module WatchDoge
|
|
10
10
|
end
|
11
11
|
desc "generating reference images"
|
12
12
|
task :make_reference => :environment do
|
13
|
-
WatchDoge::
|
13
|
+
WatchDoge::Regression::Manager.make_reference
|
14
14
|
end
|
15
15
|
desc "scrap screenshots and compare with reference images"
|
16
|
-
task :
|
17
|
-
WatchDoge::
|
16
|
+
task :regression => :environment do
|
17
|
+
WatchDoge::Regression::Manager.regression
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module WatchDoge
|
2
|
-
module
|
2
|
+
module Regression
|
3
3
|
module DSL
|
4
4
|
def use browser
|
5
5
|
puts "[use] browser #{browser}"
|
@@ -8,11 +8,15 @@ module WatchDoge
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def sign_in_as resoruce
|
11
|
+
|
11
12
|
puts "[sign_in_as] #{resoruce}"
|
12
|
-
|
13
|
+
WatchDoge.hooks.sign_in.call(@worker, resoruce)
|
14
|
+
|
15
|
+
return unless block_given?
|
16
|
+
|
13
17
|
yield(@worker)
|
14
18
|
puts "sign_out #{resoruce}"
|
15
|
-
|
19
|
+
WatchDoge.hooks.sign_out.call(@worker, resoruce)
|
16
20
|
end
|
17
21
|
|
18
22
|
def with_viewport **kwargs
|
@@ -22,7 +26,7 @@ module WatchDoge
|
|
22
26
|
end
|
23
27
|
|
24
28
|
def compare path, **kwargs
|
25
|
-
path = URI.join(WatchDoge.configuration.
|
29
|
+
path = URI.join(WatchDoge.configuration.host, path).to_s
|
26
30
|
|
27
31
|
@reference_file_name =
|
28
32
|
if kwargs[:with]
|
@@ -50,7 +54,7 @@ module WatchDoge
|
|
50
54
|
end
|
51
55
|
|
52
56
|
@worker.resize_by_document(@view_port) do
|
53
|
-
@
|
57
|
+
@regression_proc.call(@worker)
|
54
58
|
end
|
55
59
|
|
56
60
|
@teardown_proc.call if @teardown_proc
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'digest'
|
2
2
|
|
3
3
|
module WatchDoge
|
4
|
-
module
|
4
|
+
module Regression
|
5
5
|
module Utils
|
6
6
|
def load_png input
|
7
7
|
raise 'Invalid Input' unless input.respond_to? :length
|
@@ -18,16 +18,16 @@ module WatchDoge
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
WatchDoge.configuration.
|
21
|
+
def regression_dir
|
22
|
+
WatchDoge.configuration.regression_dir
|
23
23
|
end
|
24
24
|
|
25
25
|
def scenarios_dir
|
26
|
-
"#{
|
26
|
+
"#{regression_dir}/scenarios"
|
27
27
|
end
|
28
28
|
|
29
29
|
def reference_dir
|
30
|
-
"#{
|
30
|
+
"#{regression_dir}/reference"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -1,43 +1,49 @@
|
|
1
1
|
module WatchDoge
|
2
|
-
module
|
3
|
-
Dir["#{File.expand_path File.dirname(__FILE__)}/
|
2
|
+
module Regression
|
3
|
+
Dir["#{File.expand_path File.dirname(__FILE__)}/regression/*.rb"].each {|file| require file }
|
4
4
|
|
5
5
|
class Manager
|
6
|
-
extend WatchDoge::
|
7
|
-
include WatchDoge::
|
6
|
+
extend WatchDoge::Regression::Utils
|
7
|
+
include WatchDoge::Regression::DSL
|
8
8
|
|
9
9
|
class << self
|
10
|
-
def
|
11
|
-
|
12
|
-
run_all_scenarios
|
10
|
+
def regression
|
11
|
+
run_all_scenarios :regression
|
13
12
|
end
|
14
13
|
def make_reference
|
15
|
-
|
16
|
-
run_all_scenarios
|
14
|
+
run_all_scenarios :make_reference
|
17
15
|
end
|
18
16
|
|
19
17
|
private
|
20
18
|
|
21
|
-
def run_all_scenarios
|
19
|
+
def run_all_scenarios regression_flag
|
20
|
+
WatchDoge.hooks.before_regression.call
|
21
|
+
|
22
22
|
Dir["#{scenarios_dir}/*"].each do |scenario_path|
|
23
|
-
|
23
|
+
WatchDoge.hooks.before_scenario.call
|
24
|
+
|
25
|
+
mgr = self.new scenario_path, regression_flag: regression_flag
|
24
26
|
mgr.eval_scenario
|
27
|
+
|
28
|
+
WatchDoge.hooks.after_scenario.call
|
25
29
|
end
|
30
|
+
|
31
|
+
WatchDoge.hooks.after_regression.call
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
29
|
-
def initialize scenario_path
|
35
|
+
def initialize scenario_path, regression_flag:
|
30
36
|
@scenario_path = scenario_path
|
31
|
-
@scenario_name = File.basename scenario_path, '.rb'
|
37
|
+
@scenario_name = File.basename @scenario_path, '.rb'
|
32
38
|
|
33
|
-
case
|
39
|
+
case regression_flag
|
34
40
|
when :make_reference
|
35
|
-
@
|
41
|
+
@regression_proc = -> (worker) {
|
36
42
|
puts " -> make reference images on worker #{worker}"
|
37
43
|
worker.screenshot.save reference_image
|
38
44
|
}
|
39
|
-
when :
|
40
|
-
@
|
45
|
+
when :regression
|
46
|
+
@regression_proc = -> (worker) {
|
41
47
|
puts " -> compare reference images on worker #{worker}"
|
42
48
|
reference_image = self.class.load_png self.reference_image
|
43
49
|
cycle_image = self.class.load_png worker.screenshot.png
|
@@ -68,13 +74,6 @@ module WatchDoge
|
|
68
74
|
puts ""
|
69
75
|
end
|
70
76
|
|
71
|
-
def sign_in_proc
|
72
|
-
WatchDoge.configuration.user_authentication[:sign_in]
|
73
|
-
end
|
74
|
-
def sign_out_proc
|
75
|
-
WatchDoge.configuration.user_authentication[:sign_out]
|
76
|
-
end
|
77
|
-
|
78
77
|
def reference_image
|
79
78
|
self.class.reference_dir + "/#{@scenario_name}/#{@reference_file_name}.png"
|
80
79
|
end
|
data/lib/watchdoge/version.rb
CHANGED
data/lib/watchdoge/worker.rb
CHANGED
@@ -20,6 +20,7 @@ module WatchDoge
|
|
20
20
|
@landed_page = nil
|
21
21
|
|
22
22
|
# flag that cookie is loaded
|
23
|
+
@cookie_autosafe = false
|
23
24
|
@cookie_loaded = false
|
24
25
|
|
25
26
|
@width = default_opt[:width]
|
@@ -85,8 +86,6 @@ module WatchDoge
|
|
85
86
|
private
|
86
87
|
# callbacks before/after init
|
87
88
|
def _before_initialize
|
88
|
-
Selenium::WebDriver::Firefox::Service.driver_path = WatchDoge.configuration.web_drivers_dir + "/geckodriver"
|
89
|
-
Selenium::WebDriver::Chrome::Service.driver_path = WatchDoge.configuration.web_drivers_dir + "/chromedriver"
|
90
89
|
@http = Selenium::WebDriver::Remote::Http::Default.new
|
91
90
|
@browser = WatchDoge.configuration.browser
|
92
91
|
end
|
@@ -119,7 +118,9 @@ module WatchDoge
|
|
119
118
|
@cookie_loaded
|
120
119
|
end
|
121
120
|
def _save_cookie
|
122
|
-
|
121
|
+
if @cookie_autosafe
|
122
|
+
@core.cookies.save WatchDoge::CookiePool.source(@uuid, @landed_page)
|
123
|
+
end
|
123
124
|
end
|
124
125
|
def _load_cookie
|
125
126
|
source = WatchDoge::CookiePool.source(@uuid, @landed_page)
|
data/lib/watchdoge.rb
CHANGED
@@ -6,7 +6,7 @@ require 'watchdoge/cookie_pool'
|
|
6
6
|
require 'watchdoge/worker'
|
7
7
|
require 'watchdoge/notification'
|
8
8
|
require 'watchdoge/image_diff'
|
9
|
-
require 'watchdoge/
|
9
|
+
require 'watchdoge/regression'
|
10
10
|
require 'watchdoge/rails/railtie' if defined?(Rails)
|
11
11
|
require 'watchdoge/rails/generator' if defined?(Rails)
|
12
12
|
|
@@ -16,6 +16,10 @@ module WatchDoge
|
|
16
16
|
configuration.base_dir
|
17
17
|
end
|
18
18
|
|
19
|
+
def hooks
|
20
|
+
configuration.hooks
|
21
|
+
end
|
22
|
+
|
19
23
|
def configure(&block)
|
20
24
|
yield(configuration)
|
21
25
|
configuration
|
@@ -25,7 +29,7 @@ module WatchDoge
|
|
25
29
|
@_configuration ||= Configuration.new
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
32
|
+
def initialize!
|
29
33
|
path = ENV['WATCHDOGE_CONFIG'] ||
|
30
34
|
if defined?(Rails)
|
31
35
|
"#{Dir.pwd}/config/watchdoge.rb"
|
@@ -37,5 +41,3 @@ module WatchDoge
|
|
37
41
|
end
|
38
42
|
end
|
39
43
|
end
|
40
|
-
|
41
|
-
WatchDoge.load_configuration
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shen Lee
|
@@ -112,9 +112,6 @@ 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
|
118
115
|
- lib/watchdoge/configuration.rb
|
119
116
|
- lib/watchdoge/cookie_pool.rb
|
120
117
|
- lib/watchdoge/image_diff.rb
|
@@ -124,6 +121,9 @@ files:
|
|
124
121
|
- lib/watchdoge/notification/slack.rb
|
125
122
|
- lib/watchdoge/rails/generator.rb
|
126
123
|
- lib/watchdoge/rails/railtie.rb
|
124
|
+
- lib/watchdoge/regression.rb
|
125
|
+
- lib/watchdoge/regression/dsl.rb
|
126
|
+
- lib/watchdoge/regression/utils.rb
|
127
127
|
- lib/watchdoge/version.rb
|
128
128
|
- lib/watchdoge/worker.rb
|
129
129
|
- watchdoge.gemspec
|