vapir-ie 1.7.0 → 1.7.1.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,18 @@ module Vapir
21
21
  include Vapir::Container
22
22
  include Vapir::Exception
23
23
 
24
+ public
25
+ # see documentation for the common Vapir::Container#handling_existence_failure
26
+ def handling_existence_failure(options={})
27
+ options=handle_options(options, :handle => :ignore)
28
+ begin
29
+ yield
30
+ rescue WIN32OLERuntimeError, RuntimeError, Vapir::Exception::ExistenceFailureException
31
+ raise if $!.class==RuntimeError && $!.message !~ /HRESULT/ # sometimes WIN32OLE raises a RuntimeError instead of a WIN32OLERuntimeError. only catch a RuntimeError if it's from WIN32OLE, indicated by HRESULT in the error message.
32
+ handle_existence_failure($!, options)
33
+ end
34
+ end
35
+ public
24
36
  # Note: @container is the container of this object, i.e. the container
25
37
  # of this container.
26
38
  # In other words, for ie.table().this_thing().text_field().set,
@@ -41,10 +53,10 @@ module Vapir
41
53
  @container.logger.debug(what) if @logger
42
54
  end
43
55
 
44
- def set_container container
45
- @container = container
46
- @page_container = container.page_container
47
- end
56
+ # def set_container container
57
+ # @container = container
58
+ # @page_container = container.page_container
59
+ # end
48
60
 
49
61
  private
50
62
  end # module
@@ -18,6 +18,13 @@ module Vapir
18
18
  def enabled?
19
19
  !disabled
20
20
  end
21
+ # Checks if this element is enabled or not. Raises ObjectDisabledException if this is disabled.
22
+ def assert_enabled
23
+ # TODO: dry? copied from common InputElement
24
+ if disabled
25
+ raise Exception::ObjectDisabledException, "#{self.inspect} is disabled"
26
+ end
27
+ end
21
28
 
22
29
  private
23
30
  def base_element_class
@@ -173,10 +180,9 @@ module Vapir
173
180
  ]
174
181
  actions.each do |action|
175
182
  # javascript stuff responding to previous events can cause self to stop existing, so check at every subsequent step
176
- if exists?
183
+ handling_existence_failure(:handle => proc{ return result }) do
184
+ assert_exists :force => true
177
185
  result=action.call
178
- else
179
- return result
180
186
  end
181
187
  end
182
188
  wait
@@ -337,23 +343,27 @@ module Vapir
337
343
 
338
344
  private
339
345
  def element_object_exists?
340
- return nil if !@element_object
346
+ return false if !@element_object
341
347
 
342
348
  begin
343
- win=container.document_object.parentWindow
344
- document_object=win.document # I don't know why container.document_object != container.document_object.parentWindow.document
345
-
346
- # we need a javascript function to test equality because comparing two WIN32OLEs always returns false (unless they have the same object_id, which these don't)
347
- win.execScript("__watir_javascript_equals__=function(a, b){return a==b;}")
349
+ doc=container.document_object || (return false)
350
+ win=doc.parentWindow || (return false)
351
+ document_object=win.document || (return false) # I don't know why container.document_object != container.document_object.parentWindow.document
348
352
  rescue WIN32OLERuntimeError
349
353
  # if a call to these methods from the above block raised this exception, we don't exist.
350
354
  # if that's not the error, it's unexpected; raise.
351
- if $!.message =~ /unknown property or method `(parentWindow|contentWindow|document|execScript)'/
355
+ if $!.message =~ /unknown property or method `(parentWindow|contentWindow|document)'/
352
356
  return false
353
357
  else
354
358
  raise
355
359
  end
356
360
  end
361
+ begin
362
+ # we need a javascript function to test equality because comparing two WIN32OLEs always returns false (unless they have the same object_id, which these don't)
363
+ win.execScript("__watir_javascript_equals__=function(a, b){return a==b;}")
364
+ rescue WIN32OLERuntimeError
365
+ return false
366
+ end
357
367
 
358
368
  current_node=@element_object
359
369
  while current_node
@@ -375,3 +385,4 @@ module Vapir
375
385
  end
376
386
  end
377
387
  end
388
+
@@ -28,10 +28,6 @@ module Vapir
28
28
  content_window_object.document
29
29
  end
30
30
  alias document document_object
31
-
32
- def attach_command
33
- @container.page_container.attach_command + ".frame(#{@how.inspect}, #{@what.inspect})"
34
- end
35
31
 
36
32
  end
37
33
  end
@@ -865,10 +865,6 @@ module Vapir
865
865
  end
866
866
  private :element_by_absolute_xpath
867
867
 
868
- def attach_command
869
- "Vapir::IE.attach(:hwnd, #{hwnd})"
870
- end
871
-
872
868
  private
873
869
  def base_element_class
874
870
  IE::Element
@@ -60,7 +60,10 @@ module Vapir
60
60
  include IE::PageContainer
61
61
  @@iedialog_file = (File.expand_path(File.dirname(__FILE__) + '/..') + "/vapir-ie/IEDialog/Release/IEDialog.dll").gsub('/', '\\')
62
62
 
63
- GetUnknown = Win32API.new(@@iedialog_file, 'GetUnknown', ['l', 'p'], 'v')
63
+ def get_unknown(*args)
64
+ @@get_unknown ||= Win32API.new(@@iedialog_file, 'GetUnknown', ['l', 'p'], 'v')
65
+ @@get_unknown.call(*args)
66
+ end
64
67
  def initialize(containing_modal_dialog, options={})
65
68
  options=handle_options(options, :timeout => ModalDialog::DEFAULT_TIMEOUT, :error => true)
66
69
  @containing_modal_dialog=containing_modal_dialog
@@ -68,7 +71,7 @@ module Vapir
68
71
  intUnknown = nil
69
72
  ::Waiter.try_for(options[:timeout], :exception => (options[:error] && "Unable to attach to Modal Window after #{options[:timeout]} seconds.")) do
70
73
  intPointer = [0].pack("L") # will contain the int value of the IUnknown*
71
- GetUnknown.call(@containing_modal_dialog.hwnd, intPointer)
74
+ get_unknown(@containing_modal_dialog.hwnd, intPointer)
72
75
  intArray = intPointer.unpack('L')
73
76
  intUnknown = intArray.first
74
77
  intUnknown > 0
@@ -80,7 +83,7 @@ module Vapir
80
83
  attr_reader :containing_modal_dialog
81
84
  attr_reader :document_object
82
85
  def locate!(options={})
83
- exists? || raise(Vapir::Exception::NoMatchingWindowFoundException, "The modal dialog seems to have stopped existing.")
86
+ exists? || raise(Vapir::Exception::WindowGoneException, "The modal dialog seems to have stopped existing.")
84
87
  end
85
88
 
86
89
  def exists?
@@ -206,10 +209,6 @@ module Watir
206
209
  document.title
207
210
  end
208
211
 
209
- def attach_command
210
- "Watir::IE.find(:hwnd, #{@container.hwnd}).modal_dialog"
211
- end
212
-
213
212
  def wait(options={})
214
213
  end
215
214
 
@@ -1,4 +1,5 @@
1
1
  require 'vapir-ie/container'
2
+ require 'vapir-common/page_container'
2
3
 
3
4
  module Vapir
4
5
  # A PageContainer contains an HTML Document. In other words, it is a
@@ -6,6 +7,8 @@ module Vapir
6
7
  #
7
8
  # this assumes that document_object is defined on the includer.
8
9
  module IE::PageContainer
10
+ include Vapir::PageContainer
11
+
9
12
  # Used internally to determine when IE has finished loading a page
10
13
  # http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowserreadystate.aspx
11
14
  # http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.readystate.aspx
@@ -18,9 +21,6 @@ module Vapir
18
21
  end
19
22
  READYSTATE_COMPLETE = WebBrowserReadyState::Complete
20
23
 
21
- def containing_object
22
- document_object
23
- end
24
24
  include IE::Container
25
25
  include Vapir::Exception
26
26
 
@@ -45,27 +45,15 @@ module Vapir
45
45
  false
46
46
  end
47
47
 
48
- def document_element
49
- document_object.documentElement
50
- end
51
48
  def content_window_object
52
49
  document_object.parentWindow
53
50
  end
54
51
 
55
- def page_container
56
- self
57
- end
58
-
59
52
  # The HTML of the current page
60
53
  def html
61
54
  document_element.outerHTML
62
55
  end
63
56
 
64
- # The url of the page object.
65
- def url
66
- document_object.location.href
67
- end
68
-
69
57
  # The text of the current page
70
58
  def text
71
59
  document_element.innerText
@@ -75,10 +63,6 @@ module Vapir
75
63
  content_window_object.close
76
64
  end
77
65
 
78
- def title
79
- document_object.title
80
- end
81
-
82
66
  # Execute the given JavaScript string
83
67
  def execute_script(source)
84
68
  retried=false
@@ -115,11 +99,11 @@ module Vapir
115
99
  start_load_time = Time.now
116
100
 
117
101
  if respond_to?(:browser_object)
118
- ::Waiter.try_for(options[:timeout]-(Time.now-start_load_time), :interval => options[:interval], :exception => "The browser was still busy at the end of the specified interval") do
102
+ ::Waiter.try_for(options[:timeout]-(Time.now-start_load_time), :interval => options[:interval], :exception => "The browser was still busy after #{options[:timeout]} seconds") do
119
103
  return unless exists?
120
104
  !browser_object.busy
121
105
  end
122
- ::Waiter.try_for(options[:timeout]-(Time.now-start_load_time), :interval => options[:interval], :exception => "The browser's readyState was still not ready for interaction at the end of the specified interval") do
106
+ ::Waiter.try_for(options[:timeout]-(Time.now-start_load_time), :interval => options[:interval], :exception => "The browser's readyState was still not ready for interaction after #{options[:timeout]} seconds") do
123
107
  return unless exists?
124
108
  [WebBrowserReadyState::Interactive, WebBrowserReadyState::Complete].include?(browser_object.readyState)
125
109
  end
@@ -134,7 +118,7 @@ module Vapir
134
118
  return
135
119
  end
136
120
  end
137
- ::Waiter.try_for(options[:timeout]-(Time.now-start_load_time), :interval => options[:interval], :exception => "The browser's document was still not defined at the end of the specified interval") do
121
+ ::Waiter.try_for(options[:timeout]-(Time.now-start_load_time), :interval => options[:interval], :exception => "The browser's document was still not defined after #{options[:timeout]} seconds") do
138
122
  return unless exists?
139
123
  doc_or_ret.call
140
124
  end
@@ -145,7 +129,7 @@ module Vapir
145
129
  end
146
130
  case all_frames_complete_result
147
131
  when false
148
- raise "A frame on the browser did not come into readyState complete by the end of the specified interval"
132
+ raise "A frame on the browser did not come into readyState complete after #{options[:timeout]} seconds"
149
133
  when ::Exception
150
134
  message = "A frame on the browser encountered an error.\n"
151
135
  if all_frames_complete_result.message =~ /0x80070005/
@@ -39,15 +39,16 @@ end
39
39
 
40
40
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'vapir-common', 'lib'))
41
41
 
42
- require 'vapir-common/win_window'
43
- require 'vapir-common/waiter'
44
- require 'vapir-common/exceptions'
45
-
46
42
  browser_hwnd, file_path, $error_file_name=*ARGV
47
43
  unless (2..3).include?(ARGV.size) && browser_hwnd =~ /^\d+$/ && browser_hwnd.to_i > 0
48
44
  raise ArgumentError, "This script takes two or three arguments: the hWnd that the File Selection dialog will pop up on (positive integer); the path to the file to select; and (optional) a filename to write any failure message to."
49
45
  end
50
46
 
47
+ require 'rubygems' # win_window needs this for FFI
48
+ require 'vapir-common/win_window'
49
+ require 'vapir-common/waiter'
50
+ require 'vapir-common/exceptions'
51
+
51
52
  # titles of file upload window titles in supported browsers
52
53
  # Add to this titles in other languages, too
53
54
  UploadWindowTitles= { :IE8 => "Choose File to Upload",
@@ -1,5 +1,5 @@
1
1
  module Vapir
2
2
  class IE
3
- VERSION = '1.7.0'
3
+ VERSION = '1.7.1.rc1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vapir-ie
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 1
7
7
  - 7
8
- - 0
9
- version: 1.7.0
8
+ - 1
9
+ - rc1
10
+ version: 1.7.1.rc1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ethan
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-02 00:00:00 -04:00
18
+ date: 2010-08-06 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -55,8 +56,9 @@ dependencies:
55
56
  segments:
56
57
  - 1
57
58
  - 7
58
- - 0
59
- version: 1.7.0
59
+ - 1
60
+ - rc1
61
+ version: 1.7.1.rc1
60
62
  type: :runtime
61
63
  version_requirements: *id003
62
64
  - !ruby/object:Gem::Dependency
@@ -148,11 +150,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
150
  version: "0"
149
151
  required_rubygems_version: !ruby/object:Gem::Requirement
150
152
  requirements:
151
- - - ">="
153
+ - - ">"
152
154
  - !ruby/object:Gem::Version
153
155
  segments:
154
- - 0
155
- version: "0"
156
+ - 1
157
+ - 3
158
+ - 1
159
+ version: 1.3.1
156
160
  requirements:
157
161
  - Microsoft Windows
158
162
  - Internet Explorer