Class: JstdRunner::Browser

Inherits:
Object
  • Object
show all
Includes:
Monitorable
Defined in:
lib/jstd-runner/browser.rb

Instance Method Summary collapse

Methods included from Monitorable

#monitor

Constructor Details

#initialize(type = :firefox) ⇒ Browser

Returns a new instance of Browser.



5
6
7
8
# File 'lib/jstd-runner/browser.rb', line 5

def initialize(type = :firefox)
  @type     = type
  @switched = @restarting = false
end

Instance Method Details

#capture(host, port) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/jstd-runner/browser.rb', line 15

def capture(host, port)
  @restarting = true
  @switched = false
  start unless @browser
  @browser.get "http://#{host}:#{port}/capture"
  @restarting = false
end

#restartObject



23
24
25
26
27
28
29
30
# File 'lib/jstd-runner/browser.rb', line 23

def restart
  @restarting = true
  Log.info "restarting browser - #{@type}"
  stop rescue nil
  @switched = false
  start
  @restarting = false
end

#running?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/jstd-runner/browser.rb', line 39

def running?
  Log.info "browser state: #{status}"
  true
rescue => ex
  Log.warn "#{self}#running? caught #{ex.message}"
  false
end

#startObject



10
11
12
13
# File 'lib/jstd-runner/browser.rb', line 10

def start
  Log.info "starting browser - #{@type}"
  @browser = Selenium::WebDriver.for @type
end

#statusObject



47
48
49
# File 'lib/jstd-runner/browser.rb', line 47

def status
  status_spans.map { |e| e.text }.inspect
end

#stopObject



32
33
34
35
36
37
# File 'lib/jstd-runner/browser.rb', line 32

def stop
  Log.info "stopping browser - #{@type}"
  @browser.quit if @browser
rescue Errno::ECONNREFUSED
  # looks like we're not running
end