operawatir 0.4.3.pre1-jruby → 0.5-jruby

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.
Files changed (98) hide show
  1. data/.gitmodules +1 -1
  2. data/CHANGES +230 -0
  3. data/Gemfile +4 -0
  4. data/Rakefile +3 -2
  5. data/VERSION +1 -1
  6. data/bin/desktopwatir +1 -1
  7. data/bin/operawatir +16 -4
  8. data/lib/operadriver/guava-r09.jar +0 -0
  9. data/lib/operadriver/operadriver-v0.7.2.jar +0 -0
  10. data/lib/operadriver/selenium-nodeps-20100909.jar +0 -0
  11. data/lib/operawatir.rb +10 -3
  12. data/lib/operawatir/actions.rb +111 -0
  13. data/lib/operawatir/browser.rb +24 -20
  14. data/lib/operawatir/clickable_item.rb +68 -0
  15. data/lib/operawatir/compat.rb +4 -4
  16. data/lib/operawatir/compat/collection.rb +1 -1
  17. data/lib/operawatir/compat/element.rb +1 -1
  18. data/lib/operawatir/compat/window.rb +4 -3
  19. data/lib/operawatir/desktop_browser.rb +299 -95
  20. data/lib/operawatir/desktop_common.rb +88 -23
  21. data/lib/operawatir/desktop_container.rb +103 -34
  22. data/lib/operawatir/desktop_enums.rb +4 -4
  23. data/lib/operawatir/desktop_exceptions.rb +2 -2
  24. data/lib/operawatir/desktop_helper.rb +31 -8
  25. data/lib/operawatir/element.rb +6 -2
  26. data/lib/operawatir/exceptions.rb +4 -4
  27. data/lib/operawatir/helper.rb +6 -6
  28. data/lib/operawatir/keys.rb +4 -4
  29. data/lib/operawatir/preferences.rb +126 -155
  30. data/lib/operawatir/quickwidgets.rb +3 -3
  31. data/lib/operawatir/quickwidgets/quick_addressfield.rb +12 -5
  32. data/lib/operawatir/quickwidgets/quick_button.rb +39 -53
  33. data/lib/operawatir/quickwidgets/quick_checkbox.rb +6 -6
  34. data/lib/operawatir/quickwidgets/quick_dialogtab.rb +5 -5
  35. data/lib/operawatir/quickwidgets/quick_dropdown.rb +28 -4
  36. data/lib/operawatir/quickwidgets/quick_dropdownitem.rb +46 -0
  37. data/lib/operawatir/quickwidgets/quick_editfield.rb +16 -13
  38. data/lib/operawatir/quickwidgets/quick_label.rb +1 -1
  39. data/lib/operawatir/quickwidgets/quick_menu.rb +155 -0
  40. data/lib/operawatir/quickwidgets/quick_menuitem.rb +387 -0
  41. data/lib/operawatir/quickwidgets/quick_searchfield.rb +7 -4
  42. data/lib/operawatir/quickwidgets/quick_tab.rb +23 -12
  43. data/lib/operawatir/quickwidgets/quick_thumbnail.rb +4 -4
  44. data/lib/operawatir/quickwidgets/quick_toolbar.rb +1 -1
  45. data/lib/operawatir/quickwidgets/quick_treeitem.rb +45 -29
  46. data/lib/operawatir/quickwidgets/quick_treeview.rb +2 -2
  47. data/lib/operawatir/quickwidgets/quick_widget.rb +267 -77
  48. data/lib/operawatir/quickwidgets/quick_window.rb +64 -38
  49. data/lib/operawatir/screenshot.rb +1 -1
  50. data/lib/operawatir/utils.rb +31 -0
  51. data/lib/operawatir/window.rb +1 -1
  52. data/operawatir.gemspec +38 -132
  53. data/spec/operawatir/core/actions_spec.rb +202 -0
  54. data/spec/operawatir/core/browser_spec.rb +8 -8
  55. data/spec/operawatir/core/element_spec.rb +11 -2
  56. data/spec/operawatir/core/keys_spec.rb +50 -2
  57. data/spec/operawatir/core/preferences_spec.rb +44 -128
  58. data/spec/operawatir/core/spatnav_spec.rb +16 -16
  59. data/spec/operawatir/core/utils_spec.rb +47 -0
  60. data/spec/operawatir/core/window_spec.rb +1 -1
  61. data/spec/operawatir/desktop/desktopbrowser_spec.rb +191 -22
  62. data/spec/operawatir/desktop/quickbutton_spec.rb +197 -164
  63. data/spec/operawatir/desktop/quickcheckbox_spec.rb +12 -12
  64. data/spec/operawatir/desktop/quickdialogtab_spec.rb +11 -11
  65. data/spec/operawatir/desktop/quickdropdown_spec.rb +25 -25
  66. data/spec/operawatir/desktop/quickeditfield_spec.rb +31 -31
  67. data/spec/operawatir/desktop/quickmenu_spec.rb +57 -0
  68. data/spec/operawatir/desktop/quickmenuitem_spec.rb +168 -0
  69. data/spec/operawatir/desktop/quicktab_spec.rb +26 -15
  70. data/spec/operawatir/desktop/quickthumbnail_spec.rb +18 -4
  71. data/spec/operawatir/desktop/quicktreeitem_spec.rb +72 -72
  72. data/spec/operawatir/desktop/quicktreeview_spec.rb +13 -13
  73. data/spec/operawatir/desktop/quickwidget_spec.rb +51 -13
  74. data/spec/operawatir/desktop/quickwindow_spec.rb +4 -0
  75. data/spec/operawatir/desktop/shared/shared.rb +25 -9
  76. data/spec/operawatir/fixtures/draggableLists.html +67 -0
  77. data/spec/operawatir/fixtures/formSelectionPage.html +46 -0
  78. data/spec/operawatir/fixtures/js/jquery-1.4.4.min.js +167 -0
  79. data/spec/operawatir/fixtures/js/jquery-ui-1.8.10.custom.min.js +782 -0
  80. data/spec/operawatir/fixtures/keys.html +40 -0
  81. data/spec/operawatir/fixtures/label_submit.html +5 -0
  82. data/spec/operawatir/fixtures/mouse.html +59 -0
  83. data/spec/operawatir/fixtures/simple.html +10 -0
  84. data/spec/operawatir/matchers.rb +20 -19
  85. data/spec/operawatir/watirspec_desktophelper.rb +51 -3
  86. data/spec/operawatir/watirspec_helper.rb +0 -2
  87. metadata +91 -220
  88. data/lib/operadriver/client-combined-nodeps.jar +0 -0
  89. data/lib/operadriver/webdriver-opera.jar +0 -0
  90. data/spec/watir3/browser_spec.rb +0 -190
  91. data/spec/watir3/clipboard_spec.rb +0 -64
  92. data/spec/watir3/collection_spec.rb +0 -387
  93. data/spec/watir3/element_spec.rb +0 -474
  94. data/spec/watir3/guards.rb +0 -39
  95. data/spec/watir3/keys_spec.rb +0 -204
  96. data/spec/watir3/server.rb +0 -91
  97. data/spec/watir3/watirspec_helper.rb +0 -62
  98. data/spec/watir3/window_spec.rb +0 -295
@@ -6,7 +6,7 @@ module OperaWatir
6
6
  def correct_type?
7
7
  @element.getType == WIDGET_ENUM_MAP[:label]
8
8
  end
9
-
9
+
10
10
  end
11
11
  end
12
12
 
@@ -0,0 +1,155 @@
1
+ module OperaWatir
2
+ class QuickMenu < QuickWidget #??
3
+ # @private
4
+ # Checks the type of the widget is correct
5
+ #def correct_type?
6
+ # @element.getType == WIDGET_ENUM_MAP[:menu]
7
+ #end
8
+
9
+ # @private
10
+ # window_id is set if constructor is called on a (parent) window
11
+ # location if set is this is called on a (parent) widget
12
+ def initialize(container, method, selector=nil, location=nil)
13
+
14
+ @container = container
15
+
16
+ if method.is_a? Java::ComOperaCoreSystems::QuickMenu
17
+ @elm = method
18
+ else
19
+ @method = method
20
+ @selector = selector
21
+ @location = location
22
+ end
23
+ end
24
+
25
+ ####################################################################
26
+ #
27
+ # @example
28
+ # browser.quick_menu(:name, "Browser Button Menu Bar").name.should == "Browser Button Menu Bar"
29
+ #
30
+ # @return the name of the menu (as found in standard_menu.ini)
31
+ #
32
+ def name
33
+ element.getName
34
+ end
35
+
36
+
37
+ #######################################################################
38
+ #
39
+ # @return the window_id of the window the menu is attached to
40
+ #
41
+ # Note: This only makes sense for the menubars (and not on mac where there is
42
+ # only one menubar)
43
+ # Note: This makes it possible to distinguish between menubars in different
44
+ # main windows
45
+ #
46
+ # @example:
47
+ # browser.quick_menu(:name, "Main Menu").window_id
48
+ # browser.quick_window(:id, <id>).quick_menu(:name, "Browser File Menu")...
49
+ #
50
+ #
51
+ def window_id
52
+ element.getParentWindowId()
53
+ end
54
+
55
+ #######################################################################
56
+ #
57
+ # @return string representation of menu
58
+ #
59
+ def to_s
60
+ window = window_id > 0 ? "window_id #{window_id}" : ""
61
+ "QUICKMENU #{name} #{window}" # TODO: Add rect
62
+ end
63
+
64
+ ########################################################################
65
+ #
66
+ # @return width of widget
67
+ #
68
+ def width
69
+ element.getRect().width
70
+ end
71
+
72
+ ########################################################################
73
+ #
74
+ # @return height of widget
75
+ #
76
+ def height
77
+ element.getRect().height
78
+ end
79
+
80
+ #@private
81
+ def x
82
+ element.getRect().x
83
+ end
84
+
85
+ #@private
86
+ def y
87
+ element.getRect().y
88
+ end
89
+
90
+ ########################################################################
91
+ #
92
+ # @return true if this menu has one or more submenus
93
+ #
94
+ # @example
95
+ # menu.should be_parentmenu
96
+ #
97
+ def parentmenu?
98
+ element.getItemList().each do |item|
99
+ if item.hasSubMenu()
100
+ return true
101
+ end
102
+ end
103
+ false
104
+ end
105
+
106
+ ########################################################################
107
+ #
108
+ # @return array of all menuitems in this menu
109
+ #
110
+ # @example:
111
+ # menu.menuitems.select { |item| item.menu != menu.name }.should be_empty
112
+ # menu.menuitems.each { | item | puts item.name }
113
+ #
114
+ def quick_menuitems
115
+ element.getItemList().map do |java_item|
116
+ QuickMenuItem.new(self,java_item)
117
+ end
118
+ end
119
+
120
+ ######################################################################
121
+ # Checks whether a widget exists or not
122
+ #
123
+ # @return [Boolean] true if the widget exists otherwise false
124
+ #
125
+ def exist?
126
+ !!element
127
+ rescue Exceptions::UnknownObjectException
128
+ false
129
+ end
130
+ alias_method :exists?, :exist?
131
+
132
+ private
133
+
134
+ # Finds the element on the page.
135
+ def find
136
+ #If @method set and we do new find because of refresh, we need to get @selector first
137
+ #Have the java object because the construct was done on it
138
+ #if @selector == nil && @elm != nil
139
+ # set_selector
140
+ #end
141
+ #puts "\n<find> Find Menu by " + @method.to_s + ", " + @selector.to_s + ", " + @location.to_s
142
+ case @method
143
+ when :name
144
+ if @location != nil && @location >= 0
145
+ @element = driver.getQuickMenu(@selector, @location)
146
+ else
147
+ @element = driver.getQuickMenu(@selector)
148
+ end
149
+ end
150
+ raise(Exceptions::UnknownObjectException, "Element #{@selector} not found using #{@method}") unless @element
151
+ @element
152
+ end
153
+
154
+ end
155
+ end
@@ -0,0 +1,387 @@
1
+ module OperaWatir
2
+ class QuickMenuItem < QuickWidget #
3
+ # @private
4
+ # Checks the type of the widget is correct
5
+ #def correct_type?
6
+ # @element.getType == WIDGET_ENUM_MAP[:menuitem]
7
+ #end
8
+
9
+ # @private
10
+ # window_id is set if constructor is called on a (parent) window
11
+ # location is set is this is called on a (parent) widget
12
+ def initialize(container, method, selector=nil, location=nil)
13
+
14
+ #puts "QuickMenuItem initialize method #{method}, selector #{selector}"
15
+
16
+ @container = container
17
+
18
+ if method.is_a? Java::ComOperaCoreSystems::QuickMenuItem
19
+ @elm = method
20
+ else
21
+ @method = method
22
+ @selector = selector
23
+ @location = location
24
+ end
25
+ end
26
+
27
+ #########################################################################
28
+ #
29
+ # Returns the name of the menuitem. The name is either the action name
30
+ # of the action the item performs, or the name of the submenu the item
31
+ # opens. If the item is a separator, the name is "Separator"
32
+ #
33
+ # @example (RSpec)
34
+ # menuitem.name.should == "Separator"
35
+ # menuitem.name.should == "Close page" #action
36
+ # menuitem.name.should == "Toolbar Popup Customize Menu" #submenu
37
+ #
38
+ # @return name of menuitem
39
+ #
40
+ def name
41
+ element.getName();
42
+ end
43
+
44
+ ##########################################################################
45
+ #
46
+ # @return name of the menu this menuitem is part of
47
+ #
48
+ # @example
49
+ # browser.quick_menu(:name, "Browser File Menu").quick_menuitem(:text, "Open File").menu
50
+ #
51
+ #
52
+ def menu
53
+ element.getMenu()
54
+ end
55
+
56
+ ##########################################################################
57
+ #
58
+ # @return the text of this menu item
59
+ #
60
+ # (Note: this should normally not be used to access the item, as it will
61
+ # be language dependent)
62
+ #
63
+ def text
64
+ element.getText()
65
+ end
66
+
67
+ ######################################################################
68
+ #
69
+ # @return true if element is a checkbox item that is checked, else false
70
+ #
71
+ def checked?
72
+ element.isChecked()
73
+ end
74
+
75
+ #####################################################################
76
+ #
77
+ # @return true if this menuitem has bold text, otherwise false
78
+ #
79
+ def bold?
80
+ element.isBold()
81
+ end
82
+
83
+ #####################################################################
84
+ #
85
+ # @return true if this menuitem is a separator, else false
86
+ #
87
+ def separator?
88
+ element.isSeparator()
89
+ end
90
+
91
+ #####################################################################
92
+ #
93
+ # @return true if this item is a command/action item
94
+ #
95
+ def action_item?
96
+ action.length > 0
97
+ end
98
+
99
+ #####################################################################
100
+ #
101
+ # @return true if this menuitem opens a submenu, otherwise false
102
+ #
103
+ def submenu_item?
104
+ element.hasSubMenu()
105
+ end
106
+
107
+ #####################################################################
108
+ #
109
+ # @return shortcutletter of this menuitem (typing this letter while the
110
+ # menu is open, will select the item)
111
+ #
112
+ # @example (t is shortcutletter to open submenu below)
113
+ # addressfield.open_menu_with_rightclick("Toolbar Edit Item Popup Menu")
114
+ # browser.open_menu_with_key_press("Toolbar Popup Customize Menu", "t")
115
+ #
116
+ # (Note: not used on mac, so not a platform dependant feature)
117
+ def shortcutletter
118
+ element.getShortcutLetter()
119
+ end
120
+
121
+ #####################################################################
122
+ #
123
+ # @return the shortcut of this menuitem as a string
124
+ #
125
+ # browser.quick_menuitem(:action, "Close page").shortcut # Ctrl+W
126
+ #
127
+ def shortcut
128
+ element.getShortcut()
129
+ end
130
+
131
+ #####################################################################
132
+ #
133
+ # @return position of this menuitem within the menu, also counting
134
+ # separators
135
+ #
136
+ # browser.quick_menu(:name, "Browser Tools Menu").quick_menuitem(:pos, 2).name.should == "Separator"
137
+ #
138
+ def pos
139
+ element.getRow()
140
+ end
141
+
142
+ #####################################################################
143
+ #
144
+ # @return the name of the action this item executes when selected
145
+ #
146
+ def action
147
+ element.getActionName()
148
+ end
149
+
150
+ ########################################################################
151
+ #
152
+ # @return the parameters to the action that will be used for the action
153
+ # executed for this item when it is selected
154
+ #
155
+ def action_params
156
+ element.getActionParameter()
157
+ end
158
+
159
+ ##########################################################################
160
+ #
161
+ # @return the name of the submenu this item opens
162
+ #
163
+ # (Note: an item will either have a submenu, or an action)
164
+ #
165
+ def submenu
166
+ element.getSubMenu()
167
+ end
168
+
169
+
170
+ ########################################################################
171
+ #
172
+ # @return width of the menuitem
173
+ #
174
+ def width
175
+ element.getRect().width
176
+ end
177
+
178
+ ########################################################################
179
+ #
180
+ # @return height of the menuitem
181
+ #
182
+ def height
183
+ element.getRect().height
184
+ end
185
+
186
+ #@private
187
+ def x
188
+ element.getRect().x
189
+ end
190
+
191
+ #@private
192
+ def y
193
+ element.getRect().y
194
+ end
195
+
196
+ ########################################################################
197
+ # Hovers the menuitem and waits for the menu with menu_name to open
198
+ #
199
+ # @example
200
+ # menu.quick_menuitem(:submenu, "Toolbar Popup Customize Menu").open_menu_with_hover("Toolbar Popup Customize Menu")
201
+ #
202
+ # @param [String] name of menu that will open
203
+ #
204
+ # @return name of menu opened if it matches menu_name parameter,
205
+ # otherwise returns the empty string
206
+ #
207
+ def open_menu_with_hover(menu_name)
208
+ if mac_internal?
209
+ wait_start
210
+ press_menu
211
+ wait_for_menu_pressed
212
+ else
213
+ wait_start
214
+ element.hover
215
+ wait_for_menu_shown(menu_name)
216
+ end
217
+ end
218
+
219
+ ######################################################################
220
+ # Use to toggle a checkbox or radio item menuitem
221
+ #
222
+ def toggle_with_click
223
+ if mac_internal?
224
+ wait_start
225
+ press_menu
226
+ wait_for_menu_pressed
227
+ else
228
+ click
229
+
230
+ # Cheat since we don't have an event yet
231
+ sleep(0.1)
232
+ end
233
+ end
234
+
235
+ def to_s
236
+ "QUICKMENUITEM #{name}, pos #{pos}, menu #{menu}, rect: #{x}, #{y}, #{width}, #{height}, checked? #{checked?}, pos #{pos}, acckey #{shortcutletter}, #{shortcut unless shortcut.nil?}, separator #{separator?}"
237
+ end
238
+
239
+
240
+ ######################################################################
241
+ # Clicks the button, and waits for loading to finish
242
+ #
243
+ # @return [int] Window ID of the window shown or 0 if no window is shown
244
+ #
245
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the button
246
+ # is not visible
247
+ #
248
+ def load_page_with_click
249
+ if mac_internal?
250
+ wait_start
251
+ press_menu
252
+ wait_for_menu_pressed
253
+ wait_start
254
+ # Just wait for the load
255
+ wait_for_window_loaded("")
256
+ else
257
+ wait_start
258
+ click
259
+ # Just wait for the load
260
+ wait_for_window_loaded("")
261
+ end
262
+ end
263
+
264
+ ######################################################################
265
+ # Clicks the button, and waits for the window with window name
266
+ # win_name to be shown
267
+ #
268
+ # @param [String] win_name name of the window that will be opened (Pass a blank string for any window)
269
+ #
270
+ # @return [int] Window ID of the window shown or 0 if no window is shown
271
+ #
272
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the button
273
+ # is not visible
274
+ #
275
+ def open_window_with_click(win_name)
276
+ if mac_internal?
277
+ wait_start
278
+ press_menu
279
+ wait_for_menu_pressed
280
+ wait_start
281
+ wait_for_window_shown(win_name)
282
+ else
283
+ wait_start
284
+ click
285
+ wait_for_window_shown(win_name)
286
+ end
287
+ end
288
+ alias_method :open_dialog_with_click, :open_window_with_click
289
+
290
+
291
+ ######################################################################
292
+ # Clicks item and waits for the menu to close
293
+ #
294
+ # @return name of menu closed
295
+ #
296
+ def close_menu_with_key_press(menu_name, key, *modifiers)
297
+ wait_start
298
+ key_press_direct(key, *modifiers)
299
+ wait_for_menu_closed(menu_name)
300
+ end
301
+
302
+ ######################################################################
303
+ # Clicks the item, and waits for the menu with menu with name
304
+ # menu_name to be shown
305
+ #
306
+ # @param [String] name of menu that should open
307
+ #
308
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the button
309
+ # is not visible
310
+ #
311
+ # @return name of menu opened if it matches menu_name (or if menu_name is ""),
312
+ # otherwise returns empty string
313
+ #
314
+ def open_menu_with_click(menu_name)
315
+ if mac_internal?
316
+ wait_start
317
+ press_menu
318
+ wait_for_menu_pressed
319
+ else
320
+ wait_start
321
+ click
322
+ wait_for_menu_shown(menu_name)
323
+ end
324
+ end
325
+
326
+ ######################################################################
327
+ # Clicks item and waits for the menu to close
328
+ #
329
+ # @return name of menu closed
330
+ #
331
+ def close_menu_with_click(menu_name)
332
+ wait_start
333
+ click
334
+ wait_for_menu_closed(menu_name)
335
+ end
336
+
337
+ private
338
+
339
+ # Finds the element on the page.
340
+ def find
341
+ #If @method set and we do new find because of refresh, we need to get @selector first
342
+ #Have the java object because the construct was done on it
343
+ #if @selector == nil && @elm != nil
344
+ # set_selector
345
+ #end
346
+ #puts "\n<find MenuItem> Find MenuItem by " + @method.to_s + ", " + @selector.to_s + ", " + @location.to_s
347
+ case @method
348
+ # action or submenu name?
349
+ when :name
350
+ if @location.class == Fixnum && @location >= 0
351
+ @element = driver.getQuickMenuItemByName(@selector, @location)
352
+ else
353
+ @element = driver.getQuickMenuItemByName(@selector)
354
+ end
355
+ when :action
356
+ @element = driver.getQuickMenuItemByAction(@selector)
357
+ when :submenu
358
+ @element = driver.getQuickMenuItemBySubmenu(@selector)
359
+ when :text
360
+ @element = driver.getQuickMenuItemByText(@selector)
361
+ when :pos # only row
362
+ @element = driver.getQuickMenuItemByPosition(@selector, @location)
363
+ when :acckey
364
+ @element = driver.getQuickMenuItemByAccKey(@selector, @location)
365
+ when :shortcut
366
+ @element = driver.getQuickMenuItemByShortcut(@selector)
367
+ when :string_id
368
+ @element = driver.getQuickMenuItemByStringId(@selector)
369
+ end
370
+
371
+ raise(Exceptions::UnknownObjectException, "Element #{@selector} not found using #{@method}") unless @element
372
+ @element
373
+ end
374
+
375
+ # Presses a menu on Mac where you can't click them
376
+ def press_menu
377
+ driver.pressQuickMenuItem(text, false);
378
+ end
379
+
380
+ # Waits for the menu to be pressed
381
+ def wait_for_menu_pressed
382
+ name = driver.waitForMenuItemPressed(text)
383
+ name
384
+ end
385
+
386
+ end
387
+ end