lib/taza/browser.rb in bret-watircraft-0.4.3 vs lib/taza/browser.rb in bret-watircraft-0.4.4
- old
+ new
@@ -1,50 +1,67 @@
-module Taza
- class Browser
-
- # Create a browser instance depending on configuration. Configuration should be read in via Taza::Settings.config.
- #
- # Example:
- # browser = Taza::Browser.create(Taza::Settings.config)
- #
- def self.create(params={})
- self.send("create_#{params[:driver]}".to_sym,params)
- end
-
- private
-
- def self.create_watir(params)
- require 'watir'
- require 'extensions/watir'
- if params[:browser] == :ie
- require 'watir/ie'
- Watir.add_display_value_methods_to Watir
- end
- if params[:browser] == :firefox
- require 'firewatir'
- Watir.add_display_value_methods_to FireWatir
- end
- Watir::Browser.default = params[:browser].to_s
- Watir::Browser.new
- end
-
- def self.create_selenium(params)
- require 'selenium'
- Selenium::SeleniumDriver.new(params[:server_ip],params[:server_port],'*' + params[:browser].to_s,params[:timeout])
- end
-
- def self.create_fake(params)
- FakeBrowser.new
- end
-
- end
-
- class FakeBrowser
- def goto(*args)
- end
- def close
- end
-
- end
-
-end
-
+module Taza
+ class Browser
+
+ class << self
+
+ # Create a browser instance depending on configuration. Configuration should be read in via Taza::Settings.config.
+ #
+ # Example:
+ # browser = Taza::Browser.create(Taza::Settings.config)
+ #
+ def create(params={})
+ send("create_#{params[:driver]}", params)
+ end
+
+ private
+
+ def create_watir(params)
+ require 'watir'
+ require 'extensions/watir'
+ Watir::Browser.default = params[:browser]
+ case params[:browser]
+ when 'ie'
+ require 'watir/ie'
+ Watir.add_display_value_methods_to Watir
+ Watir::IE.set_options(:visible => params[:visible])
+ browser = provision_watir_browser params
+ browser.speed = params[:speed]
+ when 'firefox'
+ require 'firewatir'
+ Watir.add_display_value_methods_to FireWatir
+ browser = provision_watir_browser params
+ else
+ browser = provision_watir_browser params
+ end
+
+ browser
+ end
+
+ def provision_watir_browser(params)
+ if params[:attach] && params[:browser] == 'ie'
+ browser = Watir::IE.find(:title, //)
+ end
+ browser || Watir::Browser.new
+ end
+
+ def create_selenium(params)
+ require 'selenium'
+ Selenium::SeleniumDriver.new(params[:server_ip],params[:server_port],'*' + params[:browser],params[:timeout])
+ end
+
+ def create_fake(params)
+ FakeBrowser.new
+ end
+ end
+
+ end
+
+ class FakeBrowser
+ def goto(*args)
+ end
+ def close
+ end
+
+ end
+
+end
+