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
@@ -8,9 +8,12 @@ module OperaWatir
8
8
  end
9
9
 
10
10
  ######################################################################
11
- # Enters the search text into the search field, and waits for page
11
+ # Enters the search text into the search field, and waits for page
12
12
  # loading to finish
13
13
  #
14
+ # @example (RSpec)
15
+ # browser.quick_searchfield(:name, "tbs_MainSearch").search_with_text("old cars").should include "http://www.google"
16
+ #
14
17
  # @param [String] url text to search with
15
18
  #
16
19
  # @return [String] text in the address field after the page is loaded
@@ -19,13 +22,13 @@ module OperaWatir
19
22
  def search_with_text(search_text)
20
23
  # Must focus field before calling enter_text...
21
24
  focus_with_click
22
-
25
+
23
26
  # Enters text in a field and then hits enter
24
27
  t = enter_text_and_hit_enter(search_text)
25
28
 
26
- # return text in addressfield (in same window as search field)
29
+ # return text in addressfield (in same window as search field)
27
30
  driver.findWidgetByName(WIDGET_ENUM_MAP[:addressfield], @window_id, "tba_address_field", "Document Toolbar").getText
28
31
  end
29
-
32
+
30
33
  end
31
34
  end
@@ -1,12 +1,12 @@
1
1
  module OperaWatir
2
2
  class QuickTab < QuickButton
3
-
3
+
4
4
  # @private
5
5
  # Checks the type of the widget is correct
6
6
  def correct_type?
7
7
  @element.getType == WIDGET_ENUM_MAP[:tabbutton]
8
8
  end
9
-
9
+
10
10
  ######################################################################
11
11
  # Drag and drop this tab on tab tab_target
12
12
  #
@@ -17,10 +17,10 @@ module OperaWatir
17
17
  def move_with_drag(tab_target)
18
18
  raise(Exceptions::UnknownObjectException) unless tab_target.type == :tabbutton
19
19
  drag_and_drop_on(tab_target, :center)
20
-
20
+
21
21
  sleep(0.1)
22
22
  end
23
-
23
+
24
24
  ######################################################################
25
25
  # Drag and drop this tab on another tab to add it to its tab group
26
26
  #
@@ -32,34 +32,45 @@ module OperaWatir
32
32
  # in which case it represents only 1 tab, itself
33
33
  def group_with_drag(tab_target)
34
34
  raise(Exceptions::UnknownObjectException) unless tab_target.type == :tabbutton
35
-
35
+
36
36
  # Drop on the edge of a tab to make the grouping work
37
37
  drag_and_drop_on(tab_target, :edge)
38
-
38
+
39
39
  sleep(0.1)
40
-
40
+
41
41
  #Get the number of tabs in the group
42
42
  element(true).value
43
43
  end
44
-
45
-
44
+
45
+
46
46
  ######################################################################
47
47
  # Clicks the tab button, and waits for the tab to be shown / switches to the page
48
48
  #
49
49
  # @param [String] win_name name of the window that will be opened (Pass a blank string for any window)
50
50
  #
51
- # @return [int] Window ID of the window activated,
51
+ # @return [int] Window ID of the window activated,
52
52
  # 0 if the window is already the active one,
53
- # or if no window is active
53
+ # or if no window is active
54
54
  #
55
55
  # @raise [DesktopExceptions::WidgetNotVisibleException] if the tab button
56
56
  # is not visible
57
57
  #
58
58
  def activate_tab_with_click
59
59
  wait_start
60
- click
60
+ click
61
61
  wait_for_window_activated("Document Window")
62
62
  end
63
63
 
64
+ ###########################################################################
65
+ # Double clicks the tab and waits for it to be closed
66
+ #
67
+ # @return [int] Window ID of the window that was closed
68
+ #
69
+ def close_window_with_doubleclick
70
+ wait_start
71
+ click(:left, 2)
72
+ wait_for_window_close("Document Window")
73
+ end
74
+
64
75
  end
65
76
  end
@@ -1,12 +1,12 @@
1
1
  module OperaWatir
2
2
  class QuickThumbnail < QuickButton
3
-
3
+
4
4
  # @private
5
5
  # Checks the type of the widget is correct
6
6
  def correct_type?
7
7
  @element.getType == WIDGET_ENUM_MAP[:thumbnail]
8
8
  end
9
-
9
+
10
10
  ######################################################################
11
11
  # Drag and drop this speeddial onto the speed dial tab_target
12
12
  #
@@ -18,9 +18,9 @@ module OperaWatir
18
18
  def move_with_drag(tab_target)
19
19
  raise(Exceptions::UnknownObjectException) unless tab_target.type == :thumbnail
20
20
  drag_and_drop_on(tab_target, :center)
21
-
21
+
22
22
  sleep(0.1)
23
23
  end
24
-
24
+
25
25
  end
26
26
  end
@@ -6,6 +6,6 @@ module OperaWatir
6
6
  def correct_type?
7
7
  @element.getType == WIDGET_ENUM_MAP[:toolbar]
8
8
  end
9
-
9
+
10
10
  end
11
11
  end
@@ -10,7 +10,7 @@ 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
15
  # @raise [DesktopExceptions::WidgetDisabledException] if the treeitem
16
16
  # is disabled
@@ -20,24 +20,24 @@ module OperaWatir
20
20
  scroll_item_into_view unless visible?
21
21
  super
22
22
  end
23
-
23
+
24
24
  ######################################################################
25
25
  # Expands a tree item when it is clicked
26
26
  #
27
- # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
27
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
28
28
  # is not visible
29
29
  #
30
30
  def expand_with_click
31
31
  # For now there is no difference to focusing
32
32
  focus_with_click
33
33
  end
34
-
34
+
35
35
  alias_method :collapse_with_click, :expand_with_click
36
36
 
37
37
  ######################################################################
38
38
  # Expands a tree item when it is double clicked
39
39
  #
40
- # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
40
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
41
41
  # is not visible
42
42
  #
43
43
  def expand_with_double_click
@@ -46,9 +46,9 @@ module OperaWatir
46
46
  # No event yet so just cheat and sleep
47
47
  sleep(0.1);
48
48
  end
49
-
49
+
50
50
  alias_method :collapse_with_double_click, :expand_with_double_click
51
-
51
+
52
52
  ######################################################################
53
53
  # Presses a key including modifiers
54
54
  #
@@ -70,7 +70,7 @@ module OperaWatir
70
70
  key_press_direct(key, *opts)
71
71
  sleep(0.1)
72
72
  end
73
-
73
+
74
74
  ######################################################################
75
75
  # Checks if the treeitem is selected
76
76
  #
@@ -81,24 +81,24 @@ module OperaWatir
81
81
  def selected?
82
82
  element.isSelected
83
83
  end
84
-
85
-
84
+
85
+
86
86
  ######################################################################
87
- # Switches to the tree view tab by clicking on it (e.g. on the
88
- # Advanced page of the preferences dialog)
87
+ # Switches to the tree view tab by clicking on it (e.g. on the
88
+ # Advanced page of the preferences dialog)
89
89
  #
90
90
  # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
91
91
  # is not visible
92
92
  #
93
93
  def activate_tab_with_click
94
94
  click
95
-
95
+
96
96
  # No event yet so just cheat and sleep
97
97
  sleep(0.1);
98
98
  end
99
-
99
+
100
100
  ######################################################################
101
- # Double clicks the tree item, and waits for the window with
101
+ # Double clicks the tree item, and waits for the window with
102
102
  # window name win_name to be shown
103
103
  #
104
104
  # @param [String] win_name name of the window that will be opened (Pass a blank string for any window)
@@ -109,15 +109,31 @@ module OperaWatir
109
109
  # is not visible
110
110
  #
111
111
  def open_window_with_double_click(win_name)
112
- wait_start
113
- click(:left, 2)
114
- wait_for_window_shown(win_name)
112
+ open_window_with_click_internal(win_name, 2)
115
113
  end
116
-
114
+
117
115
  alias_method :open_dialog_with_double_click, :open_window_with_double_click
118
116
 
117
+
118
+ ######################################################################
119
+ # Clicks the tree item, and waits for the window with
120
+ # window name win_name to be shown
121
+ #
122
+ # @param [String] win_name name of the window that will be opened (Pass a blank string for any window)
123
+ #
124
+ # @return [int] Window ID of the window shown or 0 if no window is shown
125
+ #
126
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
127
+ # is not visible
128
+ #
129
+ def open_window_with_click(win_name)
130
+ open_window_with_click_internal(win_name, 1)
131
+ end
132
+
133
+ alias_method :open_dialog_with_click, :open_window_with_click
134
+
119
135
  ######################################################################
120
- # Double clicks the tree item, and waits for the window with
136
+ # Double clicks the tree item, and waits for the window with
121
137
  # window name win_name to be loaded with the url of the treeitem
122
138
  #
123
139
  # @param [String] win_name name of the window that will be loaded (Pass a blank string for any window)
@@ -132,21 +148,21 @@ module OperaWatir
132
148
  click(:left, 2)
133
149
  wait_for_window_loaded(win_name)
134
150
  end
135
-
151
+
136
152
 
137
153
  private
138
154
  # @private
139
155
  # Scrolls the item into view if required
140
156
  def scroll_item_into_view
141
-
157
+
142
158
  # Make sure we have a window id
143
159
  win_id = window_id >= 0 ? window_id : driver.getActiveQuickWindowID()
144
-
160
+
145
161
  # Filter only treeitems in parent_treeview
146
162
  treeitems = driver.getQuickWidgetList(win_id).select do |wdg|
147
163
  wdg.getType == QuickWidget::WIDGET_ENUM_MAP[:treeitem] && wdg.getParentName == parent_name
148
164
  end
149
-
165
+
150
166
  # Get the first visible item
151
167
  lowest = treeitems.find { | item| item.visible? } #This will always be a parent item, not a child
152
168
  # Assume list is ordered? => lower row means scroll up, higher row means scroll down
@@ -156,10 +172,10 @@ private
156
172
  qw = QuickTreeItem.new(self,lowest)
157
173
  qw.focus_with_click
158
174
  key_press_direct(key)
159
-
175
+
160
176
  #First scroll
161
177
  key_press_direct(key)
162
-
178
+
163
179
  visible_treeitems = driver.getQuickWidgetList(win_id).select do |wdg|
164
180
  wdg.getType == QuickWidget::WIDGET_ENUM_MAP[:treeitem] && wdg.getParentName == parent_name && wdg.visible?
165
181
  end
@@ -167,12 +183,12 @@ private
167
183
  # Stop scrolling if we have run through the whole list, the item is then a child and won't get visible
168
184
  max_times = treeitems.length / visible_treeitems.length + 1
169
185
  until element(true).visible? || max_times < 0
170
- key_press_direct(key)
186
+ key_press_direct(key)
171
187
  max_times-=1
172
188
  end
173
-
189
+
174
190
  end
175
191
  end
176
-
192
+
177
193
  end
178
194
 
@@ -18,11 +18,11 @@ module OperaWatir
18
18
  end.select { |item| item != nil }
19
19
  treeitems.select {|item| item.parent_name == name }
20
20
  end
21
-
21
+
22
22
  def num_treeitems
23
23
  treeitems.select { |item| item.position[1] == 0 }.length
24
24
  end
25
-
25
+
26
26
  end
27
27
  end
28
28
 
@@ -3,13 +3,16 @@ module OperaWatir
3
3
  include DesktopCommon
4
4
  include DesktopContainer
5
5
  include Deprecated
6
-
6
+
7
+ ConditionTimeout = 10.0
8
+
7
9
  # @private
8
10
  # window_id is set if constructor is called on a (parent) window
9
11
  # location is set is this is called on a (parent) widget
10
12
  def initialize(container, method, selector=nil, location=nil, window_id=-1, type=nil)
13
+
11
14
  @container = container
12
-
15
+
13
16
  if method.is_a? Java::ComOperaCoreSystems::QuickWidget
14
17
  @elm = method
15
18
  @type = WIDGET_ENUM_MAP.invert[method.getType]
@@ -21,9 +24,9 @@ module OperaWatir
21
24
  @window_id = window_id
22
25
  end
23
26
  end
24
-
27
+
25
28
  #######################################################################
26
- #
29
+ #
27
30
  # Hovers widget and waits for window to be shown
28
31
  #
29
32
  #
@@ -32,7 +35,25 @@ module OperaWatir
32
35
  element.hover
33
36
  wait_for_window_shown(win_name)
34
37
  end
35
-
38
+
39
+ ######################################################################
40
+ # Rightclicks the widget, and waits for the menu with name
41
+ # menu_name to be shown
42
+ #
43
+ # @param [String] menu name (from standard_menu.ini)
44
+ #
45
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the button
46
+ # is not visible
47
+ #
48
+ # @return [String] name of menu opened if it matches parameter menu_name
49
+ # otherwise empty string
50
+ #
51
+ def open_menu_with_rightclick(menu_name)
52
+ wait_start
53
+ click(:right)
54
+ wait_for_menu_shown(menu_name)
55
+ end
56
+
36
57
  ######################################################################
37
58
  # Checks whether a widget exists or not
38
59
  #
@@ -44,26 +65,26 @@ module OperaWatir
44
65
  false
45
66
  end
46
67
  alias_method :exists?, :exist?
47
-
68
+
48
69
  ######################################################################
49
70
  # Checks if a widget is enabled or not
50
71
  #
51
72
  # @return [Boolean] true if enabled otherwise false
52
73
  #
53
74
  # @raise [Exceptions::UnknownObjectException] if the widget could not be found
54
- # using the specified method
75
+ # using the specified method
55
76
  #
56
77
  def enabled?
57
78
  element.isEnabled
58
79
  end
59
-
80
+
60
81
  ######################################################################
61
82
  # Checks if a widget is visible or not
62
83
  #
63
84
  # @return [Boolean] true if visible otherwise false
64
85
  #
65
86
  # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
66
- # using the specified method
87
+ # using the specified method
67
88
  #
68
89
  def visible?
69
90
  element.isVisible
@@ -78,24 +99,24 @@ module OperaWatir
78
99
  # @return [String] text of the widget
79
100
  #
80
101
  # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
81
- # using the specified method
102
+ # using the specified method
82
103
  #
83
104
  def text
84
105
  element.getText
85
106
  end
86
-
107
+
87
108
  ######################################################################
88
109
  # Gets the type of a widget
89
110
  #
90
111
  # @return [Symbol] type of the widget (e.g. :dropdown, :button)
91
112
  #
92
- # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
113
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
93
114
  # using the specified method
94
- #
115
+ #
95
116
  def type
96
117
  WIDGET_ENUM_MAP.invert[element.getType]
97
118
  end
98
-
119
+
99
120
  ######################################################################
100
121
  # Gets the name of the widget (as it appears in dialog.ini or code)
101
122
  #
@@ -107,7 +128,7 @@ module OperaWatir
107
128
  def name
108
129
  element.getName
109
130
  end
110
-
131
+
111
132
  ######################################################################
112
133
  # Gets a string representation of the widget
113
134
  #
@@ -127,7 +148,7 @@ module OperaWatir
127
148
  #
128
149
  # @param [String] string_id String ID to use to load the string from the current
129
150
  # language file (e.g. "D_NEW_PREFERENCES_GENERAL")
130
- #
151
+ #
131
152
  # @return [Boolean] true if the text matches, otherwise false
132
153
  #
133
154
  # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
@@ -140,19 +161,38 @@ module OperaWatir
140
161
  res = /#{text}/ =~ element.getText()
141
162
  res == nil ? false: true
142
163
  else
143
- element.verifyText(string_id)
164
+ element.verifyText(string_id)
144
165
  end
145
166
  end
146
-
167
+
147
168
  alias_method :has_ui_string?, :verify_text
148
-
169
+
170
+ ######################################################################
171
+ # Checks that the text in the widget matches the text as loaded
172
+ # from the current language file in Opera using the string_id
173
+ # (Strips &'s from the string before comparing)
174
+ #
175
+ # @param [String] string_id String ID to use to load the string from the current
176
+ # language file (e.g. "D_NEW_PREFERENCES_GENERAL")
177
+ #
178
+ # @return [Boolean] true if the text matches, otherwise false
179
+ #
180
+ # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
181
+ # using the specified method
182
+ #
183
+ def verify_text(string_id, *params)
184
+ text = driver.getString(string_id, true)
185
+ verify_realtext(text, *params)
186
+ end
187
+
188
+
149
189
  ######################################################################
150
190
  # Checks that the text in the widget includes the text as loaded
151
191
  # from the current language file in Opera using the string_id
152
192
  #
153
193
  # @param [String] string_id String ID to use to load the string from the current
154
194
  # language file (e.g. "D_NEW_PREFERENCES_GENERAL")
155
- #
195
+ #
156
196
  # @return [Boolean] true if the text is included, otherwise false
157
197
  #
158
198
  # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
@@ -161,7 +201,7 @@ module OperaWatir
161
201
  def verify_includes_text(string_id)
162
202
  element.verifyContainsText(string_id)
163
203
  end
164
-
204
+
165
205
  alias_method :includes_text?, :verify_includes_text
166
206
  deprecated :verify_includes_text
167
207
  deprecated :includes_text?
@@ -197,10 +237,15 @@ module OperaWatir
197
237
  # @return position for elements that have a position, else false
198
238
  #
199
239
  def position
200
- return [row, col] if type == :treeitem
201
- return col if type == :tabbutton
202
- return col if type == :button
203
- false
240
+ case type
241
+ when :treeitem then [row, col]
242
+ when :tabbutton, :button then col
243
+ else false
244
+ end
245
+ #return [row, col] if type == :treeitem
246
+ #return col if type == :tabbutton
247
+ #return col if type == :button
248
+ #false
204
249
  end
205
250
 
206
251
  ########################################################################
@@ -228,13 +273,13 @@ module OperaWatir
228
273
  def y
229
274
  element.getRect().y
230
275
  end
231
-
276
+
232
277
  ######################################################################
233
278
  # Prints out all of the internal information about the widget. Used
234
279
  # to discover the names of widgets and windows to use in the tests
235
280
  #
236
281
  # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
237
- # using the specified method
282
+ # using the specified method
238
283
  #@private
239
284
  def print_widget_info
240
285
  puts widget_info_string
@@ -245,10 +290,10 @@ module OperaWatir
245
290
  # to discover the names of widgets and windows to use in the tests
246
291
  #
247
292
  # @raise [Exceptions::UnknownObjectException] if the widget cannot be found
248
- # using the specified method
293
+ # using the specified method
249
294
  #
250
295
  def widget_info_string
251
- " Name: " + name +
296
+ " Name: " + name +
252
297
  "\n Text: " + text +
253
298
  "\n Type: " + type.to_s +
254
299
  "\n Parent: " + element.getParentName() +
@@ -259,31 +304,132 @@ module OperaWatir
259
304
  "\n Ref: row=" + element.getRow().to_s + ", col=" + element.getColumn().to_s +
260
305
  "\nselected: " + element.isSelected().to_s + "\n"
261
306
  end
262
-
307
+
263
308
  # @private
264
309
  def driver
265
310
  @container.driver
266
311
  end
267
-
312
+
268
313
  # Gets parent widget name
269
314
  def parent_name
270
315
  element.getParentName()
271
316
  end
272
-
317
+
273
318
  #################################################################
274
319
  # Focus a widget with a click
275
320
  #
276
321
  def focus_with_click
277
322
  click
278
323
  # No event yet so just cheat and sleep
279
- sleep(0.1);
324
+ sleep(0.1)
280
325
  end
281
-
282
- #@private
326
+
327
+ #################################################################
328
+ # Focus a widget by moving the mouse over it
329
+ #
330
+ def focus_with_hover
331
+ element.hover
332
+ #No event yet so just cheat and sleep
333
+ sleep(0.1)
334
+ end
335
+
336
+ ###############################################################
337
+ #
338
+ # double_click_with_condition { block } → res
339
+ #
340
+ # Doubleclicks widget and waits until block evaluates to true or timeout is hit
341
+ #
342
+ # @return value of block, or false if no block provided
343
+ #
344
+ def double_click_with_condition(&condition)
345
+ click_with_condition_internal(:left, 2, &condition)
346
+ end
347
+
348
+ ###############################################################
349
+ #
350
+ # right_click_with_condition { block } → res
351
+ #
352
+ # Rightclicks widget and waits until block evaluates to true or timeout is hit
353
+ #
354
+ # @return value of block, or false if no block provided
355
+ #
356
+ def right_click_with_condition(&condition)
357
+ click_with_condition_internal(:right, 1, &condition)
358
+ end
359
+
360
+ ##############################################################
361
+ #
362
+ # middle_click_with_condition { block } → res
363
+ #
364
+ # Middleclicks widget and waits until block evaluates to true or timeout is hit
365
+ #
366
+ # @return value of block, or false if no block provided
367
+ #
368
+ def middle_click_with_condition(&condition)
369
+ click_with_condition_internal(:middle, 1, &condition)
370
+ end
371
+
372
+ ###############################################################
373
+ #
374
+ # click_with_condition { block } → res
375
+ #
376
+ # @example
377
+ # browser.quick_button(:name, "[buttonname]").click_with_condition {
378
+ # browser.quick_treeview(:name, "[name]").quick_treeitems.length == 4 }.should be_true
379
+ #
380
+ # Clicks widget and waits until block evaluates to true or timeout is hit
381
+ #
382
+ # @return value of block, or false if no block provided
383
+ #
384
+ def click_with_condition(&condition)
385
+ click_with_condition_internal(:left, 1, &condition)
386
+ end
387
+
388
+
389
+ #######################################################
390
+ #
391
+ #
392
+ #
283
393
  def value
284
394
  return element.getValue
285
395
  end
286
-
396
+
397
+ #########################################################
398
+ #
399
+ # @return all widgets inside this widget
400
+ #
401
+ # @example
402
+ # browser.quick_treeview(:name, "Mail View").quick_widgets
403
+ #
404
+ # @note
405
+ # you can also specify the widgets by type to retrieve only
406
+ # a specific type of widgets
407
+ #
408
+ # @example
409
+ # browser.quick_treeview(:name, "Mail View").quick_treeitems
410
+ #
411
+ #
412
+ def quick_widgets
413
+ widgets(window_id).select { | w | w.parent_name == name }
414
+ end
415
+
416
+ def quick_tabs
417
+ quick_tabbuttons
418
+ end
419
+
420
+ WIDGET_ENUM_MAP.keys.each do |widget_type|
421
+ my_type = "quick_" << widget_type.to_s
422
+ type = my_type
423
+ if my_type == "quick_search" || my_type == "quick_checkbox"
424
+ my_type << "es"
425
+ else
426
+ my_type << "s"
427
+ end
428
+ define_method(my_type.to_sym) do #|win|
429
+ quick_widgets.select { |w| w.type == widget_type and w.parent_name == name }
430
+ end
431
+ end
432
+
287
433
  protected
288
434
  #@private
289
435
  # Return the element
@@ -291,14 +437,83 @@ protected
291
437
  if (@elm == nil || refresh == true)
292
438
  @elm = find
293
439
  end
294
-
295
- raise(Exceptions::UnknownObjectException, "Element #{@selector} not found using #{@method}") unless @elm
440
+
441
+ raise(Exceptions::UnknownObjectException, "Element #{@selector} not found using #{@method}") unless @elm
296
442
  @elm
297
443
  end
298
444
 
299
-
445
+
300
446
  private
301
-
447
+
448
+ def open_window_with_click_internal(win_name, num_clicks)
449
+ wait_start
450
+ click(:left, num_clicks)
451
+ wait_for_window_shown(win_name)
452
+ end
453
+
454
+ def click_with_condition_internal(button = :left, times = 1, &blk)
455
+ return false unless block_given?
456
+
457
+ click(button, times)
458
+
459
+ start = Time.now
460
+ until res = yield rescue false do
461
+ if Time.now - start > ConditionTimeout
462
+ return false
463
+ end
464
+ sleep 0.1
465
+
466
+ end
467
+ res
468
+ end
469
+
470
+ # Right click a widget
471
+ def right_click
472
+ click(:right, 1)
473
+ end
474
+
475
+ # Click widget
476
+ def click(button = :left, times = 1, *opts)
477
+
478
+ #raise DesktopExceptions::WidgetDisabledException, "Element #{@selector} is disabled" unless enabled?
479
+
480
+ #Some buttons etc. aren't visible until hovering them
481
+ if (visible? == false and type != :dialogtab)
482
+ element.hover
483
+ element(true)
484
+ end
485
+
486
+ # Dialog tabs are always visible even if the page they are connected to isn't
487
+ if visible? == true or type == :dialogtab
488
+ button = DesktopEnums::MOUSEBUTTON_ENUM_MAP[button]
489
+ list = Java::JavaUtil::ArrayList.new
490
+ opts.each { |mod| list << DesktopEnums::KEYMODIFIER_ENUM_MAP[mod] }
491
+ element.click(button, times, list)
492
+ else
493
+ raise(DesktopExceptions::WidgetNotVisibleException, "Widget #{name.length > 0 ? name : text} not visible")
494
+ end
495
+ end
496
+
497
+ def verify_realtext(text, *params)
498
+ if text.include? "%1"
499
+ result = text.scan(/%\d/)
500
+ if (params.length == result.length)
501
+ result.length.times do |time|
502
+ number = time+1
503
+ p = params[time]
504
+ text.gsub!("%#{number}", params[time])
505
+ end
506
+ end
507
+ text == element.getText()
508
+ else
509
+ params.each do |param|
510
+ text.gsub!(/%[csduoxefg0-9]/, param)
511
+ end
512
+ text == element.getText()
513
+ end
514
+ end
515
+
516
+
302
517
  def drag_and_drop_on(other, drop_pos)
303
518
  element.dragAndDropOn(other.element, DROPPOSITION_ENUM_MAP[drop_pos])
304
519
  end
@@ -308,7 +523,7 @@ private
308
523
  if @selector == nil && @elm != nil
309
524
  set_selector
310
525
  end
311
-
526
+
312
527
  #FIXME: Shouldn't this always be name if present, then text if present, else pos?
313
528
  case @method
314
529
  when :name
@@ -323,7 +538,7 @@ private
323
538
  end
324
539
  end
325
540
 
326
- # Get row
541
+ # Get row
327
542
  def row
328
543
  element.getRow()
329
544
  end
@@ -332,46 +547,21 @@ private
332
547
  def col
333
548
  element.getColumn()
334
549
  end
335
-
550
+
336
551
  # Gets the window id to use for the search
337
552
  def window_id
338
553
  # Need to pass on the current setting of @window_id to make
339
554
  # nesting of quick widgets work
340
555
  @window_id
341
556
  end
342
-
343
- # Click widget
344
- def click(button = :left, times = 1, *opts)
345
- raise DesktopExceptions::WidgetDisabledException, "Element #{@selector} is disabled" unless enabled?
346
-
347
- #Some buttons etc. aren't visible until hovering them
348
- if (visible? == false and type != :dialogtab)
349
- element.hover
350
- element(true)
351
- end
352
-
353
- # Dialog tabs are always visible even if the page they are connected to isn't
354
- if visible? == true or type == :dialogtab
355
- button = DesktopEnums::MOUSEBUTTON_ENUM_MAP[button]
356
- list = Java::JavaUtil::ArrayList.new
357
- opts.each { |mod| list << DesktopEnums::KEYMODIFIER_ENUM_MAP[mod] }
358
- element.click(button, times, list)
359
- else
360
- raise(DesktopExceptions::WidgetNotVisibleException, "Widget #{name.length > 0 ? name : text} not visible")
361
- end
362
- end
363
557
 
364
- # Right click a widget
365
- def right_click
366
- click(:right, 1)
367
- end
368
-
558
+
369
559
  # double click widget
370
560
  def double_click
371
- click(:left, 2)
561
+ click(:left, 2)
372
562
  end
373
563
 
374
-
564
+
375
565
  def set_selector
376
566
  if @elm.name.length > 0
377
567
  @method = :name
@@ -382,18 +572,18 @@ private
382
572
  elsif @elm.type == :treeitem
383
573
  @method = :pos
384
574
  @selector = [@elm.row, @elm.col]
385
- =begin
575
+ =begin
386
576
  # tabbuttons now specified by generated name
387
577
  elsif @elm.type == :tabbutton
388
578
  @method = :pos
389
579
  @selector = @elm.col
390
- =end
580
+ =end
391
581
  end
392
582
  @location = element.getParentName()
393
583
  @window_id = -1
394
584
  end
395
-
396
- # Finds the element on the page.
585
+
586
+ # Finds the element on the page.
397
587
  def find
398
588
  #If @method set and we do new find because of refresh, we need to get @selector first
399
589
  #Have the java object because the construct was done on it
@@ -426,11 +616,11 @@ private
426
616
  else
427
617
  @element = driver.findWidgetByPosition(WIDGET_ENUM_MAP[@type], @window_id, @selector[0], @selector[1])
428
618
  end
429
- end
619
+ end
430
620
  if @window_id < 0 && @element != nil
431
621
  @window_id = @element.getParentWindowId
432
622
  end
433
- raise(Exceptions::UnknownObjectException, "Element #{@selector} not found using #{@method}") unless @element
623
+ raise(Exceptions::UnknownObjectException, "Element #{@selector} not found using #{@method}") unless @element
434
624
  raise(Exceptions::UnknownObjectException, "Element #{@selector} has wrong type #{@element.getType}") unless correct_type?
435
625
  @element
436
626
  end