watir/ie.rb in watir-1.5.3 vs watir/ie.rb in watir-1.5.4
- old
+ new
@@ -16,31 +16,55 @@
@@attach_timeout
end
def self.attach_timeout=(timeout)
@@attach_timeout = timeout
end
-
+
+ def self.defaults
+ {:speed => self.speed, :visible => self.visible}
+ end
+ def self.defaults= options
+ options.each do |name, value|
+ send "#{name}=", value
+ end
+ end
+ # The globals $FAST_SPEED and $HIDE_IE are checked both at initialization
+ # and later, because they
+ # might be set after initialization. Setting them beforehand (e.g. from
+ # the command line) will affect the class, otherwise it is only a temporary
+ # effect
+ @@speed = $FAST_SPEED ? :fast : :slow
+ def self.speed
+ return :fast if $FAST_SPEED
+ @@speed
+ end
+ def self.speed= x
+ $FAST_SPEED = nil
+ @@speed = x
+ end
+ @@visible = $HIDE_IE ? false : true
+ def self.visible
+ return false if $HIDE_IE
+ @@visible
+ end
+ def self.visible= x
+ $HIDE_IE = nil
+ @@visible = x
+ end
+
# The revision number (according to Subversion)
REVISION_STRING = '$Revision: 1263 $'
REVISION_STRING.scan(/Revision: (\d*)/)
REVISION = $1 or 'unknown'
# The Release number
- VERSION_SHORT = '1.5.3'
+ VERSION_SHORT = '1.5.4'
VERSION = VERSION_SHORT + '.' + REVISION
# Used internally to determine when IE has finished loading a page
READYSTATE_COMPLETE = 4
-
- # TODO: the following constants should be able to be specified by object (not class)
-
- # The delay when entering text on a web page when speed = :slow.
- DEFAULT_TYPING_SPEED = 0.08
-
- # The default time we wait after a page has loaded when speed = :slow.
- DEFAULT_SLEEP_TIME = 0.1
-
+
# The default color for highlighting objects as they are accessed.
HIGHLIGHT_COLOR = 'yellow'
# IE inserts some element whose tagName is empty and just acts as block level element
# Probably some IE method of cleaning things
@@ -75,11 +99,11 @@
_new_window_init unless suppress_new_window
end
def _new_window_init
create_browser_window
- set_defaults
+ initialize_options
goto 'about:blank' # this avoids numerous problems caused by lack of a document
end
# Create a new IE Window, starting at the specified url.
# If no url is given, start empty.
@@ -106,11 +130,11 @@
def _new_process_init
iep = Process.start
@ie = iep.window
@process_id = iep.process_id
- set_defaults
+ initialize_options
goto 'about:blank'
end
# Create a new IE window in a new process, starting at the specified URL.
# Same as IE.start.
@@ -136,66 +160,72 @@
end
# this method is used internally to attach to an existing window
def _attach_init how, what
attach_browser_window how, what
- set_defaults
+ initialize_options
wait
end
# Return an IE object that wraps the given window, typically obtained from
# Shell.Application.windows.
def self.bind window
ie = new true
ie.ie = window
- ie.set_defaults
+ ie.initialize_options
ie
end
def create_browser_window
@ie = WIN32OLE.new('InternetExplorer.Application')
end
private :create_browser_window
- def set_defaults
- self.visible = ! $HIDE_IE
+ def initialize_options
+ self.visible = IE.visible
+ self.speed = IE.speed
+
@ole_object = nil
@page_container = self
@error_checkers = []
@activeObjectHighLightColor = HIGHLIGHT_COLOR
- if $FAST_SPEED
- set_fast_speed
- else
- set_slow_speed
- end
@logger = DefaultLogger.new
@url_list = []
end
def speed= how_fast
case how_fast
- when :fast : set_fast_speed
- when :slow : set_slow_speed
+ when :zippy :
+ @typingspeed = 0
+ @pause_after_wait = 0.01
+ @type_keys = false
+ @speed = :fast
+ when :fast :
+ @typingspeed = 0
+ @pause_after_wait = 0.01
+ @type_keys = true
+ @speed = :fast
+ when :slow :
+ @typingspeed = 0.08
+ @pause_after_wait = 0.1
+ @type_keys = true
+ @speed = :slow
else
raise ArgumentError, "Invalid speed: #{how_fast}"
end
end
# deprecated: use speed = :fast instead
def set_fast_speed
- @typingspeed = 0
- @defaultSleepTime = 0.01
- @speed = :fast
+ self.speed = :fast
end
# deprecated: use speed = :slow instead
def set_slow_speed
- @typingspeed = DEFAULT_TYPING_SPEED
- @defaultSleepTime = DEFAULT_SLEEP_TIME
- @speed = :slow
+ self.speed = :slow
end
def visible
@ie.visible
end
@@ -451,11 +481,11 @@
documents_to_wait_for = [@ie.document]
rescue WIN32OLERuntimeError # IE window must have been closed
@down_load_time = Time.now - start_load_time
- sleep @defaultSleepTime unless no_sleep
+ sleep @pause_after_wait unless no_sleep
return @down_load_time
end
while doc = documents_to_wait_for.shift
begin
@@ -473,10 +503,10 @@
end
end
@down_load_time = Time.now - start_load_time
run_error_checks
- sleep @defaultSleepTime unless no_sleep
+ sleep @pause_after_wait unless no_sleep
@down_load_time
end
# Error checkers
\ No newline at end of file