Sha256: 478e89c2936075e697ead2488969dafe861c0e71e87dcc47588f3b562d044f88

Contents?: true

Size: 1.38 KB

Versions: 10

Compression:

Stored size: 1.38 KB

Contents

module Speedos
  class Page
    def server
      if !@server
        @server = BrowserMob::Proxy::Server.new(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'browsermob-proxy-2.0-beta-8', 'bin', 'browsermob-proxy'))
        @server.start
      end
      @server
    end

    def server_proxy
      if !@proxy
        @proxy = server.create_proxy
      end
      @proxy
    end

    def get_har
      server_proxy.har
    end

    def new_har
      server_proxy.new_har "", capture_headers: true
    end

    def firefox_profile
      profile       = Selenium::WebDriver::Firefox::Profile.new
      profile.proxy = server_proxy.selenium_proxy
      profile["network.proxy.ssl"]      = server_proxy.host
      profile["network.proxy.ssl_port"] = server_proxy.port
      profile
    end

    def driver
      @driver ||= reset_driver
    end

    def reset_driver
      Capybara.register_driver :selenium do |app|
        http_client         = Selenium::WebDriver::Remote::Http::Default.new
        http_client.timeout = 300
        Capybara::Selenium::Driver.new(app,
          :profile     => firefox_profile,
          :http_client => http_client,
        )
      end
      Capybara.default_driver = :selenium
      @driver = Capybara::Session.new(:selenium)
    end

    def is value
      raise "Page name cannot be empty" if value.empty?
      server_proxy.new_page value
      yield
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
speedos-0.0.14 lib/speedos/page.rb
speedos-0.0.13 lib/speedos/page.rb
speedos-0.0.12 lib/speedos/page.rb
speedos-0.0.11 lib/speedos/page.rb
speedos-0.0.10 lib/speedos/page.rb
speedos-0.0.9 lib/speedos/page.rb
speedos-0.0.8 lib/speedos/page.rb
speedos-0.0.7 lib/speedos/page.rb
speedos-0.0.6 lib/speedos/page.rb
speedos-0.0.5 lib/speedos/page.rb