Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Commit

Permalink
Move support for configuring speed into the Browser class.
Browse files Browse the repository at this point in the history
  • Loading branch information
bret committed Oct 28, 2008
1 parent b04cfed commit 7af69a6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
15 changes: 13 additions & 2 deletions watir-common/lib/watir/browser.rb
Expand Up @@ -3,22 +3,27 @@
module Watir
module Browser
@@browser_classes = {}
@@sub_options = {}
@@default = 'ie'
class << self
def new *args
set_sub_options
klass.new *args
end
def start *args
set_sub_options
klass.start *args
end
def klass
key = Watir.options[:browser]
eval @@browser_classes[key] # this triggers the autoload
end
# Add support for the browser option, using the specified class,
# provided as a string.
def support option, class_string
# provided as a string. Optionally, additional options supported by
# the class can be specified
def support option, class_string, additional_options=[]
@@browser_classes[option] = class_string
@@sub_options[option] = additional_options
end
def default
@@default
Expand All @@ -30,6 +35,12 @@ def default= option
def options
@@browser_classes.keys
end
def set_sub_options
return unless defined?(klass.set_options)
sub_options = @@sub_options[Watir.options[:browser]]
specified_options = Watir.options.reject {|k, v| !sub_options.include? k}
klass.set_options specified_options
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion watir-common/lib/watir/browsers.rb
Expand Up @@ -2,7 +2,7 @@
# Define browsers supported by Watir

module Watir; autoload :IE, 'watir'; end
Watir::Browser.support 'ie', 'Watir::IE'
Watir::Browser.support 'ie', 'Watir::IE', [:speed]

module FireWatir; autoload :Firefox, 'firewatir'; end
Watir::Browser.support 'firefox', 'FireWatir::Firefox'
Expand Down
1 change: 1 addition & 0 deletions watir-common/lib/watir/options.rb
Expand Up @@ -42,6 +42,7 @@ def add_choices builder
:default => 'fast'
end
def execute
@user_choices[:speed] = @user_choices[:speed].to_sym
@user_choices
end
end
Expand Down
7 changes: 1 addition & 6 deletions watir-common/unittests/setup/browser.rb
Expand Up @@ -4,15 +4,10 @@
when 'ie'
at_exit {Watir::IE.quit}
$LOAD_PATH.unshift File.expand_path($watir_dev_lib)

speed = Watir.options[:speed].to_sym
Watir::IE.speed = speed
$browser = Watir::Browser.new
$browser.speed = speed
when 'firefox'
$LOAD_PATH.unshift File.expand_path($firewatir_dev_lib)
$browser = Watir::Browser.new
end
$browser = Watir::Browser.new

# close browser at completion of the tests
# the at_exit execute before loading test/unit, otherwise IE will close *before* the tests run.
Expand Down

0 comments on commit 7af69a6

Please sign in to comment.