Class: Watir::Screenshot

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-screenshot-stitch.rb

Instance Method Summary collapse

Instance Method Details

#base64_canvasString

Deprecated.

@param [Watir::Browser] browser

Employs html2canvas to produce a Base64 encoded string of a full page screenshot.

Examples:

browser.screenshot.base64_canvas(browser)
#=> '7HWJ43tZDscPleeUuPW6HhN3x+z7vU/lufmH0qNTtTum94IBWMT46evImci1vnFGT'


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/watir-screenshot-stitch.rb', line 85

def base64_canvas
  return self.base64 if base64_capable?
  output = nil

  return self.base64 if one_shot? || bug_shot?

  @browser.execute_script html2canvas_payload
  @browser.execute_script h2c_activator

  @browser.wait_until(timeout: MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME) {
    output = @browser.execute_script "return window.canvasImgContentDecoded;"
  }

  raise "Could not generate screenshot blob within #{MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME} seconds" unless output

  output.sub!(/^data\:image\/png\;base64,/, '')
end

#base64_geckodriverString

Employs a cutting edge feature in geckodriver version 0.24.0 to produce a Base64 encoded string of a full page screenshot.

Examples:

browser.screenshot.base64_geckodriver
#=> '7HWJ43tZDscPleeUuPW6HhN3x+z7vU/lufmH0qNTtTum94IBWMT46evImci1vnFGT'


33
34
35
36
37
38
39
40
41
# File 'lib/watir-screenshot-stitch.rb', line 33

def base64_geckodriver
  ensure_geckodriver

  resource_url = build_driver_url

  raw = request_payload(resource_url)

  parse_gecko(raw)
end

#save_stitch(path, opts = {}) ⇒ Object

Deprecated.

@param [Watir::Browser] browser

Represents stitched together screenshot and writes to file.

Examples:

opts = {:page_height_limit => 5000}
browser.screenshot.save_stitch("path/abc.png", browser, opts)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/watir-screenshot-stitch.rb', line 56

def save_stitch(path, opts = {})
  return @browser.screenshot.save(path) if base64_capable?
  @options = opts
  @path = path
  calculate_dimensions

  return self.save(@path) if (one_shot? || bug_shot?)

  build_canvas
  gather_slices
  stitch_together

  @combined_screenshot.write @path
end