Class: Aquatone::Browser::Drivers::Nightmare
- Inherits:
-
Object
- Object
- Aquatone::Browser::Drivers::Nightmare
- Defined in:
- lib/aquatone/browser/drivers/nightmare.rb
Instance Attribute Summary collapse
-
#headers_destination ⇒ Object
readonly
Returns the value of attribute headers_destination.
-
#html_destination ⇒ Object
readonly
Returns the value of attribute html_destination.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#screenshot_destination ⇒ Object
readonly
Returns the value of attribute screenshot_destination.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#vhost ⇒ Object
readonly
Returns the value of attribute vhost.
Instance Method Summary collapse
-
#initialize(url, vhost, html_destination, headers_destination, screenshot_destination, options) ⇒ Nightmare
constructor
A new instance of Nightmare.
- #visit ⇒ Object
Constructor Details
#initialize(url, vhost, html_destination, headers_destination, screenshot_destination, options) ⇒ Nightmare
Returns a new instance of Nightmare.
10 11 12 13 14 15 16 17 |
# File 'lib/aquatone/browser/drivers/nightmare.rb', line 10 def initialize(url, vhost, html_destination, headers_destination, screenshot_destination, ) @url = url @vhost = vhost @html_destination = html_destination @headers_destination = headers_destination @screenshot_destination = screenshot_destination @options = end |
Instance Attribute Details
#headers_destination ⇒ Object (readonly)
Returns the value of attribute headers_destination.
8 9 10 |
# File 'lib/aquatone/browser/drivers/nightmare.rb', line 8 def headers_destination @headers_destination end |
#html_destination ⇒ Object (readonly)
Returns the value of attribute html_destination.
8 9 10 |
# File 'lib/aquatone/browser/drivers/nightmare.rb', line 8 def html_destination @html_destination end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/aquatone/browser/drivers/nightmare.rb', line 8 def @options end |
#screenshot_destination ⇒ Object (readonly)
Returns the value of attribute screenshot_destination.
8 9 10 |
# File 'lib/aquatone/browser/drivers/nightmare.rb', line 8 def screenshot_destination @screenshot_destination end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/aquatone/browser/drivers/nightmare.rb', line 8 def url @url end |
#vhost ⇒ Object (readonly)
Returns the value of attribute vhost.
8 9 10 |
# File 'lib/aquatone/browser/drivers/nightmare.rb', line 8 def vhost @vhost end |
Instance Method Details
#visit ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/aquatone/browser/drivers/nightmare.rb', line 19 def visit rout, wout = IO.pipe process = ChildProcess.build(*construct_command) process.cwd = Aquatone::AQUATONE_ROOT process.io.stdout = wout process.start process.poll_for_exit([:timeout]) wout.close command_output = rout.readlines.join("\n").strip JSON.parse(command_output) rescue JSON::ParserError fail IncompatabilityError, "Nightmarejs must be run on a system with a graphical desktop session (X11)" rescue => e process.stop if process return { "success" => false, "error" => e.is_a?(ChildProcess::TimeoutError) ? "Timeout" : "#{e.class}: #{e.}", "code" => 0, "details" => "" } end |