Sha256: b7bb40f7c45bfcd4cf3f967c2b9af3f73de7e68b0ecf7f54ecf68351f06cdef7

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

module JstdRunner
  class Browser
    include Monitorable

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

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

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

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

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

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

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

    private

    def status_spans
      unless @switched
        @browser.switch_to.frame(@browser.find_element(:tag_name => "frame"))
        @switched = true
      end

      @browser.find_elements(:tag_name => "span")
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jstd-runner-0.0.9 lib/jstd-runner/browser.rb
jstd-runner-0.0.8 lib/jstd-runner/browser.rb
jstd-runner-0.0.7 lib/jstd-runner/browser.rb
jstd-runner-0.0.6 lib/jstd-runner/browser.rb
jstd-runner-0.0.5 lib/jstd-runner/browser.rb
jstd-runner-0.0.4 lib/jstd-runner/browser.rb
jstd-runner-0.0.3 lib/jstd-runner/browser.rb