operawatir 0.4.1.pre5-jruby → 0.4.1.pre6-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 (60) hide show
  1. data/AUTHORS +1 -0
  2. data/CHANGES +170 -3
  3. data/README.md +30 -27
  4. data/VERSION +1 -1
  5. data/bin/desktopwatir +19 -16
  6. data/bin/operawatir +4 -4
  7. data/lib/operadriver/client-combined-nodeps.jar +0 -0
  8. data/lib/operadriver/webdriver-opera.jar +0 -0
  9. data/lib/operawatir/browser.rb +1 -2
  10. data/lib/operawatir/collection.rb +1 -1
  11. data/lib/operawatir/compat/collection.rb +13 -0
  12. data/lib/operawatir/compat/element.rb +57 -15
  13. data/lib/operawatir/compat/window.rb +41 -0
  14. data/lib/operawatir/desktop_browser.rb +26 -9
  15. data/lib/operawatir/desktop_container.rb +82 -29
  16. data/lib/operawatir/element.rb +48 -24
  17. data/lib/operawatir/keys.rb +18 -25
  18. data/lib/operawatir/preferences.rb +223 -6
  19. data/lib/operawatir/quickwidgets/quick_button.rb +8 -2
  20. data/lib/operawatir/quickwidgets/quick_checkbox.rb +4 -4
  21. data/lib/operawatir/quickwidgets/quick_editfield.rb +1 -1
  22. data/lib/operawatir/quickwidgets/quick_find.rb +11 -0
  23. data/lib/operawatir/quickwidgets/quick_griditem.rb +11 -0
  24. data/lib/operawatir/quickwidgets/quick_gridlayout.rb +11 -0
  25. data/lib/operawatir/quickwidgets/quick_searchfield.rb +5 -1
  26. data/lib/operawatir/quickwidgets/quick_tab.rb +0 -1
  27. data/lib/operawatir/quickwidgets/quick_treeitem.rb +22 -1
  28. data/lib/operawatir/quickwidgets/quick_widget.rb +61 -22
  29. data/lib/operawatir/quickwidgets/quick_window.rb +26 -0
  30. data/lib/operawatir/quickwidgets.rb +2 -1
  31. data/lib/operawatir/window.rb +36 -25
  32. data/lib/operawatir.rb +1 -1
  33. data/operawatir.gemspec +38 -5
  34. data/spec/operawatir/core/element_spec.rb +5 -0
  35. data/spec/operawatir/core/window_spec.rb +42 -0
  36. data/spec/operawatir/desktop/desktopbrowser_spec.rb +16 -0
  37. data/spec/operawatir/desktop/quickaddressfield_spec.rb +15 -3
  38. data/spec/operawatir/desktop/quickbutton_spec.rb +234 -20
  39. data/spec/operawatir/desktop/quickcheckbox_spec.rb +36 -0
  40. data/spec/operawatir/desktop/quickdialogtab_spec.rb +30 -0
  41. data/spec/operawatir/desktop/quickdropdown_spec.rb +39 -0
  42. data/spec/operawatir/desktop/quickeditfield_spec.rb +51 -0
  43. data/spec/operawatir/desktop/quickfind_spec.rb +30 -0
  44. data/spec/operawatir/desktop/quickgriditem_spec.rb +16 -0
  45. data/spec/operawatir/desktop/quickgridlayout_spec.rb +15 -0
  46. data/spec/operawatir/desktop/quicklabel_spec.rb +28 -0
  47. data/spec/operawatir/desktop/quickradiobutton_spec.rb +24 -0
  48. data/spec/operawatir/desktop/quicksearchfield_spec.rb +26 -0
  49. data/spec/operawatir/desktop/quicktab_spec.rb +86 -0
  50. data/spec/operawatir/desktop/quickthumbnail_spec.rb +37 -0
  51. data/spec/operawatir/desktop/quicktreeitem_spec.rb +135 -0
  52. data/spec/operawatir/desktop/quicktreeview_spec.rb +30 -0
  53. data/spec/operawatir/desktop/quickwidget_spec.rb +52 -11
  54. data/spec/operawatir/desktop/quickwindow_spec.rb +11 -0
  55. data/spec/operawatir/desktop/shared/shared.rb +100 -10
  56. data/spec/operawatir/fixtures/browsers.svg +367 -0
  57. data/spec/operawatir/fixtures/frames.html +13 -0
  58. data/spec/watir2/select_list_spec.rb +84 -71
  59. metadata +37 -4
  60. data/lib/operadriver/selenium-common.jar +0 -0
@@ -89,7 +89,8 @@ module OperaWatir
89
89
  # Clicks a button or expand control and toggles it state
90
90
  #
91
91
  # @return [int] the new state of the button or expand control,
92
- # 0 for not pressed, or 1 for pressed
92
+ # 0 for not pressed, or 1 for pressed,
93
+ # nil if the element does no longer exist
93
94
  #
94
95
  # @raise [DesktopExceptions::WidgetNotVisibleException] if the button
95
96
  # is not visible
@@ -100,7 +101,12 @@ module OperaWatir
100
101
  # Cheat since we don't have an event yet
101
102
  sleep(0.1)
102
103
 
103
- element(true).getValue
104
+ # Note: click might have made this element dissapear ...
105
+ begin
106
+ element(true).getValue
107
+ rescue Exceptions::UnknownObjectException
108
+ nil
109
+ end
104
110
  end
105
111
 
106
112
  ######################################################################
@@ -33,6 +33,7 @@ module OperaWatir
33
33
  # Cheat since we don't have an even yet
34
34
  sleep(0.1)
35
35
 
36
+ # is this guaranteed to be same as getValue?
36
37
  element(true).isSelected
37
38
  end
38
39
 
@@ -49,10 +50,9 @@ module OperaWatir
49
50
  # is not visible
50
51
  #
51
52
  def open_dialog_with_click(win_name)
52
- super
53
- #wait_start
54
- #click
55
- #wait_for_window_shown(win_name)
53
+ wait_start
54
+ click
55
+ wait_for_window_shown(win_name)
56
56
  end
57
57
 
58
58
  end
@@ -20,7 +20,7 @@ module OperaWatir
20
20
  ######################################################################
21
21
  # Types a text string into the edit field
22
22
  #
23
- # @note Only chanracters that appear on the keyboard that is currently
23
+ # @note Only characters that appear on the keyboard that is currently
24
24
  # selected can be typed, and the edit field must have focus.
25
25
  #
26
26
  # @param [String] text text string to type in
@@ -0,0 +1,11 @@
1
+ module OperaWatir
2
+ class QuickFind < QuickDropdown
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:quickfind]
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module OperaWatir
2
+ class QuickGridItem < QuickWidget
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:griditem]
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module OperaWatir
2
+ class QuickGridLayout < QuickWidget
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:gridlayout]
8
+ end
9
+
10
+ end
11
+ end
@@ -19,8 +19,12 @@ module OperaWatir
19
19
  def search_with_text(search_text)
20
20
  # Must focus field before calling enter_text...
21
21
  focus_with_click
22
+
22
23
  # Enters text in a field and then hits enter
23
- enter_text_and_hit_enter(search_text)
24
+ t = enter_text_and_hit_enter(search_text)
25
+
26
+ # return text in addressfield (in same window as search field)
27
+ driver.findWidgetByName(WIDGET_ENUM_MAP[:addressfield], @window_id, "tba_address_field", "Document Toolbar").getText
24
28
  end
25
29
 
26
30
  end
@@ -12,7 +12,6 @@ module OperaWatir
12
12
  #
13
13
  # @param [QuickTab] tab button to drop this tab on
14
14
  #
15
- #
16
15
  # @raise [DesktopExceptions::UnknownObjectException] if the target is not a tab
17
16
  #
18
17
  def move_with_drag(tab_target)
@@ -10,8 +10,10 @@ module OperaWatir
10
10
  ######################################################################
11
11
  # Set focus to the tree item by clicking on it
12
12
  #
13
- # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeview
13
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeview
14
14
  # the treeitem is in is not visible
15
+ # @raise [DesktopExceptions::WidgetDisabledException] if the treeitem
16
+ # is disabled
15
17
  #
16
18
  def focus_with_click
17
19
  # First scroll the item into view
@@ -29,6 +31,8 @@ module OperaWatir
29
31
  # For now there is no difference to focusing
30
32
  focus_with_click
31
33
  end
34
+
35
+ alias_method :collapse_with_click, :expand_with_click
32
36
 
33
37
  ######################################################################
34
38
  # Expands a tree item when it is double clicked
@@ -111,6 +115,23 @@ module OperaWatir
111
115
  end
112
116
 
113
117
  alias_method :open_dialog_with_double_click, :open_window_with_double_click
118
+
119
+ ######################################################################
120
+ # Double clicks the tree item, and waits for the window with
121
+ # window name win_name to be loaded with the url of the treeitem
122
+ #
123
+ # @param [String] win_name name of the window that will be loaded (Pass a blank string for any window)
124
+ #
125
+ # @return [int] Window ID of the window shown or 0 if no window is shown
126
+ #
127
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
128
+ # is not visible
129
+ #
130
+ def load_window_with_double_click(win_name)
131
+ wait_start
132
+ click(:left, 2)
133
+ wait_for_window_loaded(win_name)
134
+ end
114
135
 
115
136
 
116
137
  private
@@ -2,17 +2,20 @@ module OperaWatir
2
2
  class QuickWidget
3
3
  include DesktopCommon
4
4
  include DesktopContainer
5
+ include Deprecated
5
6
 
6
7
  # @private
7
8
  # window_id is set if constructor is called on a (parent) window
8
9
  # location is set is this is called on a (parent) widget
9
- def initialize(container, method, selector=nil, location=nil, window_id=-1)
10
+ def initialize(container, method, selector=nil, location=nil, window_id=-1, type=nil)
10
11
  @container = container
11
12
 
12
13
  if method.is_a? Java::ComOperaCoreSystems::QuickWidget
13
14
  @elm = method
15
+ @type = WIDGET_ENUM_MAP.invert[method.getType]
14
16
  else
15
17
  @method = method
18
+ @type = type
16
19
  @selector = selector
17
20
  @location = location
18
21
  @window_id = window_id
@@ -70,8 +73,7 @@ module OperaWatir
70
73
  # Gets the text of the widget
71
74
  #
72
75
  # @note This method should not be used to check the text in a widget if
73
- # the text is in the Opera language file. Use verify_text or
74
- # verify_includes_text instead
76
+ # the text is in the Opera language file. Use verify_text instead
75
77
  #
76
78
  # @return [String] text of the widget
77
79
  #
@@ -121,6 +123,7 @@ module OperaWatir
121
123
  ######################################################################
122
124
  # Checks that the text in the widget matches the text as loaded
123
125
  # from the current language file in Opera using the string_id
126
+ # (Strips &'s from the string before comparing)
124
127
  #
125
128
  # @param [String] string_id String ID to use to load the string from the current
126
129
  # language file (e.g. "D_NEW_PREFERENCES_GENERAL")
@@ -131,10 +134,17 @@ module OperaWatir
131
134
  # using the specified method
132
135
  #
133
136
  def verify_text(string_id)
134
- element.verifyText(string_id);
137
+ text = driver.getString(string_id, true) #true => stripAmpersands from string
138
+ if text.include? "%"
139
+ text.gsub!(/%[csduoxefg0-9]/, ".*")
140
+ res = /#{text}/ =~ element.getText()
141
+ res == nil ? false: true
142
+ else
143
+ element.verifyText(string_id)
144
+ end
135
145
  end
136
146
 
137
- alias_method :is_text?, :verify_text
147
+ alias_method :has_ui_string?, :verify_text
138
148
 
139
149
  ######################################################################
140
150
  # Checks that the text in the widget includes the text as loaded
@@ -153,6 +163,8 @@ module OperaWatir
153
163
  end
154
164
 
155
165
  alias_method :includes_text?, :verify_includes_text
166
+ deprecated :verify_includes_text
167
+ deprecated :includes_text?
156
168
 
157
169
  ######################################################################
158
170
  # Prints out all of the row/col information in single lines. Used to
@@ -187,8 +199,35 @@ module OperaWatir
187
199
  def position
188
200
  return [row, col] if type == :treeitem
189
201
  return col if type == :tabbutton
202
+ return col if type == :button
190
203
  false
191
204
  end
205
+
206
+ ########################################################################
207
+ #
208
+ # @return width of widget
209
+ #
210
+ def width
211
+ element.getRect().width
212
+ end
213
+
214
+ ########################################################################
215
+ #
216
+ # @return height of widget
217
+ #
218
+ def height
219
+ element.getRect().height
220
+ end
221
+
222
+ #@private
223
+ def x
224
+ element.getRect().x
225
+ end
226
+
227
+ #@private
228
+ def y
229
+ element.getRect().y
230
+ end
192
231
 
193
232
  ######################################################################
194
233
  # Prints out all of the internal information about the widget. Used
@@ -244,7 +283,7 @@ module OperaWatir
244
283
  def value
245
284
  return element.getValue
246
285
  end
247
-
286
+
248
287
  protected
249
288
  #@private
250
289
  # Return the element
@@ -256,8 +295,8 @@ protected
256
295
  raise(Exceptions::UnknownObjectException, "Element #{@selector} not found using #{@method}") unless @elm
257
296
  @elm
258
297
  end
259
-
260
-
298
+
299
+
261
300
  private
262
301
 
263
302
  def drag_and_drop_on(other, drop_pos)
@@ -304,15 +343,15 @@ private
304
343
  # Click widget
305
344
  def click(button = :left, times = 1, *opts)
306
345
  raise DesktopExceptions::WidgetDisabledException, "Element #{@selector} is disabled" unless enabled?
307
-
346
+
308
347
  #Some buttons etc. aren't visible until hovering them
309
348
  if (visible? == false and type != :dialogtab)
310
349
  element.hover
311
350
  element(true)
312
351
  end
313
-
352
+
314
353
  # Dialog tabs are always visible even if the page they are connected to isn't
315
- if visible? == true or type == :dialogtab
354
+ if visible? == true or type == :dialogtab
316
355
  button = DesktopEnums::MOUSEBUTTON_ENUM_MAP[button]
317
356
  list = Java::JavaUtil::ArrayList.new
318
357
  opts.each { |mod| list << DesktopEnums::KEYMODIFIER_ENUM_MAP[mod] }
@@ -321,12 +360,12 @@ private
321
360
  raise(DesktopExceptions::WidgetNotVisibleException, "Widget #{name.length > 0 ? name : text} not visible")
322
361
  end
323
362
  end
324
-
363
+
325
364
  # Right click a widget
326
365
  def right_click
327
366
  click(:right, 1)
328
367
  end
329
-
368
+
330
369
  # double click widget
331
370
  def double_click
332
371
  click(:left, 2)
@@ -361,31 +400,31 @@ private
361
400
  if @selector == nil && @elm != nil
362
401
  set_selector
363
402
  end
364
- #puts "<find> Find Widget by " + @method.to_s + " " + @window_id.to_s + ", " + @selector.to_s + ", " + @location.to_s
403
+ #puts "\n<find> Find Widget by " + @method.to_s + " " + @window_id.to_s + ", " + @selector.to_s + ", " + @location.to_s + ", " + @type.to_s
365
404
  case @method
366
405
  when :name
367
406
  if @location != nil
368
- @element = driver.findWidgetByName(@window_id, @selector, @location)
407
+ @element = driver.findWidgetByName(WIDGET_ENUM_MAP[@type], @window_id, @selector, @location)
369
408
  else
370
- @element = driver.findWidgetByName(@window_id, @selector)
409
+ @element = driver.findWidgetByName(WIDGET_ENUM_MAP[@type], @window_id, @selector)
371
410
  end
372
411
  when :string_id
373
412
  if @location != nil
374
- @element = driver.findWidgetByStringId(@window_id, @selector, @location)
413
+ @element = driver.findWidgetByStringId(WIDGET_ENUM_MAP[@type], @window_id, @selector, @location)
375
414
  else
376
- @element = driver.findWidgetByStringId(@window_id, @selector)
415
+ @element = driver.findWidgetByStringId(WIDGET_ENUM_MAP[@type], @window_id, @selector)
377
416
  end
378
417
  when :text
379
418
  if @location != nil
380
- @element = driver.findWidgetByText(@window_id, @selector, @location)
419
+ @element = driver.findWidgetByText(WIDGET_ENUM_MAP[@type], @window_id, @selector, @location)
381
420
  else
382
- @element = driver.findWidgetByText(@window_id, @selector)
421
+ @element = driver.findWidgetByText(WIDGET_ENUM_MAP[@type], @window_id, @selector)
383
422
  end
384
423
  when :pos
385
424
  if @location != nil
386
- @element = driver.findWidgetByPosition(@window_id, @selector[0], @selector[1], @location)
425
+ @element = driver.findWidgetByPosition(WIDGET_ENUM_MAP[@type], @window_id, @selector[0], @selector[1], @location)
387
426
  else
388
- @element = driver.findWidgetByPosition(@window_id, @selector[0], @selector[1])
427
+ @element = driver.findWidgetByPosition(WIDGET_ENUM_MAP[@type], @window_id, @selector[0], @selector[1])
389
428
  end
390
429
  end
391
430
  if @window_id < 0 && @element != nil
@@ -106,7 +106,33 @@ module OperaWatir
106
106
  def print_window_info
107
107
  puts window_info_string
108
108
  end
109
+
110
+ ########################################################################
111
+ #
112
+ # @return width of widget
113
+ #
114
+ def width
115
+ element.getRect().width
116
+ end
109
117
 
118
+ ########################################################################
119
+ #
120
+ # @return height of widget
121
+ #
122
+ def height
123
+ element.getRect().height
124
+ end
125
+
126
+ #@private
127
+ def x
128
+ element.getRect().x
129
+ end
130
+
131
+ #@private
132
+ def y
133
+ element.getRect().y
134
+ end
135
+
110
136
  ######################################################################
111
137
  # Returns a string of the internal information about the window. Used
112
138
  # to discover the names of widgets and windows to use in the tests.
@@ -1,3 +1,4 @@
1
1
  %w(quick_widget quick_button quick_checkbox quick_editfield
2
2
  quick_dropdown quick_dialogtab quick_label quick_radiobutton quick_treeview quick_addressfield
3
- quick_searchfield quick_toolbar quick_window quick_tab quick_treeitem quick_thumbnail).each {|widget| require "operawatir/quickwidgets/#{widget}"}
3
+ quick_searchfield quick_toolbar quick_window quick_tab quick_treeitem quick_thumbnail
4
+ quick_find quick_griditem quick_gridlayout).each {|widget| require "operawatir/quickwidgets/#{widget}"}
@@ -52,27 +52,40 @@ class OperaWatir::Window
52
52
  driver.getTitle
53
53
  end
54
54
 
55
+ #
55
56
  # Gets the URL of the document.
56
57
  #
57
58
  # @return [String] The URL of the current document.
59
+ #
60
+
58
61
  def url
59
62
  driver.getCurrentUrl
60
63
  end
61
64
 
65
+ #
62
66
  # Navigates to a new URL.
63
67
  #
64
- # @param [String] url The new URL to navigate to.
68
+
65
69
  def url=(url)
66
- driver.get(url)
70
+ driver.navigate.to(url)
67
71
  end
72
+
68
73
  alias_method :goto, :url= # deprecate?
69
74
 
75
+ #
76
+ # Refreshes the page.
77
+ #
78
+
79
+ def refresh
80
+ driver.navigate.refresh
81
+ end
82
+
70
83
  # Retrieves the text without the DOM or source code from the
71
84
  # currently loaded document.
72
85
  #
73
86
  # @return [String] The text of the document.
74
87
  def text
75
- driver.getText
88
+ document.text
76
89
  end
77
90
 
78
91
  # Retrieves the HTML/source code of the currently loaded document.
@@ -105,6 +118,7 @@ class OperaWatir::Window
105
118
 
106
119
  # Opera-specific
107
120
 
121
+ #
108
122
  # Creates a Screenshot interface or saves screenshot to specified
109
123
  # location if a file path is given.
110
124
  #
@@ -113,12 +127,21 @@ class OperaWatir::Window
113
127
  #
114
128
  # @return [Object] A Screenshot object.
115
129
  # @return [String] Filename to the saved file.
130
+ #
131
+
116
132
  def screenshot(filename=nil)
117
133
  # TODO: This should call document.screenshot instead, but that
118
134
  # requires a generic ScreenShotReply interface in OperaDriver.
119
135
  filename.nil? ? OperaWatir::Screenshot.new(self) : OperaWatir::Screenshot.new(self).save(filename)
120
136
  end
121
137
 
138
+ #
139
+ # Returns a visual hash sum of the document. It takes a screenshot of
140
+ # the page and generates an MD5 hash sum of it.
141
+ #
142
+ # @return [String] A hash sum.
143
+ #
144
+
122
145
  def visual_hash
123
146
  document.visual_hash
124
147
  end
@@ -136,16 +159,23 @@ class OperaWatir::Window
136
159
  alias_method :find_by_class, :find_by_class_name
137
160
  alias_method :find_by_tag, :find_by_tag_name
138
161
 
139
- # Finds the document of a page.
140
162
  #
141
- # @return [Element] The body/document of a page.
163
+ # Finds the root element of the document. For HTML document, this is
164
+ # the element with the tagName “HTML”.
165
+ #
166
+ # @return [Element] The root element of the document.
167
+ #
168
+
142
169
  def document
143
- find_by_tag('body')
170
+ find_by_css(':root')
144
171
  end
145
172
 
173
+ #
146
174
  # Finds all elements in document.
147
175
  #
148
176
  # @return [Collection] A collection of elements.
177
+ #
178
+
149
179
  def elements
150
180
  find_by_tag('*')
151
181
  end
@@ -160,61 +190,42 @@ class OperaWatir::Window
160
190
 
161
191
  private
162
192
 
163
- # Locate elements by id.
164
- #
165
- # @return [Array] An array of found elements.
166
193
  def find_elements_by_id(value)
167
194
  driver.findElementsById(value).to_a.map do |node|
168
195
  OperaWatir::Element.new(node)
169
196
  end
170
197
  end
171
198
 
172
- # Locate elements by class.
173
- #
174
- # @return [Array] An array of found elements.
175
199
  def find_elements_by_class_name(value)
176
200
  driver.findElementsByClassName(value).to_a.map do |node|
177
201
  OperaWatir::Element.new(node)
178
202
  end
179
203
  end
180
204
 
181
- # Locate elements by tag name.
182
- #
183
- # @return [Array] An array of found elements.
184
205
  def find_elements_by_tag_name(value)
185
206
  driver.findElementsByTagName(value).to_a.map do |node|
186
207
  OperaWatir::Element.new(node)
187
208
  end
188
209
  end
189
210
 
190
- # Locate elements by CSS selector.
191
- #
192
- # @return [Array] An array of found elements.
193
211
  def find_elements_by_css(value)
194
212
  driver.findElementsByCssSelector(value).to_a.map do |node|
195
213
  OperaWatir::Element.new(node)
196
214
  end
197
215
  end
198
216
 
199
- # Locate elements by XPath expression.
200
- #
201
- # @return [Array] An array of found elements.
202
217
  def find_elements_by_xpath(value)
203
218
  driver.findElementsByXPath(value).to_a.map do |node|
204
219
  OperaWatir::Element.new(node)
205
220
  end
206
221
  end
207
222
 
208
- # Locate elements by attribute @name.
209
- #
210
- # @return [Array] An array of found elements.
211
223
  def find_elements_by_name(value)
212
224
  driver.findElementsByName(value).to_a.map do |node|
213
225
  OperaWatir::Element.new(node)
214
226
  end
215
227
  end
216
228
 
217
- # @private
218
229
  def driver
219
230
  browser.driver
220
231
  end