Class: CapCap::Main

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL
Defined in:
lib/cap_cap.rb

Instance Method Summary collapse

Instance Method Details

#add_headers(headers) ⇒ Object



84
85
86
# File 'lib/cap_cap.rb', line 84

def add_headers headers
  page.driver.add_headers headers
end

#capture(url, output = nil, selector: nil) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/cap_cap.rb', line 58

def capture url, output = nil, selector: nil
  visit url
  output = Tempfile.open(["capcap", ".png"]).path if output.nil?
  opt = if selector.nil? then {full: true} else {selector: selector} end
  save_screenshot output, opt
  output
end

#capture_combined(outputs, output = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cap_cap.rb', line 71

def capture_combined outputs, output = nil
  visit "about:blank"
  output = Tempfile.open(["capcap", ".png"]).path if output.nil?

  imgs = outputs.map {|src| %Q|<img src="file://#{src}" />| }
  html = %Q|<table id="canvas" border=0><tr><td valign=top>#{imgs.join("</td><td valign=top>")}</td></tr></table>|
  script = %Q|document.body.innerHTML = '#{html}';|
  evaluate_script script

  save_screenshot output, selector: "#canvas"
  output
end

#invoke_open(path) ⇒ Object



66
67
68
69
# File 'lib/cap_cap.rb', line 66

def invoke_open path
  `open #{path}`
  sleep 2
end

#resize(w, h) ⇒ Object



88
89
90
# File 'lib/cap_cap.rb', line 88

def resize w, h
  page.driver.resize w, h
end