Class: WBench::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/wbench/browser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Browser

Returns a new instance of Browser.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/wbench/browser.rb', line 5

def initialize(url, options = {})
  Capybara.register_driver(CAPYBARA_DRIVER) do |app|
    http_client         = Selenium::WebDriver::Remote::Http::Default.new
    http_client.timeout = CAPYBARA_TIMEOUT
    browser             = (options[:browser] || DEFAULT_BROWSER).to_sym
    selenium_options    = { :browser => browser, :http_client => http_client }

    if options[:user_agent]
      add_selenium_args(selenium_options, "--user-agent='#{options[:user_agent]}'")
    end

    SeleniumDriver.new(app, selenium_options)
  end

  @url = Addressable::URI.parse(url).normalize.to_s
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/wbench/browser.rb', line 3

def url
  @url
end

Instance Method Details

#evaluate_script(script) ⇒ Object



30
31
32
# File 'lib/wbench/browser.rb', line 30

def evaluate_script(script)
  session.evaluate_script(script)
end

#run(&blk) ⇒ Object



34
35
36
# File 'lib/wbench/browser.rb', line 34

def run(&blk)
  session.instance_eval(&blk) if block_given?
end

#visitObject



22
23
24
25
26
27
28
# File 'lib/wbench/browser.rb', line 22

def visit
  session.visit(@url)
  wait_for_page
  session.execute_script(wbench_javascript)
  yield if block_given?
  close
end