Class: Aquatone::Browser::Drivers::Nightmare

Inherits:
Object
  • Object
show all
Defined in:
lib/aquatone/browser/drivers/nightmare.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @url                    = url
  @vhost                  = vhost
  @html_destination       = html_destination
  @headers_destination    = headers_destination
  @screenshot_destination = screenshot_destination
  @options                = options
end

Instance Attribute Details

#headers_destinationObject (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_destinationObject (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

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/aquatone/browser/drivers/nightmare.rb', line 8

def options
  @options
end

#screenshot_destinationObject (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

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/aquatone/browser/drivers/nightmare.rb', line 8

def url
  @url
end

#vhostObject (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

#visitObject



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(options[: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.message}",
    "code"    => 0,
    "details" => ""
  }
end