watir-screenshot-stitch 0.6.0 → 0.6.1

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
  SHA256:
3
- metadata.gz: 92bd32049ae37743fbf4d85d5e0605545c04c8e3c3b02496800855dca356a5fe
4
- data.tar.gz: 2fa11c2db26b151da4c4377b1dc065a3a1b259be3d2878e8f50bddcb612fb240
3
+ metadata.gz: 11dc7b41716e02d099aa0cd4a1b183bb124bbd6f1e7ff36456429a869ce3cee9
4
+ data.tar.gz: 31a582be0b3e81069f969d8a5d0a6e73a2ae56d93325a33596116b30bf041afd
5
5
  SHA512:
6
- metadata.gz: a5c6f4630eecdff250fb6dc314b93a2bb43059d141162edddfbf358bfb0fdf3ebfff8847dd7b31be37406914743f55ada1670cd173a8bc86f93e3a38870a1835
7
- data.tar.gz: 5146d05f28946fd6b759de35f382339ff990e2e3005461945085a199eea4dd0f89d102800fd19e6e3bcab561343de0fd521ae1dfae7fefe169e9617ee0d4dfb0
6
+ metadata.gz: 59e26aad22da63937756e9bb92ff40a7e3683f7f7d667e733b58ca34a4af067727bfb78cbde5ca59244e4f0cc55255e9ba0fefd3ddd32d02b81e56dc9b16a0fd
7
+ data.tar.gz: '05085b5b810fe3294b797301ec8cd7290ef9724c263b5bb3ef4260d22df1ed783e26352507105287dc19c0f440b19d6c833db408d8632f210c586d6708c7ac81'
@@ -7,6 +7,7 @@ require "base64"
7
7
 
8
8
  MINIMAGICK_PIXEL_DIMENSION_LIMIT = 65500
9
9
  MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME = 120
10
+ RANGE_MOD = 0.02
10
11
 
11
12
  module Watir
12
13
  class Screenshot
@@ -27,13 +28,12 @@ module Watir
27
28
  @options = opts
28
29
  @path = path
29
30
  @browser = browser
30
-
31
31
  calculate_dimensions
32
32
 
33
- build_canvas
33
+ return self.save(@path) if (one_shot? || bug_shot?)
34
34
 
35
+ build_canvas
35
36
  gather_slices
36
-
37
37
  stitch_together
38
38
 
39
39
  @combined_screenshot.write @path
@@ -56,19 +56,9 @@ module Watir
56
56
  @browser = browser
57
57
  output = nil
58
58
 
59
- h2c_payload = get_html2canvas
60
- @browser.execute_script h2c_payload
61
-
62
- h2c_activator = %<
63
- function genScreenshot () {
64
- var canvasImgContentDecoded;
65
- html2canvas(document.body, {
66
- onrendered: function (canvas) {
67
- window.canvasImgContentDecoded = canvas.toDataURL("image/png");
68
- }});
69
- };
70
- genScreenshot();
71
- >.gsub(/\s+/, ' ').strip
59
+ return self.base64 if one_shot? || bug_shot?
60
+
61
+ @browser.execute_script html2canvas_payload
72
62
  @browser.execute_script h2c_activator
73
63
 
74
64
  @browser.wait_until(timeout: MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME) {
@@ -77,20 +67,45 @@ module Watir
77
67
 
78
68
  raise "Could not generate screenshot blob within #{MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME} seconds" unless output
79
69
 
80
- output.sub!(/^data\:image\/png\;base64,/, '')
81
-
82
- return output
70
+ return output.sub!(/^data\:image\/png\;base64,/, '')
83
71
  end
84
72
 
85
73
  private
86
- def get_html2canvas
74
+ def one_shot?
75
+ calculate_dimensions unless @loops && @remainder
76
+ ( (@loops == 1) && (@remainder == 0) )
77
+ end
78
+
79
+ def bug_shot?
80
+ calculate_dimensions unless @page_height
81
+
82
+ image = MiniMagick::Image.read(Base64.decode64(self.base64))
83
+ range = [
84
+ ( @page_height.to_f - (@page_height.to_f * RANGE_MOD) ).to_i,
85
+ ( @page_height.to_f + (@page_height.to_f * RANGE_MOD) ).to_i
86
+ ]
87
+ image.height.between? *range
88
+ end # https://github.com/mozilla/geckodriver/issues/1129
89
+
90
+ def h2c_activator
91
+ %<
92
+ function genScreenshot () {
93
+ var canvasImgContentDecoded;
94
+ html2canvas(document.body, {
95
+ onrendered: function (canvas) {
96
+ window.canvasImgContentDecoded = canvas.toDataURL("image/png");
97
+ }});
98
+ };
99
+ genScreenshot();
100
+ >.gsub(/\s+/, ' ').strip
101
+ end
102
+
103
+ def html2canvas_payload
87
104
  path = File.join(Dir.pwd, "vendor/html2canvas.js")
88
105
  File.read(path)
89
106
  end
90
107
 
91
108
  def calculate_dimensions
92
- @start = MiniMagick::Image.read(Base64.decode64(self.base64))
93
-
94
109
  @viewport_height = (@browser.execute_script "return window.innerHeight").to_f.to_i
95
110
  @page_height = (@browser.execute_script "return Math.max( document.documentElement.scrollHeight, document.documentElement.getBoundingClientRect().height )").to_f.to_i
96
111
 
@@ -106,7 +121,7 @@ module Watir
106
121
  def limit_page_height
107
122
  @original_page_height = @page_height
108
123
 
109
- if @options[:page_height_limit] && ("#{@options[:page_height_limit]}".to_i > 0)
124
+ if @options && ("#{@options[:page_height_limit]}".to_i > 0)
110
125
  @page_height = [@options[:page_height_limit], @page_height].min
111
126
  end
112
127
 
@@ -116,6 +131,7 @@ module Watir
116
131
  end
117
132
 
118
133
  def build_canvas
134
+ @start = MiniMagick::Image.read(Base64.decode64(self.base64))
119
135
  @combined_screenshot = MiniMagick::Image.new(@path)
120
136
  @combined_screenshot.run_command(:convert, "-size", "#{ @start.width }x#{ @page_height*@mac_factor }", "xc:white", @combined_screenshot.path)
121
137
  end
@@ -1,3 +1,3 @@
1
1
  module WatirScreenshotStitch
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir-screenshot-stitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Nissen