operawatir 0.4.3.pre1-jruby → 0.5-jruby

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -2,10 +2,10 @@
2
2
  class OperaWatir::Browser
3
3
  include Deprecated
4
4
 
5
- attr_accessor :driver, :active_window, :preferences, :keys, :spatnav
5
+ attr_accessor :driver, :active_window, :preferences, :keys, :spatnav, :utils
6
6
 
7
7
  def self.settings=(settings={})
8
- @opera_driver_settings = nil # Bust cache
8
+ @desired_capabilities = nil # Bust cache
9
9
  @settings = settings
10
10
  end
11
11
 
@@ -22,11 +22,12 @@ class OperaWatir::Browser
22
22
  def initialize
23
23
  OperaWatir.compatibility! unless OperaWatir.api >= 3
24
24
 
25
- self.driver = OperaDriver.new(self.class.opera_driver_settings)
25
+ self.driver = OperaDriver.new(self.class.desired_capabilities)
26
26
  self.active_window = OperaWatir::Window.new(self)
27
27
  self.preferences = OperaWatir::Preferences.new(self)
28
28
  self.keys = OperaWatir::Keys.new(self)
29
29
  self.spatnav = OperaWatir::Spatnav.new(self)
30
+ self.utils = OperaWatir::Utils.new(self)
30
31
  end
31
32
 
32
33
  alias_method :window, :active_window
@@ -48,14 +49,7 @@ class OperaWatir::Browser
48
49
 
49
50
  # Instruct the browser instance to quit and shut down.
50
51
  def quit
51
- driver.shutdown
52
- end
53
-
54
- # Closes all windows.
55
- #
56
- # TODO This should be on Windows
57
- def close_all
58
- driver.closeAll
52
+ driver.quit
59
53
  end
60
54
 
61
55
  # Get the version number of the driver. This _is not_ the same as
@@ -106,6 +100,7 @@ class OperaWatir::Browser
106
100
  def opera_action(name, *args)
107
101
  driver.operaAction(name, args.to_java(:string))
108
102
  end
103
+
109
104
  deprecated :opera_action
110
105
 
111
106
  # Full list of available Opera actions in the Opera build you're
@@ -116,8 +111,9 @@ class OperaWatir::Browser
116
111
  #
117
112
  # @return [String] List of available Opera actions.
118
113
  def opera_action_list
119
- driver.getOperaActionList.to_s
114
+ driver.getOperaActionList.to_a
120
115
  end
116
+
121
117
  deprecated :opera_action_list
122
118
 
123
119
  # Selects all content in the currently focused element. Equivalent
@@ -195,16 +191,24 @@ class OperaWatir::Browser
195
191
 
196
192
  deprecated :key, 'browser.keys.send'
197
193
 
194
+ # actions
195
+
196
+ def actions
197
+ OperaWatir::Actions.new(browser)
198
+ end
199
+
198
200
  private
199
201
 
200
- def self.opera_driver_settings
201
- @opera_driver_settings ||= OperaDriverSettings.new.tap { |s|
202
- s.setAutostart false if self.settings[:manual]
203
- s.setOperaLauncherBinary self.settings[:launcher] if self.settings[:launcher]
204
- s.setOperaBinaryLocation self.settings[:path] if self.settings[:path]
205
- s.setOperaBinaryArguments self.settings[:args].to_s if self.settings[:args]
206
- s.setNoQuit true if self.settings[:no_quit]
207
- s.setUseOperaIdle true if self.settings[:opera_idle] or ENV['OPERA_IDLE'].truthy?
202
+ def self.desired_capabilities
203
+ @desired_capabilities ||= DesiredCapabilities.new.tap { |s|
204
+ s.setCapability('opera.logging.level', self.settings[:logging_level]) if self.settings[:logging_level]
205
+ s.setCapability('opera.logging.file', self.settings[:logging_file]) if self.settings[:logging_file]
206
+ s.setCapability('opera.autostart', false) if self.settings[:manual]
207
+ s.setCapability('opera.launcher', self.settings[:launcher]) if self.settings[:launcher]
208
+ s.setCapability('opera.binary', self.settings[:path]) if self.settings[:path]
209
+ s.setCapability('opera.arguments', self.settings[:args].to_s) if self.settings[:args]
210
+ s.setCapability('opera.no_quit', true) if self.settings[:no_quit]
211
+ s.setCapability('opera.idle', true) if self.settings[:opera_idle] or ENV['OPERA_IDLE'].truthy?
208
212
  }
209
213
  end
210
214
 
@@ -0,0 +1,68 @@
1
+ module OperaWatir
2
+ module ClickableItem
3
+
4
+ ######################################################################
5
+ # Clicks the button, and waits for loading to finish
6
+ #
7
+ # @return [int] Window ID of the window shown or 0 if no window is shown
8
+ #
9
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the button
10
+ # is not visible
11
+ #
12
+ def load_page_with_click
13
+ wait_start
14
+ click
15
+ # Just wait for the load
16
+ wait_for_window_loaded("")
17
+ end
18
+
19
+ ######################################################################
20
+ # Clicks the button, and waits for the window with window name
21
+ # win_name to be shown
22
+ #
23
+ # @param [String] win_name name of the window that will be opened (Pass a blank string for any window)
24
+ #
25
+ # @return [int] Window ID of the window shown or 0 if no window is shown
26
+ #
27
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the button
28
+ # is not visible
29
+ #
30
+ def open_window_with_click(win_name)
31
+ wait_start
32
+ click
33
+ wait_for_window_shown(win_name)
34
+ end
35
+ alias_method :open_dialog_with_click, :open_window_with_click
36
+
37
+ ######################################################################
38
+ # Clicks item and waits for the menu to close
39
+ #
40
+ # @return name of menu closed
41
+ #
42
+ def close_menu_with_click(menu_name)
43
+ wait_start
44
+ click
45
+ wait_for_menu_closed(menu_name)
46
+ end
47
+
48
+ ######################################################################
49
+ # Clicks the item, and waits for the menu with menu with name
50
+ # menu_name to be shown
51
+ #
52
+ # @param [String] name of menu that should open
53
+ #
54
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the button
55
+ # is not visible
56
+ #
57
+ # @return name of menu opened if it matches the parameter menu_name,
58
+ # otherwise returns empty string
59
+ #
60
+ def open_menu_with_click(menu_name)
61
+ wait_start
62
+ click
63
+ wait_for_menu_shown(menu_name)
64
+ end
65
+
66
+
67
+ end
68
+ end
@@ -1,5 +1,5 @@
1
1
  module OperaWatir
2
-
2
+
3
3
  module Compat; end
4
4
 
5
5
  # Switches on compatibility layer (Watir 2 API).
@@ -7,12 +7,12 @@ module OperaWatir
7
7
  require 'operawatir/compat/browser'
8
8
  require 'operawatir/compat/element_finders'
9
9
  require 'operawatir/compat/window'
10
-
10
+
11
11
  Browser.send :include, Compat::Browser
12
12
  Window.send :include, Compat::ElementFinders
13
13
  Window.send :include, Compat::Window
14
14
  Collection.send :include, Compat::ElementFinders
15
-
15
+
16
16
  # TODO Ruby Modules can't override methods defined in their included klass
17
17
  # Requiring the files is OK, but there needs to be some way of detecting
18
18
  # that we are in compatibility mode.
@@ -21,5 +21,5 @@ module OperaWatir
21
21
  require 'operawatir/compat/collection'
22
22
  require 'operawatir/compat/element'
23
23
  end
24
-
24
+
25
25
  end
@@ -26,7 +26,7 @@ class OperaWatir::Collection
26
26
  elsif args.first == :index
27
27
  type, value = :index, args[1].to_i - 1
28
28
 
29
- # Handle a hash of selectors
29
+ # Handle a hash of selectors
30
30
  elsif args.length == 1 and args.first.is_a? Hash
31
31
  args.first.each_pair do |k, v|
32
32
  s = add_selector_from_arguments([k, v], default_method)
@@ -74,7 +74,7 @@ class OperaWatir::Element
74
74
  # @param [optional, Fixnum] y The offset from the top of the element
75
75
  #
76
76
 
77
- def click(x=0, y=0)
77
+ def click(x=1, y=1)
78
78
  assert_enabled!
79
79
  node.click(x.to_i, y.to_i)
80
80
  end
@@ -64,11 +64,12 @@ module OperaWatir
64
64
  driver.switch_to.default_content
65
65
  end
66
66
 
67
-
67
+
68
68
  def show_frames
69
69
  frames = driver.list_frames
70
- puts "There are #{frames.length.to_s} frames"
71
- frames.each_with_index { |frame, i| puts "frame index: #{(i.to_i + 1).to_s} name: #{frame.to_s}" }
70
+ text = "There are #{frames.length.to_s} frames\n"
71
+ frames.each_with_index { |frame, i| text << "frame index: #{(i.to_i + 1).to_s} name: #{frame.to_s}\n" }
72
+ text
72
73
  end
73
74
 
74
75
  end
@@ -2,11 +2,13 @@ module OperaWatir
2
2
  class DesktopBrowser < Browser
3
3
  include DesktopContainer
4
4
  include DesktopCommon
5
-
5
+
6
+ ConditionTimeout = 10.0
7
+
6
8
  LoadActions = ["Open url in new page", "Open url in current page", "Open url in new background page",
7
- "Open url in new window", "New private page", "Paste and go", "Paste and go background",
8
- "Hotclick search", "Duplicate page", "Reopen page", "Back", "Forward", "Help"]
9
-
9
+ "Open url in new window", "New private page", "Paste and go", "Paste and go background",
10
+ "Hotclick search", "Duplicate page", "Reopen page", "Back", "Forward", "Help", "Autocomplete server name"]
11
+
10
12
  # @private
11
13
  def initialize
12
14
  OperaWatir.compatibility! unless OperaWatir.api >= 3
@@ -18,22 +20,26 @@ module OperaWatir
18
20
  self.spatnav = OperaWatir::Spatnav.new(self)
19
21
  end
20
22
 
23
+ #def running?
24
+ # driver.isOperaRunning()
25
+ #end
26
+
21
27
  # @private
22
- # Hack overload to allow for timing of the OnLoaded event that can cause
23
- # dialogs to autoclose in Dialog.cpp when then OnUrlChanged is fired
28
+ # Hack overload to allow for timing of the OnLoaded event that can cause
29
+ # dialogs to autoclose in Dialog.cpp when then OnUrlChanged is fired
24
30
  # after a dialog is opened
25
31
  def goto(url = "")
26
32
  active_window.url = url
27
33
  sleep(1)
28
34
  end
29
-
35
+
30
36
  ######################################################################
31
37
  # Quits Opera
32
38
  #
33
39
  def quit_opera
34
40
  driver.quitOpera
35
41
  end
36
-
42
+
37
43
  ######################################################################
38
44
  # Restarts Opera
39
45
  #
@@ -41,14 +47,22 @@ module OperaWatir
41
47
  driver.quitOpera
42
48
  driver.startOpera
43
49
  end
44
-
50
+
45
51
  ######################################################################
46
52
  # Quits the driver without exiting Opera
47
53
  #
48
54
  def quit_driver
49
55
  driver.quitDriver
50
56
  end
51
-
57
+
58
+ ######################################################################
59
+ #
60
+ # Get ID of active Desktop UI window
61
+ #
62
+ def active_quick_window_id
63
+ driver.getActiveQuickWindowID()
64
+ end
65
+
52
66
  ######################################################################
53
67
  # Executes the action given by action_name, and waits for
54
68
  # the window with window name win_name to be shown
@@ -67,14 +81,14 @@ module OperaWatir
67
81
  if LoadActions.include?(action_name) then
68
82
  raise(DesktopExceptions::UnsupportedActionException, "Action #{action_name} not supported")
69
83
  end
70
-
84
+
71
85
  wait_start
72
86
  opera_desktop_action(action_name, *params)
73
87
  wait_for_window_shown(win_name)
74
88
  end
75
-
89
+
76
90
  alias_method :open_dialog_with_action, :open_window_with_action
77
-
91
+
78
92
  ######################################################################
79
93
  # Executes the action given by action_name, and waits for
80
94
  # the window with window name win_name to be loaded
@@ -89,7 +103,7 @@ module OperaWatir
89
103
  #
90
104
  # @return [int] Window ID of the window shown or 0 if no window is shown
91
105
  def load_window_with_action(win_name, action_name, *params)
92
- if LoadActions.include?(action_name)
106
+ if LoadActions.include?(action_name)
93
107
  wait_start
94
108
  opera_desktop_action(action_name, *params)
95
109
  wait_for_window_loaded(win_name)
@@ -117,14 +131,17 @@ module OperaWatir
117
131
  key_press_direct(key, *modifiers)
118
132
  wait_for_window_shown(win_name)
119
133
  end
120
-
134
+
121
135
  alias_method :open_dialog_with_key_press, :open_window_with_key_press
122
-
136
+
123
137
  ######################################################################
124
138
  # Clicks the key and modifiers and waits for a new tab to be activated
125
139
  #
140
+ # @example
141
+ # browser.activate_tab_with_key_press("F6", :ctrl)
142
+ #
126
143
  # @param [String] key key to press (e.g. "a" or "backspace")
127
- # @param [Symbol] modifiers optional modifier(s) to hold down while pressing
144
+ # @param [Symbol] modifiers optional modifier(s) to hold down while pressing
128
145
  # the key (e.g. :shift, :ctrl, :alt, :meta)
129
146
  #
130
147
  # @return [int] Window ID of the document window (tab) that is activated, or 0 if no tab
@@ -133,22 +150,26 @@ module OperaWatir
133
150
  def activate_tab_with_key_press(key, *modifiers)
134
151
  wait_start
135
152
  # TODO: FIXME. key_down and up are not yet implemented on mac and windows
136
- if linux?
137
- key_down(key,*modifiers)
138
- key_up(key, *modifiers)
153
+ if linux?
154
+ key_down_direct(key,*modifiers)
155
+ key_up_direct(key, *modifiers)
139
156
  else
140
157
  key_press_direct(key, *modifiers)
141
158
  end
142
159
  wait_for_window_activated("Document Window")
143
160
  end
144
-
161
+
145
162
  ######################################################################
146
163
  # Opens a new tab and loads the url entered, then waits for
147
164
  # a dialog to be shown based on the url entered
148
165
  #
149
- # @param [String] dialog_name name of the dialog that will be opened
166
+ # @example
167
+ # browser.open_dialog_with_url("Setup Apply Dialog Confirm Dialog", \
168
+ # "http://t/platforms/desktop/bts/DSK-316777/001-1.ini")
169
+ #
170
+ # @param [String] dialog_name name of the dialog that will be opened
150
171
  # (Pass a blank string for any window)
151
- # @param [String] url to load
172
+ # @param [String] url to load
152
173
  #
153
174
  # @return [int] Window ID of the dialog opened or 0 if no window is opened
154
175
  #
@@ -158,7 +179,7 @@ module OperaWatir
158
179
  # The loading of the page will happen first then the dialog will be shown
159
180
  wait_for_window_shown(dialog_name)
160
181
  end
161
-
182
+
162
183
  ######################################################################
163
184
  # Executes the action given by action_name, and waits for
164
185
  # the window with window name win_name to close
@@ -175,12 +196,12 @@ module OperaWatir
175
196
  #
176
197
  def close_window_with_action(win_name, action_name, *params)
177
198
  wait_start
178
- opera_desktop_action(action_name, *params)
199
+ opera_desktop_action(action_name, *params)
179
200
  wait_for_window_close(win_name)
180
201
  end
181
-
202
+
182
203
  alias_method :close_dialog_with_action, :close_window_with_action
183
-
204
+
184
205
  ######################################################################
185
206
  # Presses the key, with optional modifiers, and waits for
186
207
  # the window with window name win_name to close
@@ -200,13 +221,16 @@ module OperaWatir
200
221
  key_press_direct(key, *opts)
201
222
  wait_for_window_close(win_name)
202
223
  end
203
-
224
+
204
225
  alias_method :close_dialog_with_key_press, :close_window_with_key_press
205
-
226
+
206
227
  ######################################################################
207
228
  # Close the dialog with name dialog_name, using the "Cancel" action
208
229
  #
209
- # @param [String] dialog_name name of the dialog that will be closed
230
+ # @example
231
+ # browser.close_dialog("New Preferences Dialog")
232
+ #
233
+ # @param [String] dialog_name name of the dialog that will be closed
210
234
  # (Pass a blank string for any window)
211
235
  #
212
236
  # @return [int] Window ID of the dialog closed or 0 if no window is closed
@@ -216,7 +240,7 @@ module OperaWatir
216
240
  opera_desktop_action("Cancel")
217
241
  wait_for_window_close(dialog_name)
218
242
  end
219
-
243
+
220
244
  ######################################################################
221
245
  # Sets the alignment of a toolbar or panel
222
246
  #
@@ -226,11 +250,11 @@ module OperaWatir
226
250
  #
227
251
  def set_alignment_with_action(toolbar_name, alignment)
228
252
  opera_desktop_action("Set alignment", toolbar_name, alignment)
229
- sleep(0.1)
253
+ sleep(0.1)
230
254
  end
231
255
 
232
256
  ######################################################################
233
- # Retrieves an array of all widgets in the window with window
257
+ # Retrieves an array of all widgets in the window with window
234
258
  # name win_name
235
259
  #
236
260
  # @example
@@ -243,15 +267,15 @@ module OperaWatir
243
267
  # @return [Array] Array of widgets retrieved from the window
244
268
  #
245
269
  def widgets(window)
246
-
270
+
247
271
  # If window specifies window name, and the active window has this name
248
272
  # use its id to get the widgets,
249
273
  if window.is_a? String
250
274
  active_win_id = driver.getActiveQuickWindowID()
251
275
  active_win_name = driver.getQuickWindowName(active_win_id)
252
-
276
+
253
277
  #If the active window is of same type, then grab that one, not first
254
- if active_win_name == window #e.g. Both Document Window
278
+ if active_win_name == window #e.g. Both Document Window
255
279
  window = active_win_id
256
280
  end
257
281
  end
@@ -282,11 +306,14 @@ module OperaWatir
282
306
  end
283
307
  end.to_a
284
308
  end
285
-
309
+
286
310
  alias_method :quick_widgets, :widgets
287
-
311
+
288
312
  ####################################################
289
- # Retrieves an array of all windows
313
+ # Retrieves an array of all windows
314
+ #
315
+ # @example
316
+ # browser.quick_windows.each { |win| puts win.to_s }
290
317
  #
291
318
  # @return [Array] Array of windows
292
319
  #
@@ -295,28 +322,31 @@ module OperaWatir
295
322
  QuickWindow.new(self,java_window)
296
323
  end.to_a
297
324
  end
298
-
325
+
299
326
  ####################################################
300
327
  # Retrieves an array of all tabs (Document Windows)
301
328
  #
329
+ # @example
330
+ # browser.open_pages.length.should == 2
331
+ #
302
332
  # @return [Array] Array of windows
303
333
  #
304
334
  def open_pages
305
335
  quick_windows.select { |win| win.name == "Document Window" }
306
336
  end
307
-
337
+
308
338
  #@private
309
339
  # Not needed as quick_tabs is def. below
310
340
  #def tab_buttons
311
341
  # widgets("Browser Window").select { | w | w.type == :tabbutton }
312
342
  #end
313
-
343
+
314
344
  #=begin
315
345
  # Return collection for each widget type
316
346
  # example browser.quick_buttons
317
347
  # browser.quick_treeitems
318
348
  # ....
319
- #
349
+ #
320
350
  WIDGET_ENUM_MAP.keys.each do |widget_type|
321
351
  my_type = "quick_" << widget_type.to_s
322
352
  type = my_type
@@ -330,7 +360,63 @@ module OperaWatir
330
360
  end
331
361
  end
332
362
  #=end
333
-
363
+
364
+ #TODO
365
+ def quick_menus
366
+ driver.getQuickMenuList().map do |java_menu|
367
+ QuickMenu.new(self, java_menu)
368
+ end.to_a
369
+ end
370
+
371
+ #TODO
372
+ def quick_menuitems
373
+ driver.getQuickMenuItemList().map do |java_item|
374
+ QuickMenuItem.new(self, java_item)
375
+ end.to_a
376
+ end
377
+
378
+ #####################################################################
379
+ #
380
+ # Closes the active menu
381
+ #
382
+ def close_active_menu
383
+ wait_start
384
+
385
+ menus = quick_menus
386
+ main = menus.select {|menu| menu.name == "Main Menu"}
387
+ main_open = main.length > 0
388
+ real_submenu = main_open ? (menus.length > 2) : menus.length > 1
389
+
390
+ if real_submenu
391
+ key_press_direct("Left")
392
+ else
393
+ close_menu
394
+ end
395
+
396
+ wait_for_menu_closed("")
397
+ end
398
+
399
+ #####################################################################
400
+ #
401
+ # Closes all open menus
402
+ # (Note: On mac one esc closes all menus)
403
+ def close_all_menus
404
+ i = 6 #Just some number
405
+ while quick_menus.delete_if { |menu| menu.name == "Main Menu" }.length > 0
406
+ close_menu
407
+ i-=1
408
+ break if i == 0
409
+ end
410
+ end
411
+
412
+ ######################################################################
413
+ #
414
+ # @return [Array] with all tabs (quick_tab)
415
+ #
416
+ def quick_tabs
417
+ quick_tabbuttons
418
+ end
419
+
334
420
  ######################################################################
335
421
  # Retrieves the name of a window based on it's id
336
422
  #
@@ -341,7 +427,7 @@ module OperaWatir
341
427
  def window_name(win_id)
342
428
  driver.getQuickWindowName(win_id)
343
429
  end
344
-
430
+
345
431
  ######################################################################
346
432
  # Presses the key, with optional modifiers, and waits for loaded event
347
433
  #
@@ -360,9 +446,57 @@ module OperaWatir
360
446
  key_press_direct(key, *modifiers)
361
447
  wait_for_window_loaded("")
362
448
  end
363
-
449
+
450
+ ######################################################################
451
+ # Clicks the element and waits for the menu with menu_name as given
452
+ # opens
453
+ #
454
+ # @param [String] element Web page element to click (a link, an image ..)
455
+ # @param [Symbol] menu_name Name of menu that should open when clicking the element
456
+ #
457
+ # @return [String] name of menu opened if it matches menu_name given as
458
+ # parameter, otherwise empty string
459
+ #
460
+ def open_menu_with_rightclick(element, menu_name)
461
+ wait_start
462
+ element.right_click
463
+ wait_for_menu_shown(menu_name)
464
+ end
465
+
466
+ #####################################################################
467
+ #
468
+ # Presses key and waits for the menu to show
469
+ #
470
+ # @param [String] menu_name Name of the menu that should be opened
471
+ # @param [String] key Key to press
472
+ #
473
+ # @return [String] name of menu that was opened, or empty
474
+ #
475
+ def open_menu_with_key_press(menu_name, key, *modifiers)
476
+ wait_start
477
+ key_press_direct(key, *modifiers)
478
+ wait_for_menu_shown(menu_name)
479
+ end
480
+
481
+ #####################################################################
482
+ #
483
+ # Presses key and waits for the menu to close
484
+ #
485
+ # @param [String] menu_name Name of the menu that should be opened
486
+ # @param [String] key Key to press
487
+ #
488
+ # @return [String] name of menu that was closed, or empty string
489
+ #
490
+ def close_menu_with_key_press(menu_name, key, *modifiers)
491
+ wait_start
492
+ key_press_direct(key, *modifiers)
493
+ wait_for_menu_closed(menu_name)
494
+ end
495
+
496
+
497
+ =begin
364
498
  ##############################################################################
365
- # Clicks the element specified by method and selector,
499
+ # Clicks the element specified by method and selector,
366
500
  # and waits for the window with name win_name to be shown
367
501
  #
368
502
  # @param [WebElement] element element to click
@@ -370,53 +504,53 @@ module OperaWatir
370
504
  #
371
505
  # @return [int] Window ID of the window shown or 0 if no window is shown
372
506
  #
373
- =begin
507
+ #=begin
374
508
  # or open_dialog_with_click(type, method, selector, win_name)
375
509
  # open_dialog_with_click(:button, :id, "text", win_name)
376
- =end
510
+ #=end
377
511
  def open_dialog_with_click(method, selector, win_name)
378
512
  wait_start
379
513
  OperaWatir::WebElement.new(self, method, selector).click
380
514
  wait_for_window_shown(win_name)
381
515
  end
382
-
516
+ =end
383
517
 
384
518
  ######################################################################
385
- # Returns the full path to the Opera executable
519
+ # Returns the full path to the Opera executable
386
520
  #
387
- # @return [String] Full path to the opera executable
521
+ # @return [String] Full path to the opera executable
388
522
  #
389
523
  def path
390
524
  driver.getOperaPath()
391
525
  end
392
526
 
393
527
  ######################################################################
394
- # Returns the full path to the Opera large preferences folder
528
+ # Returns the full path to the Opera large preferences folder
395
529
  #
396
530
  # @return [String] Full path to the large preferences folder
397
531
  #
398
532
  def large_preferences_path
399
533
  driver.getLargePreferencesPath()
400
534
  end
401
-
535
+
402
536
  ######################################################################
403
- # Returns the full path to the Opera small preferences folder
537
+ # Returns the full path to the Opera small preferences folder
404
538
  #
405
539
  # @return [String] Full path to the small preferences folder
406
540
  #
407
541
  def small_preferences_path
408
542
  driver.getSmallPreferencesPath()
409
543
  end
410
-
544
+
411
545
  ######################################################################
412
- # Returns the full path to the Opera cache preferences folder
546
+ # Returns the full path to the Opera cache preferences folder
413
547
  #
414
548
  # @return [String] Full path to the cache preferences folder
415
549
  #
416
550
  def cache_preferences_path
417
551
  driver.getCachePreferencesPath()
418
552
  end
419
-
553
+
420
554
  ######################################################################
421
555
  # Returns the language string corresponding to the string_id provided
422
556
  #
@@ -436,56 +570,56 @@ module OperaWatir
436
570
  end
437
571
 
438
572
  ######################################################################
439
- # Returns true if the test is running on Mac
573
+ # Returns true if the test is running on Mac
440
574
  #
441
- # @return [Boolean] true we the operating system is Mac, otherwise false
575
+ # @return [Boolean] true we the operating system is Mac, otherwise false
442
576
  #
443
577
  def mac?
444
- Config::CONFIG['target_os'] == "darwin"
578
+ mac_internal?
445
579
  end
446
-
580
+
447
581
  ######################################################################
448
- # Returns true if the test is running on Linux
582
+ # Returns true if the test is running on Linux
449
583
  #
450
- # @return [Boolean] true we the operating system is Linux, otherwise false
584
+ # @return [Boolean] true we the operating system is Linux, otherwise false
451
585
  #
452
586
  def linux?
453
- Config::CONFIG['target_os'] == "linux"
587
+ linux_internal?
454
588
  end
455
-
589
+
456
590
  # @private
457
591
  # Special method to access the driver
458
592
  attr_reader :driver
459
-
593
+
460
594
  ######################################################################
461
- # Clear all private data (as in Delete Private Data Dialog)
595
+ # Clear all private data (as in Delete Private Data Dialog)
462
596
  #
463
- # @return [int] 0 if operation failed, else > 0
597
+ # @return [int] 0 if operation failed, else > 0
464
598
  #
465
599
  def clear_all_private_data
466
-
600
+
467
601
  #FIXME: Set CheckFlags to uncheck to prevent storing the settings used here
468
-
602
+
469
603
  win_id = open_dialog_with_action("Clear Private Data Dialog", "Delete private data")
470
604
  return 0 if win_id == 0
471
-
605
+
472
606
  #Ensure is Expanded
473
607
  if quick_button(:name, "Destails_expand").value == 0
474
608
  quick_button(:name, "Destails_expand").toggle_with_click
475
609
  end
476
-
610
+
477
611
  quick_checkboxes("Clear Private Data Dialog").each do |box|
478
612
  box.toggle_with_click unless box.checked?
479
613
  end
480
-
614
+
481
615
  #Delete all
482
616
  win_id = quick_button(:name, "button_OK").close_dialog_with_click("Clear Private Data Dialog")
483
-
617
+
484
618
  #FIXME: Reset CheckFlags
485
-
619
+
486
620
  win_id
487
621
  end
488
-
622
+
489
623
  ######################################################################
490
624
  # Clear typed and visited history
491
625
  #
@@ -494,35 +628,35 @@ module OperaWatir
494
628
  opera_desktop_action("Clear visited history")
495
629
  opera_desktop_action("Clear typed in history")
496
630
  end
497
-
631
+
498
632
  ######################################################################
499
- #
633
+ #
500
634
  # Clear disk cache
501
635
  #
502
636
  def clear_cache
503
637
  #TODO: Use Delete Private Data Dialog?
504
638
  opera_desktop_action("Clear disk cache")
505
639
  end
506
-
640
+
507
641
  ######################################################################
508
- #
642
+ #
509
643
  # Close all open tabs (except last one)
510
644
  #
511
645
  def close_all_tabs
512
646
  #The collection has the activate tab first and then the rest sorted on number, so resort to get on descending position
513
647
  quick_tabbuttons("Browser Window").sort {|t1, t2| (t2.position <=> t1.position) }.each do |btn|
514
648
  #Tab button is in Browser window which is prob not the active window,
515
- #so we cannot do this the easy way
649
+ #so we cannot do this the easy way
516
650
  #btn.quick_button(:name, "pb_CloseButton").close_window_with_click("Document Window") unless btn.position == 0
517
651
  #puts "Current tab = #{btn}"
518
652
  if btn.position != 0 or btn.value > 1 then
519
653
  quick_window(:name, "Browser Window").quick_tab(:pos, btn.position).quick_button(:name, "pb_CloseButton").close_window_with_click("Document Window")
520
- end
654
+ end
521
655
  end
522
656
  end
523
-
657
+
524
658
  #####################################################################
525
- #
659
+ #
526
660
  # Close all open dialogs
527
661
  #
528
662
  def close_all_dialogs
@@ -539,7 +673,61 @@ module OperaWatir
539
673
  end
540
674
  end
541
675
  end
542
-
676
+
677
+ ###############################################################
678
+ #
679
+ # key_press_with_condition(key, modifiers) { block } → res
680
+ #
681
+ #
682
+ # Performs the keypress specified and waits until block evaluates to true or timeout is hit
683
+ #
684
+ # @param [String] key - key to press
685
+ # @param *modifiers - modifier(s) to hold while pressing key
686
+ #
687
+ # @return value of block, or false if no block provided
688
+ #
689
+ def key_press_with_condition(key, *modifiers)
690
+ return false unless block_given?
691
+
692
+ key_press_direct(key, *modifiers)
693
+
694
+ start = Time.now
695
+ until res = yield rescue false do
696
+ if Time.now - start > ConditionTimeout
697
+ return false
698
+ end
699
+ sleep 0.1
700
+ end
701
+ res
702
+ end
703
+
704
+ ###############################################################
705
+ #
706
+ # action_with_condition { block } → res
707
+ #
708
+ #
709
+ # Executes action and waits until block evaluates to true or timeout is hit.
710
+ #
711
+ # @param [String] action_name - name of action to execute
712
+ # @param *params - parameters to the action
713
+ #
714
+ # @return value of block, or false if no block provided
715
+ #
716
+ def action_with_condition(action_name, *params)
717
+ return false unless block_given?
718
+
719
+ opera_desktop_action(action_name, *params)
720
+
721
+ start = Time.now
722
+ until res = yield rescue false do
723
+ if Time.now - start > ConditionTimeout
724
+ return false
725
+ end
726
+ sleep 0.1
727
+ end
728
+ res
729
+ end
730
+
543
731
  ############################################################################
544
732
  #
545
733
  # Reset prefs
@@ -550,7 +738,7 @@ module OperaWatir
550
738
  def reset_prefs(new_prefs)
551
739
  driver.resetOperaPrefs(new_prefs)
552
740
  end
553
-
741
+
554
742
  ##############################################################################
555
743
  #
556
744
  # Deletes profile for the connected Opera instance.
@@ -560,7 +748,7 @@ module OperaWatir
560
748
  def delete_profile
561
749
  driver.deleteOperaPrefs
562
750
  end
563
-
751
+
564
752
  # Set preference pref in prefs section prefs_section to value
565
753
  # specified.
566
754
  #
@@ -580,7 +768,7 @@ module OperaWatir
580
768
  def get_preference(prefs_section, pref)
581
769
  driver.getPref(prefs_section, pref)
582
770
  end
583
-
771
+
584
772
  # Get default value of preference pref in prefs section
585
773
  # prefs_section.
586
774
  #
@@ -591,37 +779,53 @@ module OperaWatir
591
779
  def get_default_preference(prefs_section, pref)
592
780
  driver.getDefaultPref(prefs_section, pref)
593
781
  end
594
-
782
+
595
783
  # @private
596
784
  def start_opera
597
785
  driver.startOpera
598
786
  end
599
787
 
788
+ # Is attached browser instance of type internal build or public
789
+ # desktop?
790
+ #
791
+ # @return [Boolean] True if browser attached is of type desktop,
792
+ # false otherwise.
793
+ def desktop?
794
+ true # Not nice, but if you're running desktopbrowser, assume running desktop
795
+ end
796
+
600
797
  private
601
798
 
799
+ def close_menu
800
+ wait_start
801
+ key_press_direct("Esc")
802
+ wait_for_menu_closed("")
803
+ end
804
+
805
+
602
806
  def self.opera_driver_settings
603
807
  @opera_driver_settings ||= OperaDriverSettings.new.tap {|s|
604
- s.setRunOperaLauncherFromOperaDriver true
808
+ #s.setRunOperaLauncherFromOperaDriver true
605
809
  s.setAutostart false if self.settings[:manual]
606
810
  s.setOperaLauncherBinary self.settings[:launcher]
607
811
  s.setOperaBinaryLocation self.settings[:path]
608
- s.setOperaBinaryArguments self.settings[:args].to_s + ' -autotestmode'
812
+ # s.setOperaBinaryArguments self.settings[:args].to_s + ' -autotestmode'
609
813
  s.setNoQuit self.settings[:no_quit]
610
814
  s.setNoRestart self.settings[:no_restart]
611
815
  s.setGuessOperaPath false
612
816
  s.setUseOperaIdle false if !self.settings[:opera_idle]
613
817
  }
614
818
  end
615
-
819
+
616
820
  # Gets the parent widget name of which there is none here
617
821
  def parent_widget
618
822
  nil
619
823
  end
620
-
824
+
621
825
  # Gets the window id to use for the search
622
826
  def window_id
623
827
  -1
624
828
  end
625
829
  end
626
-
830
+
627
831
  end