Class: WBench::Browser
- Inherits:
-
Object
- Object
- WBench::Browser
- Defined in:
- lib/wbench/browser.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #evaluate_script(script) ⇒ Object
-
#initialize(url, options = {}) ⇒ Browser
constructor
A new instance of Browser.
- #run(&blk) ⇒ Object
- #visit ⇒ Object
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 21 22 23 24 25 26 27 |
# File 'lib/wbench/browser.rb', line 5 def initialize(url, = {}) Capybara.register_driver(CAPYBARA_DRIVER) do |app| http_client = Selenium::WebDriver::Remote::Http::Default.new http_client.timeout = CAPYBARA_TIMEOUT browser = ([:browser] || DEFAULT_BROWSER).to_sym = { :browser => browser, :http_client => http_client } if [:user_agent] if browser == :firefox profile = Selenium::WebDriver::Firefox::Profile.new profile['general.useragent.override'] = [:user_agent] [:profile] = profile else add_selenium_args(, "--user-agent='#{[:user_agent]}'") end end SeleniumDriver.new(app, ) end @url = Addressable::URI.parse(url).normalize.to_s @cookie_string = [:cookie] end |
Instance Attribute Details
#url ⇒ Object
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
38 39 40 |
# File 'lib/wbench/browser.rb', line 38 def evaluate_script(script) session.evaluate_script(script) end |
#run(&blk) ⇒ Object
42 43 44 |
# File 'lib/wbench/browser.rb', line 42 def run(&blk) session.instance_eval(&blk) if block_given? end |
#visit ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/wbench/browser.rb', line 29 def visit session.visit(@url) wait_for_page session.execute_script(wbench_javascript) yield if block_given? close end |