operawatir 0.3-jruby → 0.3.2-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/Gemfile +6 -2
  2. data/LICENSE +1 -1
  3. data/Rakefile +7 -8
  4. data/VERSION +1 -1
  5. data/bin/desktopwatir +3 -0
  6. data/bin/operawatir +2 -2
  7. data/lib/operadriver/webdriver-opera.jar +0 -0
  8. data/lib/operawatir.rb +14 -8
  9. data/lib/operawatir/browser.rb +49 -38
  10. data/lib/operawatir/compat/collection.rb +6 -0
  11. data/lib/operawatir/compat/element.rb +5 -2
  12. data/lib/operawatir/compat/element_finders.rb +19 -0
  13. data/lib/operawatir/desktop-waiter.rb +144 -0
  14. data/lib/operawatir/desktop_browser.rb +506 -0
  15. data/lib/operawatir/desktop_common.rb +111 -0
  16. data/lib/operawatir/desktop_container.rb +252 -0
  17. data/lib/operawatir/desktop_enums.rb +42 -0
  18. data/lib/operawatir/desktop_exceptions.rb +16 -0
  19. data/lib/operawatir/element.rb +6 -6
  20. data/lib/operawatir/exceptions.rb +3 -0
  21. data/lib/operawatir/keys.rb +116 -0
  22. data/lib/operawatir/platform.rb +59 -0
  23. data/lib/operawatir/quickwidgets.rb +3 -0
  24. data/lib/operawatir/quickwidgets/quick_addressfield.rb +23 -0
  25. data/lib/operawatir/quickwidgets/quick_button.rb +151 -0
  26. data/lib/operawatir/quickwidgets/quick_checkbox.rb +58 -0
  27. data/lib/operawatir/quickwidgets/quick_dialogtab.rb +23 -0
  28. data/lib/operawatir/quickwidgets/quick_dropdown.rb +27 -0
  29. data/lib/operawatir/quickwidgets/quick_editfield.rb +115 -0
  30. data/lib/operawatir/quickwidgets/quick_label.rb +12 -0
  31. data/lib/operawatir/quickwidgets/quick_radiobutton.rb +11 -0
  32. data/lib/operawatir/quickwidgets/quick_searchfield.rb +25 -0
  33. data/lib/operawatir/quickwidgets/quick_tab.rb +66 -0
  34. data/lib/operawatir/quickwidgets/quick_thumbnail.rb +26 -0
  35. data/lib/operawatir/quickwidgets/quick_toolbar.rb +11 -0
  36. data/lib/operawatir/quickwidgets/quick_treeitem.rb +157 -0
  37. data/lib/operawatir/quickwidgets/quick_treeview.rb +27 -0
  38. data/lib/operawatir/quickwidgets/quick_widget.rb +369 -0
  39. data/lib/operawatir/quickwidgets/quick_window.rb +150 -0
  40. data/lib/operawatir/selector.rb +1 -1
  41. data/lib/operawatir/version.rb +0 -1
  42. data/lib/operawatir/window.rb +9 -0
  43. data/operawatir.gemspec +382 -0
  44. data/spec/new_watirspec/browser_spec.rb +279 -0
  45. data/spec/new_watirspec/clipboard_spec.rb +79 -0
  46. data/spec/new_watirspec/collection_spec.rb +387 -0
  47. data/spec/new_watirspec/element_spec.rb +456 -0
  48. data/spec/new_watirspec/guards.rb +39 -0
  49. data/spec/new_watirspec/keys_spec.rb +206 -0
  50. data/spec/new_watirspec/server.rb +91 -0
  51. data/spec/new_watirspec/watirspec_helper.rb +62 -0
  52. data/spec/new_watirspec/window_spec.rb +370 -0
  53. data/utils/launchers/launcher-mac +0 -0
  54. metadata +191 -28
  55. data/.gitmodules +0 -3
@@ -0,0 +1,27 @@
1
+ module OperaWatir
2
+ class QuickTreeView < QuickWidget
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:treeview]
8
+ end
9
+
10
+ #Should rather use what's already in browser
11
+ def treeitems
12
+ treeitems = driver.getQuickWidgetList(driver.getWindowName(window_id)).map do |java_widget|
13
+ case java_widget.getType
14
+ when QuickWidget::WIDGET_ENUM_MAP[:treeitem]
15
+ QuickTreeItem.new(self,java_widget)
16
+ end
17
+ end.select { |item| item != nil }
18
+ treeitems.select {|item| item.parent_name == name }
19
+ end
20
+
21
+ def num_treeitems
22
+ treeitems.select { |item| item.position[1] == 0 }.length
23
+ end
24
+
25
+ end
26
+ end
27
+
@@ -0,0 +1,369 @@
1
+ module OperaWatir
2
+ class QuickWidget
3
+ include DesktopCommon
4
+ include DesktopContainer
5
+
6
+ # @private
7
+ # window_id is set if constructor is called on a (parent) window
8
+ # location is set is this is called on a (parent) widget
9
+ def initialize(container, method, selector=nil, location=nil, window_id=-1)
10
+ @container = container
11
+
12
+ if method.is_a? Java::ComOperaCoreSystems::QuickWidget
13
+ @elm = method
14
+ else
15
+ @method = method
16
+ @selector = selector
17
+ @location = location
18
+ @window_id = window_id
19
+ #puts "Constructed widget #{@selector} inside #{@location} in window with id #{@window_id}"
20
+ end
21
+ end
22
+
23
+ def open_window_with_hover(win_name = "")
24
+ wait_start
25
+ element.hover
26
+ wait_for_window_shown(win_name)
27
+ end
28
+
29
+ ######################################################################
30
+ # Checks whether a widget exists or not
31
+ #
32
+ # @return [Boolean] true if the widget exists otherwise false
33
+ #
34
+ def exist?
35
+ !!element
36
+ rescue Exceptions::UnknownObjectException
37
+ false
38
+ end
39
+ alias_method :exists?, :exist?
40
+
41
+ ######################################################################
42
+ # Checks if a widget is enabled or not
43
+ #
44
+ # @return [Boolean] true if enabled otherwise false
45
+ #
46
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
47
+ # using the specified method
48
+ #
49
+ def enabled?
50
+ element.isEnabled
51
+ end
52
+
53
+ ######################################################################
54
+ # Checks if a widget is visible or not
55
+ #
56
+ # @return [Boolean] true if visible otherwise false
57
+ #
58
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
59
+ # using the specified method
60
+ #
61
+ def visible?
62
+ element.isVisible
63
+ end
64
+
65
+ ######################################################################
66
+ # Get the text of the widget
67
+ #
68
+ # @note This method should not be used to check the text in a widget if
69
+ # the text is in the Opera language file. Use verify_text or
70
+ # verify_includes_text instead
71
+ #
72
+ # @return [String] text of the widget
73
+ #
74
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
75
+ # using the specified method
76
+ #
77
+ def text
78
+ element.getText
79
+ end
80
+
81
+ ######################################################################
82
+ # Gets the type of a widget
83
+ #
84
+ # @return [Symbol] type of the widget (e.g. :dropdown, :button)
85
+ #
86
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
87
+ # using the specified method
88
+ #
89
+ def type
90
+ WIDGET_ENUM_MAP.invert[element.getType]
91
+ end
92
+
93
+ ######################################################################
94
+ # Get the name of the widget (as it appears in dialog.ini or code)
95
+ #
96
+ # @return [String] name of the widget
97
+ #
98
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
99
+ # using the specified method
100
+ #
101
+ def name
102
+ element.getName
103
+ end
104
+
105
+ ######################################################################
106
+ # Get a string representation of the widget
107
+ #
108
+ # @return [String] representation of the widget
109
+ #
110
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
111
+ # using the specified method
112
+ #
113
+ def to_s
114
+ "#{type.to_s.capitalize} #{name}, visible=#{visible?}, enabled=#{enabled?}, text=#{text}, parentName=#{parent_name}, position=#{row},#{col}"
115
+ end
116
+
117
+ ######################################################################
118
+ # Checks that the text in the widget matches the text as loaded
119
+ # from the current language file in Opera using the string_id
120
+ #
121
+ # @param [String] string_id String ID to use to load the string from the current
122
+ # language file (e.g. "D_NEW_PREFERENCES_GENERAL")
123
+ #
124
+ # @return [Boolean] true if the text matches, otherwise false
125
+ #
126
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
127
+ # using the specified method
128
+ #
129
+ def verify_text(string_id)
130
+ element.verifyText(string_id);
131
+ end
132
+
133
+ alias_method :is_text?, :verify_text
134
+
135
+ ######################################################################
136
+ # Checks that the text in the widget includes the text as loaded
137
+ # from the current language file in Opera using the string_id
138
+ #
139
+ # @param [String] string_id String ID to use to load the string from the current
140
+ # language file (e.g. "D_NEW_PREFERENCES_GENERAL")
141
+ #
142
+ # @return [Boolean] true if the text is included, otherwise false
143
+ #
144
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
145
+ # using the specified method
146
+ #
147
+ def verify_includes_text(string_id)
148
+ element.verifyContainsText(string_id)
149
+ end
150
+
151
+ alias_method :includes_text?, :verify_includes_text
152
+
153
+ ######################################################################
154
+ # Prints out all of the row/col information in single lines. Used to
155
+ # check items from lists
156
+ #
157
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
158
+ # using the specified method
159
+ #
160
+ def print_row
161
+ if element.getColumn() == 0
162
+ puts "Parent: " + element.getParentName() + ", Item: " + element.getRow().to_s + ", Text: " + text
163
+ end
164
+ end
165
+
166
+ # @return position for elements that have a position, else false
167
+ def position
168
+ return [row, col] if type == :treeitem
169
+ return col if type == :tabbutton
170
+ false
171
+ end
172
+
173
+ ######################################################################
174
+ # Prints out all of the internal information about the widget. Used
175
+ # to discover the names of widgets and windows to use in the tests
176
+ #
177
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
178
+ # using the specified method
179
+ #
180
+ def print_widget_info
181
+ puts " Name: " + name
182
+ puts " Text: " + text
183
+ puts " Type: " + type.to_s
184
+ puts " Parent: " + element.getParentName()
185
+ puts "Visible: " + visible?.to_s
186
+ puts "Enabled: " + enabled?.to_s
187
+ puts " Pos: x=" + element.getRect().x.to_s + ", y=" + element.getRect().y.to_s
188
+ puts " Size: width=" + element.getRect().width.to_s + ", height=" + element.getRect().height.to_s
189
+ puts " Ref: row=" + element.getRow().to_s + ", col=" + element.getColumn().to_s
190
+ puts "selected: " + element.isSelected().to_s
191
+ puts ""
192
+ end
193
+
194
+ # @private
195
+ def driver
196
+ @container.driver
197
+ end
198
+
199
+ # parent is container
200
+ # Get parent widget name
201
+ def parent_name
202
+ element.getParentName()
203
+ end
204
+
205
+ # Focus a widget with a click
206
+ def focus_with_click
207
+ click
208
+ # No event yet so just cheat and sleep
209
+ sleep(0.1);
210
+ end
211
+
212
+ #@private
213
+ def value
214
+ return element.getValue
215
+ end
216
+
217
+ protected
218
+ #@private
219
+ # Return the element
220
+ def element(refresh = false)
221
+ if (@elm == nil || refresh == true)
222
+ @elm = find
223
+ end
224
+
225
+ raise(Exceptions::UnknownObjectException, "Element #{@selector} not found using #{@method}") unless @elm
226
+ @elm
227
+ end
228
+
229
+
230
+ private
231
+
232
+ def drag_and_drop_on(other, drop_pos)
233
+ element.dragAndDropOn(other.element, DROPPOSITION_ENUM_MAP[drop_pos])
234
+ end
235
+
236
+ # Gets the widget name (used as parent name when creating child widget)
237
+ def parent_widget
238
+ if @selector == nil && @elm != nil
239
+ set_selector
240
+ end
241
+
242
+ #FIXME: Shouldn't this always be name if present, then text if present, else pos?
243
+ case @method
244
+ when :name
245
+ name
246
+ when :text
247
+ #text
248
+ name.length > 0 ? name : text
249
+ when :pos
250
+ # Pos items will have the name as the parent or
251
+ # the text if there is no name
252
+ name.length > 0 ? name : text
253
+ end
254
+ end
255
+
256
+ # Get row
257
+ def row
258
+ element.getRow()
259
+ end
260
+
261
+ # Get column
262
+ def col
263
+ element.getColumn()
264
+ end
265
+
266
+ # Gets the window id to use for the search
267
+ def window_id
268
+ # Need to pass on the current setting of @window_id to make
269
+ # nesting of quick widgets work
270
+ @window_id
271
+ end
272
+
273
+ # Click widget
274
+ def click(button = :left, times = 1, *opts)
275
+ raise Exceptions::WidgetDisabledException, "Element #{@selector} is disabled" unless enabled?
276
+
277
+ #Some buttons etc. aren't visible until hovering them
278
+ if (visible? == false and type != :dialogtab)
279
+ element.hover
280
+ element(true)
281
+ end
282
+
283
+ # Dialog tabs are always visible even if the page they are connected to isn't
284
+ if visible? == true or type == :dialogtab
285
+ #DesktopEnums::KEYMODIFIER_ENUM_MAP.each { |k, v| puts "#{k},#{v}"}
286
+ button = DesktopEnums::MOUSEBUTTON_ENUM_MAP[button]
287
+ list = Java::JavaUtil::ArrayList.new
288
+ opts.each { |mod| list << DesktopEnums::KEYMODIFIER_ENUM_MAP[mod] }
289
+ element.click(button, times, list)
290
+ else
291
+ raise(DesktopExceptions::WidgetNotVisibleException, "Widget #{name.length > 0 ? name : text} not visible")
292
+ end
293
+ end
294
+
295
+ # Right click a widget
296
+ def right_click
297
+ click(:right, 1)
298
+ end
299
+
300
+ # double click widget
301
+ def double_click
302
+ click(:left, 2)
303
+ end
304
+
305
+
306
+ def set_selector
307
+ if @elm.name.length > 0
308
+ @method = :name
309
+ @selector = @elm.name
310
+ elsif @elm.text.length > 0
311
+ @method = :text
312
+ @selector = @elm.text
313
+ elsif @elm.type == :treeitem
314
+ @method = :pos
315
+ @selector = [@elm.row, @elm.col]
316
+ =begin
317
+ # tabbuttons now specified by generated name
318
+ elsif @elm.type == :tabbutton
319
+ @method = :pos
320
+ @selector = @elm.col
321
+ =end
322
+ end
323
+ @location = element.getParentName()
324
+ @window_id = -1
325
+ end
326
+
327
+ # Finds the element on the page.
328
+ def find
329
+ #If @method set and we do new find because of refresh, we need to get @selector first
330
+ #Have the java object because the construct was done on it
331
+ if @selector == nil && @elm != nil
332
+ set_selector
333
+ end
334
+ #puts "<find> Find Widget by " + @method.to_s + " " + @window_id.to_s + ", " + @selector.to_s + ", " + @location.to_s
335
+ case @method
336
+ when :name
337
+ if @location != nil
338
+ @element = driver.findWidgetByName(@window_id, @selector, @location)
339
+ else
340
+ @element = driver.findWidgetByName(@window_id, @selector)
341
+ end
342
+ when :string_id
343
+ if @location != nil
344
+ @element = driver.findWidgetByStringId(@window_id, @selector, @location)
345
+ else
346
+ @element = driver.findWidgetByStringId(@window_id, @selector)
347
+ end
348
+ when :text
349
+ if @location != nil
350
+ @element = driver.findWidgetByText(@window_id, @selector, @location)
351
+ else
352
+ @element = driver.findWidgetByText(@window_id, @selector)
353
+ end
354
+ when :pos
355
+ if @location != nil
356
+ @element = driver.findWidgetByPosition(@window_id, @selector[0], @selector[1], @location)
357
+ else
358
+ @element = driver.findWidgetByPosition(@window_id, @selector[0], @selector[1])
359
+ end
360
+ end
361
+ if @window_id < 0 && @element != nil
362
+ @window_id = @element.getParentWindowId
363
+ end
364
+ raise(Exceptions::UnknownObjectException, "Element #{@selector} not found using #{@method}") unless @element
365
+ raise(Exceptions::UnknownObjectException, "Element #{@selector} has wrong type #{@element.getType}") unless correct_type?
366
+ @element
367
+ end
368
+ end
369
+ end
@@ -0,0 +1,150 @@
1
+ module OperaWatir
2
+ class QuickWindow
3
+ include DesktopCommon
4
+ include DesktopContainer
5
+
6
+ # @private
7
+ def initialize(container, method, selector=nil)
8
+ @container = container
9
+
10
+ if method.is_a? Java::ComOperaCoreSystems::QuickWindow
11
+ @elm = method
12
+ else
13
+ @method = method
14
+ @selector = selector
15
+ end
16
+ end
17
+
18
+ ######################################################################
19
+ # Checks whether a widget exists or not
20
+ #
21
+ # @return [Boolean] true if the widget exists otherwise false
22
+ #
23
+ def exist?
24
+ !!element
25
+ rescue Exceptions::UnknownObjectException
26
+ false
27
+ end
28
+ alias_method :exists?, :exist?
29
+
30
+ ######################################################################
31
+ # Gets the type of a widget
32
+ #
33
+ # @return [Symbol] type of the window (e.g. :dropdown, :button)
34
+ #
35
+ def type
36
+ return WINDOW_ENUM_MAP.invert[@elm.getType] unless @elm == nil
37
+ return WINDOW_ENUM_MAP.invert[element.getType]
38
+ end
39
+
40
+ ######################################################################
41
+ # Get the name of the widget (as it appears in dialog.ini or code)
42
+ #
43
+ # @return [String] name of the widget
44
+ #
45
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
46
+ # using the specified method
47
+ def name
48
+ element.getName
49
+ end
50
+
51
+ ######################################################################
52
+ # Get the title of the window
53
+ #
54
+ # @return [String] title of window
55
+ #
56
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
57
+ # using the specified method
58
+ def title
59
+ element.getTitle
60
+ end
61
+
62
+
63
+ ######################################################################
64
+ # Get a string representation of the window
65
+ #
66
+ # @return [String] representation of the widget
67
+ #
68
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
69
+ # using the specified method
70
+ def to_s
71
+ "#{type} #{name}, title=#{title}, id=#{id}, on_screen=#{on_screen?}"
72
+ end
73
+
74
+ ######################################################################
75
+ #
76
+ # @return [bool] true if window is on screen
77
+ #
78
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
79
+ # using the specified method
80
+ def on_screen?
81
+ element.isOnScreen
82
+ end
83
+
84
+ alias_method :visible?, :on_screen?
85
+
86
+ ######################################################################
87
+ # Get the window id
88
+ #
89
+ # @return [int] the windows window_id
90
+ #
91
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
92
+ # using the specified method
93
+ def window_id
94
+ element.getWindowID
95
+ end
96
+
97
+ alias_method :id, :window_id
98
+
99
+ ######################################################################
100
+ # Prints out all of the internal information about the window. Used
101
+ # to discover the names of widgets and windows to use in the tests
102
+ #
103
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
104
+ # using the specified method
105
+ def print_window_info
106
+ puts " Name: " + name
107
+ puts " Title: " + title
108
+ puts " ID: " + id.to_s
109
+ puts " Type: " + type.to_s
110
+ puts "OnScreen: " + on_screen?.to_s
111
+ puts " Pos: x=" + element.getRect().x.to_s + ", y=" + element.getRect().y.to_s
112
+ puts " Size: width=" + element.getRect().width.to_s + ", height=" + element.getRect().height.to_s
113
+ puts ""
114
+ end
115
+
116
+ # @private
117
+ def driver
118
+ @container.driver
119
+ end
120
+
121
+ private
122
+
123
+ # Gets the parent widget name of which there is none here
124
+ def parent_widget
125
+ nil
126
+ end
127
+
128
+ # Return the element
129
+ def element(refresh = false)
130
+ if (@elm == nil || refresh == true)
131
+ @elm = find
132
+ end
133
+
134
+ raise(Exceptions::UnknownObjectException, "Window #{@selector} not found using #{@method}") unless @elm
135
+ @elm
136
+ end
137
+
138
+ # Finds the element on the page.
139
+ def find
140
+ case @method
141
+ when :name
142
+ @element = driver.findWindowByName(@selector)
143
+ when :id
144
+ @element = driver.findWindowById(@selector)
145
+ end
146
+ raise(Exceptions::UnknownObjectException, "Window #{@selector} not found using #{@method}") unless @element
147
+ @element
148
+ end
149
+ end
150
+ end