watir-classic 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGES +17 -0
  2. data/Gemfile.lock +9 -8
  3. data/LICENSE +1 -0
  4. data/README.rdoc +6 -7
  5. data/Rakefile +3 -1
  6. data/VERSION +1 -1
  7. data/lib/watir-classic.rb +0 -5
  8. data/lib/watir-classic/browser.rb +58 -35
  9. data/lib/watir-classic/browsers.rb +1 -1
  10. data/lib/watir-classic/container.rb +39 -33
  11. data/lib/watir-classic/cookies.rb +32 -2
  12. data/lib/watir-classic/core.rb +0 -1
  13. data/lib/watir-classic/dialogs/alert.rb +12 -0
  14. data/lib/watir-classic/dialogs/file_field.rb +11 -0
  15. data/lib/watir-classic/drag_and_drop_helper.rb +14 -0
  16. data/lib/watir-classic/element.rb +292 -257
  17. data/lib/watir-classic/element_collection.rb +26 -8
  18. data/lib/watir-classic/element_extensions.rb +22 -16
  19. data/lib/watir-classic/exceptions.rb +4 -4
  20. data/lib/watir-classic/form.rb +52 -49
  21. data/lib/watir-classic/frame.rb +23 -14
  22. data/lib/watir-classic/ie-class.rb +363 -315
  23. data/lib/watir-classic/ie-process.rb +1 -0
  24. data/lib/watir-classic/ie.rb +0 -17
  25. data/lib/watir-classic/image.rb +58 -64
  26. data/lib/watir-classic/input_elements.rb +224 -219
  27. data/lib/watir-classic/link.rb +14 -15
  28. data/lib/watir-classic/locator.rb +12 -7
  29. data/lib/watir-classic/matches.rb +7 -3
  30. data/lib/watir-classic/modal_dialog.rb +38 -26
  31. data/lib/watir-classic/non_control_elements.rb +29 -0
  32. data/lib/watir-classic/options.rb +10 -15
  33. data/lib/watir-classic/page-container.rb +30 -48
  34. data/lib/watir-classic/process.rb +4 -2
  35. data/lib/watir-classic/screenshot.rb +6 -0
  36. data/lib/watir-classic/supported_elements.rb +36 -14
  37. data/lib/watir-classic/table.rb +81 -71
  38. data/lib/watir-classic/util.rb +9 -11
  39. data/lib/watir-classic/wait.rb +17 -4
  40. data/lib/watir-classic/wait_helper.rb +15 -2
  41. data/lib/watir-classic/win32.rb +2 -1
  42. data/lib/watir-classic/window.rb +35 -7
  43. data/lib/watir-classic/xpath_locator.rb +1 -0
  44. data/lib/watir-classic/yard/global_macros.rb +7 -0
  45. data/spec/frame_spec.rb +17 -0
  46. metadata +5 -7
  47. data/lib/watir-classic/close_all.rb +0 -31
  48. data/lib/watir-classic/contrib/enabled_popup.rb +0 -21
  49. data/lib/watir-classic/contrib/ie-new-process.rb +0 -27
  50. data/lib/watir-classic/contrib/page_checker.rb +0 -29
  51. data/watir.gif +0 -0
@@ -1,22 +1,21 @@
1
1
  module Watir
2
2
 
3
- # This class is the means of accessing a link on a page
4
- # Normally a user would not need to create this object as it is returned by the Watir::Container#link method
5
- # many of the methods available to this object are inherited from the Element class
6
- #
3
+ # Returned by {Container#link}.
7
4
  class Link < Element
8
5
  attr_ole :type
9
6
  attr_ole :href
10
7
  attr_ole :name
11
8
 
12
- # if an image is used as part of the link, this will return true
9
+ # @deprecated Use "browser.link.imgs.length > 0" instead.
13
10
  def link_has_image
11
+ Kernel.warn "Deprecated(Link#link_has_image) - use \"browser.link.imgs.length > 0\" instead."
14
12
  assert_exists
15
13
  @o.getElementsByTagName("IMG").length > 0
16
14
  end
17
15
 
18
- # this method returns the src of an image, if an image is used as part of the link
19
- def src # BUG?
16
+ # @deprecated Use "browser.link.imgs.first.src rescue ''" instead.
17
+ def src
18
+ Kernel.warn "Deprecated(Link#link_has_image) - use \"browser.link.imgs.first.src rescue ''\" instead."
20
19
  assert_exists
21
20
  if @o.getElementsByTagName("IMG").length > 0
22
21
  return @o.getElementsByTagName("IMG")[0.to_s].src
@@ -24,7 +23,15 @@ module Watir
24
23
  return ""
25
24
  end
26
25
  end
26
+
27
+ def to_s
28
+ assert_exists
29
+ r = string_creator
30
+ r = r + link_string_creator
31
+ return r.join("\n")
32
+ end
27
33
 
34
+ # @private
28
35
  def link_string_creator
29
36
  n = []
30
37
  n << "href:".ljust(TO_S_SIZE) + self.href
@@ -33,14 +40,6 @@ module Watir
33
40
  return n
34
41
  end
35
42
 
36
- # returns a textual description of the link
37
- def to_s
38
- assert_exists
39
- r = string_creator
40
- r = r + link_string_creator
41
- return r.join("\n")
42
- end
43
-
44
43
  end
45
44
 
46
45
  end
@@ -1,4 +1,5 @@
1
1
  module Watir
2
+ # @private
2
3
  class Locator
3
4
  include Watir
4
5
  include Watir::Exception
@@ -6,7 +7,7 @@ module Watir
6
7
 
7
8
  def initialize container, specifiers, klass
8
9
  @container = container
9
- @specifiers = {:index => Watir::IE.base_index}.merge(normalize_specifiers(specifiers))
10
+ @specifiers = {:index => 0}.merge(normalize_specifiers(specifiers))
10
11
  @tags = @specifiers.delete(:tag_name)
11
12
  @klass = klass
12
13
  end
@@ -131,6 +132,7 @@ module Watir
131
132
  end
132
133
  end
133
134
 
135
+ # @private
134
136
  class TaggedElementLocator < Locator
135
137
  def each_element(tag)
136
138
  document.getElementsByTagName(tag).each do |ole_object|
@@ -143,15 +145,16 @@ module Watir
143
145
  return el if el
144
146
  return locate_elements_by_xpath_css_ole[0] if has_excluding_specifiers?
145
147
 
146
- count = Watir::IE.base_index - 1
148
+ count = 0
147
149
  each do |element|
148
- count += 1
149
150
  return element.ole_object if count == @specifiers[:index]
151
+ count += 1
150
152
  end # elements
151
153
  nil
152
154
  end
153
155
  end
154
156
 
157
+ # @private
155
158
  class FrameLocator < TaggedElementLocator
156
159
  def each_element(tag)
157
160
  frames = @container.page_container.document.frames
@@ -165,10 +168,10 @@ module Watir
165
168
  end
166
169
 
167
170
  def locate
168
- count = Watir::IE.base_index - 1
171
+ count = 0
169
172
  each do |frame|
170
- count += 1
171
173
  return frame.ole_object, frame.document if count == @specifiers[:index]
174
+ count += 1
172
175
  end
173
176
  end
174
177
 
@@ -186,6 +189,7 @@ module Watir
186
189
  end
187
190
  end
188
191
 
192
+ # @private
189
193
  class FormLocator < TaggedElementLocator
190
194
  def each_element(tag)
191
195
  document.forms.each do |form|
@@ -194,6 +198,7 @@ module Watir
194
198
  end
195
199
  end
196
200
 
201
+ # @private
197
202
  class InputElementLocator < Locator
198
203
  def each_element
199
204
  elements = locate_by_name || @container.__ole_inner_elements
@@ -208,10 +213,10 @@ module Watir
208
213
  return el if el
209
214
  return locate_elements_by_xpath_css_ole[0] if has_excluding_specifiers?
210
215
 
211
- count = Watir::IE.base_index - 1
216
+ count = 0
212
217
  each do |element|
213
- count += 1
214
218
  return element.ole_object if count == @specifiers[:index]
219
+ count += 1
215
220
  end
216
221
  end
217
222
 
@@ -1,21 +1,25 @@
1
+ # @private
1
2
  class String
2
3
  def matches(x)
3
- return self == x
4
+ self == x
4
5
  end
5
6
  end
6
7
 
8
+ # @private
7
9
  class Regexp
8
10
  def matches(x)
9
- return self.match(x)
11
+ self.match(x)
10
12
  end
11
13
  end
12
14
 
15
+ # @private
13
16
  class Integer
14
17
  def matches(x)
15
- return self == x
18
+ self == x
16
19
  end
17
20
  end
18
21
 
22
+ # @private
19
23
  class Object
20
24
  def matches(x)
21
25
  raise TypeError, "#{self.class} is not supported as a locator"
@@ -1,4 +1,5 @@
1
1
  module Watir
2
+ # Returned by {Container#modal_dialog}.
2
3
  class ModalDialog
3
4
  include Container
4
5
  include PageContainer
@@ -6,9 +7,43 @@ module Watir
6
7
 
7
8
  def initialize(container)
8
9
  set_container container
9
- @modal = ::RAutomation::Window.new(:hwnd=>@container.hwnd).child(:class => 'Internet Explorer_TridentDlgFrame')
10
+ @modal = ::RAutomation::Window.new(:hwnd => @container.hwnd).child(:class => 'Internet Explorer_TridentDlgFrame')
10
11
  end
11
12
 
13
+ # @return [String] title of the dialog.
14
+ def title
15
+ document.title
16
+ end
17
+
18
+ # Close the modal dialog.
19
+ #
20
+ # @param [Fixnum] timeout timeout in seconds to wait until modal dialog is
21
+ # successfully closed.
22
+ def close(timeout=5)
23
+ return unless exists?
24
+ document.parentWindow.close
25
+ Watir::Wait.until(timeout) {!exists?} rescue nil
26
+ wait
27
+ end
28
+
29
+ # @return [Fixnum] window handle of the dialog.
30
+ def hwnd
31
+ @modal.hwnd
32
+ end
33
+
34
+ # @return [Boolean] true when modal window is active/in focus, false otherwise.
35
+ def active?
36
+ @modal.active?
37
+ end
38
+
39
+ # @return [Boolean] true when dialog exists, false otherwise.
40
+ def exists?
41
+ @modal.exists?
42
+ end
43
+
44
+ alias_method :exist?, :exists?
45
+
46
+ # @private
12
47
  def locate
13
48
  @modal.wait_until_present rescue raise NoMatchingWindowFoundException
14
49
 
@@ -29,38 +64,15 @@ module Watir
29
64
 
30
65
  alias_method :document, :locate
31
66
 
32
- def title
33
- document.title
34
- end
35
-
36
- def close(timeout=5)
37
- return unless exists?
38
- document.parentWindow.close
39
- Watir::Wait.until(timeout) {!exists?} rescue nil
40
- wait
41
- end
42
-
67
+ # @private
43
68
  def attach_command
44
69
  "Watir::IE.find(:hwnd, #{@container.hwnd}).modal_dialog"
45
70
  end
46
71
 
72
+ # @private
47
73
  def wait(no_sleep=false)
48
74
  @container.page_container.wait unless exists?
49
75
  end
50
76
 
51
- def hwnd
52
- @modal.hwnd
53
- end
54
-
55
- def active?
56
- @modal.active?
57
- end
58
-
59
- def exists?
60
- @modal.exists?
61
- end
62
-
63
- alias_method :exist?, :exists?
64
-
65
77
  end
66
78
  end
@@ -1,28 +1,37 @@
1
1
  module Watir
2
+ # Returned by the {Watir::Container#area}.
2
3
  class Area < Element
3
4
  attr_ole :alt
4
5
  attr_ole :type
5
6
  attr_ole :href
6
7
  end
7
8
 
9
+ # Returned by the {Watir::Container#audio}.
8
10
  class Audio < Element
9
11
  attr_ole :src
10
12
  end
11
13
 
14
+ # Returned by the {Watir::Container#base}.
12
15
  class Base < Element
13
16
  attr_ole :href
14
17
  end
15
18
 
19
+ # Returned by the {Watir::Container#command}.
16
20
  class Command < Element
17
21
  attr_ole :disabled?
18
22
  attr_ole :type
19
23
  end
20
24
 
25
+ # Returned by the {Watir::Container#data}.
21
26
  class Data < Element
22
27
  attr_ole :value
23
28
  end
24
29
 
30
+ # Returned by the {Watir::Container#dl}.
25
31
  class Dl < Element
32
+ # Returns Hash representation of dl element where each key-value pair consists of dt and dd element text.
33
+ #
34
+ # @return [Hash<String, String>] where key and value is dt and dd text respectively
26
35
  def to_hash
27
36
  dts.each_with_index.reduce({}) do |memo, item|
28
37
  dt, i = *item
@@ -33,92 +42,112 @@ module Watir
33
42
  end
34
43
  end
35
44
 
45
+ # Returned by the {Watir::Container#embed}.
36
46
  class Embed < Element
37
47
  attr_ole :src
38
48
  attr_ole :type
39
49
  end
40
50
 
51
+ # Returned by the {Watir::Container#fieldset}.
41
52
  class FieldSet < Element
42
53
  attr_ole :name
43
54
  attr_ole :disabled?
44
55
  end
45
56
 
57
+ # Returned by the {Watir::Container#font}.
46
58
  class Font < Element
47
59
  attr_ole :color
48
60
  attr_ole :face
49
61
  attr_ole :size
50
62
  end
51
63
 
64
+ # Returned by the {Watir::Container#keygen}.
52
65
  class Keygen < Element
53
66
  attr_ole :name
54
67
  attr_ole :disabled?
55
68
  end
56
69
 
70
+ # Returned by the {Watir::Container#label}.
57
71
  class Label < Element
58
72
  attr_ole :for, :htmlFor
59
73
  end
60
74
 
75
+ # Returned by the {Watir::Container#li}.
61
76
  class Li < Element
62
77
  attr_ole :value
63
78
  end
64
79
 
80
+ # Returned by the {Watir::Container#map}.
65
81
  class Map < Element
66
82
  attr_ole :name
67
83
  end
68
84
 
85
+ # Returned by the {Watir::Container#menu}.
69
86
  class Menu < Element
70
87
  attr_ole :type
71
88
  end
72
89
 
90
+ # Returned by the {Watir::Container#meta}.
73
91
  class Meta < Element
74
92
  attr_ole :http_equiv, :httpEquiv
75
93
  attr_ole :content
76
94
  attr_ole :name
77
95
  end
78
96
 
97
+ # Returned by the {Watir::Container#meter}.
79
98
  class Meter < Element
80
99
  attr_ole :value
81
100
  end
82
101
 
102
+ # Returned by the {Watir::Container#object}.
83
103
  class Object < Element
84
104
  attr_ole :name
85
105
  attr_ole :type
86
106
  end
87
107
 
108
+ # Returned by the {Watir::Container#optgroup}.
88
109
  class Optgroup < Element
89
110
  attr_ole :disabled?
90
111
  end
91
112
 
113
+ # Returned by the {Watir::Container#output}.
92
114
  class Output < Element
93
115
  attr_ole :name
94
116
  end
95
117
 
118
+ # Returned by the {Watir::Container#param}.
96
119
  class Param < Element
97
120
  attr_ole :name
98
121
  attr_ole :value
99
122
  end
100
123
 
124
+ # Returned by the {Watir::Container#progress}.
101
125
  class Progress < Element
102
126
  attr_ole :value
103
127
  end
104
128
 
129
+ # Returned by the {Watir::Container#script}.
105
130
  class Script < Element
106
131
  attr_ole :src
107
132
  attr_ole :type
108
133
  end
109
134
 
135
+ # Returned by the {Watir::Container#source}.
110
136
  class Source < Element
111
137
  attr_ole :type
112
138
  end
113
139
 
140
+ # Returned by the {Watir::Container#style}.
114
141
  class Style < Element
115
142
  attr_ole :type
116
143
  end
117
144
 
145
+ # Returned by the {Watir::Container#track}.
118
146
  class Track < Element
119
147
  attr_ole :src
120
148
  end
121
149
 
150
+ # Returned by the {Watir::Container#video}.
122
151
  class Video < Element
123
152
  attr_ole :src
124
153
  end
@@ -5,29 +5,24 @@ require 'rubygems'
5
5
  require 'user-choices'
6
6
 
7
7
  module Watir
8
- @@options_file = nil
9
- @@options = nil
10
8
  class << self
11
9
  # Specify the location of a yaml file containing Watir options. Must be
12
10
  # specified before the options are parsed.
13
- def options_file= file
14
- @@options_file = file
15
- end
16
- def options_file
17
- @@options_file
18
- end
19
- def options= x
20
- @@options = x
21
- end
11
+ attr_accessor :options_file
12
+
13
+ attr_writer :options
14
+
22
15
  # Return the Watir options, as a hash. If they haven't been parsed yet,
23
16
  # they will be now.
24
17
  def options
25
- @@options ||= Watir::WatirOptions.new.execute
18
+ @options ||= Watir::WatirOptions.new.execute
26
19
  end
27
20
  end
28
21
 
22
+ # @private
29
23
  class WatirOptions < UserChoices::Command
30
24
  include UserChoices
25
+
31
26
  def add_sources builder
32
27
  builder.add_source EnvironmentSource, :with_prefix, 'watir_'
33
28
  if Watir.options_file
@@ -35,6 +30,7 @@ module Watir
35
30
  Watir.options_file
36
31
  end
37
32
  end
33
+
38
34
  def add_choices builder
39
35
  builder.add_choice :browser,
40
36
  :type => Watir::Browser.browser_names,
@@ -44,13 +40,12 @@ module Watir
44
40
  :default => 'fast'
45
41
  builder.add_choice :visible,
46
42
  :type => :boolean
47
- builder.add_choice :zero_based_indexing,
48
- :type => :boolean,
49
- :default => true
50
43
  end
44
+
51
45
  def execute
52
46
  @user_choices[:speed] = @user_choices[:speed].to_sym
53
47
  @user_choices
54
48
  end
49
+
55
50
  end
56
51
  end