Sha256: c7bd6537f47f10e7d246324bcc298e31022cef6f561960a18fa84b97e5acc6d2

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 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
      false
    end

    def status
      status_span.text
    end

    private

    def status_span
      unless @switched
        @browser.switch_to.frame("0")
        @switched = true
      end

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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jstd-runner-0.0.2 lib/jstd-runner/browser.rb