Class: OperaWatir::DesktopBrowser
- Includes:
- DesktopContainer
- Defined in:
- lib/operawatir/desktop_browser.rb
Constant Summary collapse
- ConditionTimeout =
10.0- LoadActions =
["Open url in new page", "Open url in current page", "Open url in new background page", "Open url in new window", "New private page", "Paste and go", "Paste and go background", "Hotclick search", "Duplicate page", "Reopen page", "Back", "Forward", "Help", "Autocomplete server name"]
Instance Attribute Summary
Attributes inherited from Browser
#active_window, #keys, #preferences, #spatnav, #utils
Instance Method Summary collapse
-
#action_with_condition(action_name, *params) ⇒ Object
action_with_condition { block } → res.
-
#activate_tab_with_key_press(key, *modifiers) ⇒ int
Clicks the key and modifiers and waits for a new tab to be activated.
-
#active_quick_window_id ⇒ Object
Get ID of active Desktop UI window.
-
#cache_preferences_path ⇒ String
Returns the full path to the Opera cache preferences folder.
-
#clear_all_private_data ⇒ int
Clear all private data (as in Delete Private Data Dialog).
-
#clear_cache ⇒ Object
Clear disk cache.
-
#clear_history ⇒ Object
Clear typed and visited history.
-
#close_active_menu ⇒ Object
Closes the active menu.
-
#close_all_dialogs ⇒ Object
Close all open dialogs.
-
#close_all_menus ⇒ Object
Closes all open menus (Note: On mac one esc closes all menus).
-
#close_all_tabs ⇒ Object
Close all open tabs (except last one).
-
#close_dialog(dialog_name) ⇒ int
Close the dialog with name dialog_name, using the “Cancel” action.
-
#close_menu_with_key_press(menu_name, key, *modifiers) ⇒ String
Presses key and waits for the menu to close.
-
#close_window_with_action(win_name, action_name, *params) ⇒ int
(also: #close_dialog_with_action)
Executes the action given by action_name, and waits for the window with window name win_name to close.
-
#close_window_with_key_press(win_name, key, *opts) ⇒ int
(also: #close_dialog_with_key_press)
Presses the key, with optional modifiers, and waits for the window with window name win_name to close.
-
#delete_profile ⇒ Object
Deletes profile for the connected Opera instance.
-
#desktop? ⇒ Boolean
Is attached browser instance of type internal build or public desktop?.
-
#get_default_preference(prefs_section, pref) ⇒ String
Get default value of preference pref in prefs section prefs_section.
-
#get_preference(prefs_section, pref) ⇒ String
Get value of preference pref in prefs section prefs_section.
-
#key_press_with_condition(key, *modifiers) ⇒ Object
key_press_with_condition(key, modifiers) { block } → res.
-
#large_preferences_path ⇒ String
Returns the full path to the Opera large preferences folder.
-
#linux? ⇒ Boolean
Returns true if the test is running on Linux.
-
#load_page_with_key_press(key, *modifiers) ⇒ int
Presses the key, with optional modifiers, and waits for loaded event.
-
#load_window_with_action(win_name, action_name, *params) ⇒ int
Executes the action given by action_name, and waits for the window with window name win_name to be loaded.
-
#mac? ⇒ Boolean
Returns true if the test is running on Mac.
-
#open_dialog_with_url(dialog_name, url) ⇒ int
Opens a new tab and loads the url entered, then waits for a dialog to be shown based on the url entered.
-
#open_menu_with_key_press(menu_name, key, *modifiers) ⇒ String
Presses key and waits for the menu to show.
-
#open_menu_with_rightclick(element, menu_name) ⇒ String
Clicks the element and waits for the menu with menu_name as given opens.
-
#open_pages ⇒ Array
Retrieves an array of all tabs (Document Windows).
-
#open_window_with_action(win_name, action_name, *params) ⇒ int
(also: #open_dialog_with_action)
Executes the action given by action_name, and waits for the window with window name win_name to be shown.
-
#open_window_with_key_press(win_name, key, *modifiers) ⇒ int
(also: #open_dialog_with_key_press)
Presses the key, with optional modifiers, and waits for the window with window name win_name to be shown.
-
#path ⇒ String
Returns the full path to the Opera executable.
-
#quick_menuitems ⇒ Object
TODO.
-
#quick_menus ⇒ Object
TODO.
-
#quick_tabs ⇒ Array
With all tabs (quick_tab).
-
#quick_windows ⇒ Array
Retrieves an array of all windows.
-
#quit_driver ⇒ Object
Quits the driver without exiting Opera.
-
#quit_opera ⇒ Object
Quits Opera.
-
#reset_prefs(new_prefs) ⇒ Object
Reset prefs.
-
#restart ⇒ Object
Restarts Opera.
-
#set_alignment_with_action(toolbar_name, alignment) ⇒ Object
Sets the alignment of a toolbar or panel.
-
#set_preference(prefs_section, pref, value) ⇒ Object
Set preference pref in prefs section prefs_section to value specified.
-
#small_preferences_path ⇒ String
Returns the full path to the Opera small preferences folder.
-
#string(string_id, skip_ampersand = true) ⇒ String
Returns the language string corresponding to the string_id provided.
-
#widgets(window) ⇒ Array
(also: #quick_widgets)
Retrieves an array of all widgets in the window with window name win_name.
-
#window_name(win_id) ⇒ String
Retrieves the name of a window based on it’s id.
Methods included from DesktopContainer
#quick_addressfield, #quick_button, #quick_checkbox, #quick_dialogtab, #quick_dropdown, #quick_dropdownitem, #quick_editfield, #quick_find, #quick_griditem, #quick_gridlayout, #quick_label, #quick_menu, #quick_menuitem, #quick_radiobutton, #quick_searchfield, #quick_tab, #quick_thumbnail, #quick_toolbar, #quick_treeitem, #quick_treeview, #quick_window
Methods inherited from Browser
#actions, #copy, #cut, #key, #key_down, #key_up, #name, #opera_action, #opera_action_list, #paste, #platform, #quit, #select_all, settings, settings=, #type, #ua_string, #url=, #version
Instance Method Details
#action_with_condition(action_name, *params) ⇒ Object
action_with_condition { block } → res
Executes action and waits until block evaluates to true or timeout is hit.
716 717 718 719 720 721 722 723 724 725 726 727 728 729 |
# File 'lib/operawatir/desktop_browser.rb', line 716 def action_with_condition(action_name, *params) return false unless block_given? opera_desktop_action(action_name, *params) start = Time.now until res = yield rescue false do if Time.now - start > ConditionTimeout return false end sleep 0.1 end res end |
#activate_tab_with_key_press(key, *modifiers) ⇒ int
Clicks the key and modifiers and waits for a new tab to be activated
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/operawatir/desktop_browser.rb', line 150 def activate_tab_with_key_press(key, *modifiers) wait_start # TODO: FIXME. key_down and up are not yet implemented on mac and windows if linux? key_down_direct(key,*modifiers) key_up_direct(key, *modifiers) else key_press_direct(key, *modifiers) end wait_for_window_activated("Document Window") end |
#active_quick_window_id ⇒ Object
Get ID of active Desktop UI window
62 63 64 |
# File 'lib/operawatir/desktop_browser.rb', line 62 def active_quick_window_id driver.getActiveQuickWindowID() end |
#cache_preferences_path ⇒ String
Returns the full path to the Opera cache preferences folder
550 551 552 |
# File 'lib/operawatir/desktop_browser.rb', line 550 def cache_preferences_path driver.getCachePreferencesPath() end |
#clear_all_private_data ⇒ int
Clear all private data (as in Delete Private Data Dialog)
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
# File 'lib/operawatir/desktop_browser.rb', line 599 def clear_all_private_data #FIXME: Set CheckFlags to uncheck to prevent storing the settings used here win_id = open_dialog_with_action("Clear Private Data Dialog", "Delete private data") return 0 if win_id == 0 #Ensure is Expanded if (:name, "Destails_expand").value == 0 (:name, "Destails_expand").toggle_with_click end quick_checkboxes("Clear Private Data Dialog").each do |box| box.toggle_with_click unless box.checked? end #Delete all win_id = (:name, "button_OK").close_dialog_with_click("Clear Private Data Dialog") #FIXME: Reset CheckFlags win_id end |
#clear_cache ⇒ Object
Clear disk cache
636 637 638 639 |
# File 'lib/operawatir/desktop_browser.rb', line 636 def clear_cache #TODO: Use Delete Private Data Dialog? opera_desktop_action("Clear disk cache") end |
#clear_history ⇒ Object
Clear typed and visited history
626 627 628 629 630 |
# File 'lib/operawatir/desktop_browser.rb', line 626 def clear_history #TODO: Use Delete Private Data Dialog? opera_desktop_action("Clear visited history") opera_desktop_action("Clear typed in history") end |
#close_active_menu ⇒ Object
Closes the active menu
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/operawatir/desktop_browser.rb', line 382 def wait_start = main = .select {|| .name == "Main Menu"} main_open = main.length > 0 = main_open ? (.length > 2) : .length > 1 if key_press_direct("Left") else end ("") end |
#close_all_dialogs ⇒ Object
Close all open dialogs
662 663 664 665 666 667 668 669 670 671 672 673 674 675 |
# File 'lib/operawatir/desktop_browser.rb', line 662 def close_all_dialogs win_id = driver.getActiveQuickWindowID() until quick_window(:id, win_id).type != :dialog do win = quick_window(:id, driver.getActiveQuickWindowID()) if win.type == :dialog close_dialog(win.name) if (driver.getActiveQuickWindowID() != win_id) win_id = driver.getActiveQuickWindowID() else break end end end end |
#close_all_menus ⇒ Object
Closes all open menus (Note: On mac one esc closes all menus)
403 404 405 406 407 408 409 410 |
# File 'lib/operawatir/desktop_browser.rb', line 403 def i = 6 #Just some number while .delete_if { || .name == "Main Menu" }.length > 0 i-=1 break if i == 0 end end |
#close_all_tabs ⇒ Object
Close all open tabs (except last one)
645 646 647 648 649 650 651 652 653 654 655 656 |
# File 'lib/operawatir/desktop_browser.rb', line 645 def close_all_tabs #The collection has the activate tab first and then the rest sorted on number, so resort to get on descending position ("Browser Window").sort {|t1, t2| (t2.position <=> t1.position) }.each do |btn| #Tab button is in Browser window which is prob not the active window, #so we cannot do this the easy way #btn.quick_button(:name, "pb_CloseButton").close_window_with_click("Document Window") unless btn.position == 0 #puts "Current tab = #{btn}" if btn.position != 0 or btn.value > 1 then quick_window(:name, "Browser Window").quick_tab(:pos, btn.position).(:name, "pb_CloseButton").close_window_with_click("Document Window") end end end |
#close_dialog(dialog_name) ⇒ int
Close the dialog with name dialog_name, using the “Cancel” action
238 239 240 241 242 |
# File 'lib/operawatir/desktop_browser.rb', line 238 def close_dialog(dialog_name) wait_start opera_desktop_action("Cancel") wait_for_window_close(dialog_name) end |
#close_menu_with_key_press(menu_name, key, *modifiers) ⇒ String
Presses key and waits for the menu to close
490 491 492 493 494 |
# File 'lib/operawatir/desktop_browser.rb', line 490 def (, key, *modifiers) wait_start key_press_direct(key, *modifiers) () end |
#close_window_with_action(win_name, action_name, *params) ⇒ int Also known as: close_dialog_with_action
Executes the action given by action_name, and waits for the window with window name win_name to close
197 198 199 200 201 |
# File 'lib/operawatir/desktop_browser.rb', line 197 def close_window_with_action(win_name, action_name, *params) wait_start opera_desktop_action(action_name, *params) wait_for_window_close(win_name) end |
#close_window_with_key_press(win_name, key, *opts) ⇒ int Also known as: close_dialog_with_key_press
Presses the key, with optional modifiers, and waits for the window with window name win_name to close
219 220 221 222 223 |
# File 'lib/operawatir/desktop_browser.rb', line 219 def close_window_with_key_press(win_name, key, *opts) wait_start key_press_direct(key, *opts) wait_for_window_close(win_name) end |
#delete_profile ⇒ Object
Deletes profile for the connected Opera instance. Should only be called after quitting (and before starting) Opera.
748 749 750 |
# File 'lib/operawatir/desktop_browser.rb', line 748 def delete_profile driver.deleteOperaPrefs end |
#desktop? ⇒ Boolean
Is attached browser instance of type internal build or public desktop?
793 794 795 |
# File 'lib/operawatir/desktop_browser.rb', line 793 def desktop? true # Not nice, but if you're running desktopbrowser, assume running desktop end |
#get_default_preference(prefs_section, pref) ⇒ String
Get default value of preference pref in prefs section prefs_section.
779 780 781 |
# File 'lib/operawatir/desktop_browser.rb', line 779 def get_default_preference(prefs_section, pref) driver.getDefaultPref(prefs_section, pref) end |
#get_preference(prefs_section, pref) ⇒ String
Get value of preference pref in prefs section prefs_section.
768 769 770 |
# File 'lib/operawatir/desktop_browser.rb', line 768 def get_preference(prefs_section, pref) driver.getPref(prefs_section, pref) end |
#key_press_with_condition(key, *modifiers) ⇒ Object
key_press_with_condition(key, modifiers) { block } → res
Performs the keypress specified and waits until block evaluates to true or timeout is hit
689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
# File 'lib/operawatir/desktop_browser.rb', line 689 def key_press_with_condition(key, *modifiers) return false unless block_given? key_press_direct(key, *modifiers) start = Time.now until res = yield rescue false do if Time.now - start > ConditionTimeout return false end sleep 0.1 end res end |
#large_preferences_path ⇒ String
Returns the full path to the Opera large preferences folder
532 533 534 |
# File 'lib/operawatir/desktop_browser.rb', line 532 def large_preferences_path driver.getLargePreferencesPath() end |
#linux? ⇒ Boolean
Returns true if the test is running on Linux
586 587 588 |
# File 'lib/operawatir/desktop_browser.rb', line 586 def linux? linux_internal? end |
#load_page_with_key_press(key, *modifiers) ⇒ int
Presses the key, with optional modifiers, and waits for loaded event
444 445 446 447 448 |
# File 'lib/operawatir/desktop_browser.rb', line 444 def load_page_with_key_press(key, *modifiers) wait_start key_press_direct(key, *modifiers) wait_for_window_loaded("") end |
#load_window_with_action(win_name, action_name, *params) ⇒ int
Executes the action given by action_name, and waits for the window with window name win_name to be loaded
105 106 107 108 109 110 111 112 113 |
# File 'lib/operawatir/desktop_browser.rb', line 105 def load_window_with_action(win_name, action_name, *params) if LoadActions.include?(action_name) wait_start opera_desktop_action(action_name, *params) wait_for_window_loaded(win_name) else raise(DesktopExceptions::UnsupportedActionException, "Action #{action_name} not supported") end end |
#mac? ⇒ Boolean
Returns true if the test is running on Mac
577 578 579 |
# File 'lib/operawatir/desktop_browser.rb', line 577 def mac? mac_internal? end |
#open_dialog_with_url(dialog_name, url) ⇒ int
Opens a new tab and loads the url entered, then waits for a dialog to be shown based on the url entered
176 177 178 179 180 181 |
# File 'lib/operawatir/desktop_browser.rb', line 176 def open_dialog_with_url(dialog_name, url) wait_start opera_desktop_action("Open url in new page", url) # The loading of the page will happen first then the dialog will be shown wait_for_window_shown(dialog_name) end |
#open_menu_with_key_press(menu_name, key, *modifiers) ⇒ String
Presses key and waits for the menu to show
475 476 477 478 479 |
# File 'lib/operawatir/desktop_browser.rb', line 475 def (, key, *modifiers) wait_start key_press_direct(key, *modifiers) () end |
#open_menu_with_rightclick(element, menu_name) ⇒ String
Clicks the element and waits for the menu with menu_name as given opens
460 461 462 463 464 |
# File 'lib/operawatir/desktop_browser.rb', line 460 def (element, ) wait_start element.right_click () end |
#open_pages ⇒ Array
Retrieves an array of all tabs (Document Windows)
334 335 336 |
# File 'lib/operawatir/desktop_browser.rb', line 334 def open_pages quick_windows.select { |win| win.name == "Document Window" } end |
#open_window_with_action(win_name, action_name, *params) ⇒ int Also known as: open_dialog_with_action
Executes the action given by action_name, and waits for the window with window name win_name to be shown
80 81 82 83 84 85 86 87 88 |
# File 'lib/operawatir/desktop_browser.rb', line 80 def open_window_with_action(win_name, action_name, *params) if LoadActions.include?(action_name) then raise(DesktopExceptions::UnsupportedActionException, "Action #{action_name} not supported") end wait_start opera_desktop_action(action_name, *params) wait_for_window_shown(win_name) end |
#open_window_with_key_press(win_name, key, *modifiers) ⇒ int Also known as: open_dialog_with_key_press
Presses the key, with optional modifiers, and waits for the window with window name win_name to be shown
129 130 131 132 133 |
# File 'lib/operawatir/desktop_browser.rb', line 129 def open_window_with_key_press(win_name, key, *modifiers) wait_start key_press_direct(key, *modifiers) wait_for_window_shown(win_name) end |
#path ⇒ String
Returns the full path to the Opera executable
523 524 525 |
# File 'lib/operawatir/desktop_browser.rb', line 523 def path driver.getOperaPath() end |
#quick_menuitems ⇒ Object
TODO
372 373 374 375 376 |
# File 'lib/operawatir/desktop_browser.rb', line 372 def driver.getQuickMenuItemList().map do |java_item| QuickMenuItem.new(self, java_item) end.to_a end |
#quick_menus ⇒ Object
TODO
365 366 367 368 369 |
# File 'lib/operawatir/desktop_browser.rb', line 365 def driver.getQuickMenuList().map do || QuickMenu.new(self, ) end.to_a end |
#quick_tabs ⇒ Array
Returns with all tabs (quick_tab).
416 417 418 |
# File 'lib/operawatir/desktop_browser.rb', line 416 def quick_tabs end |
#quick_windows ⇒ Array
Retrieves an array of all windows
320 321 322 323 324 |
# File 'lib/operawatir/desktop_browser.rb', line 320 def quick_windows driver.getQuickWindowList.map do |java_window| QuickWindow.new(self,java_window) end.to_a end |
#quit_driver ⇒ Object
Quits the driver without exiting Opera
54 55 56 |
# File 'lib/operawatir/desktop_browser.rb', line 54 def quit_driver driver.quitDriver end |
#quit_opera ⇒ Object
Quits Opera
39 40 41 |
# File 'lib/operawatir/desktop_browser.rb', line 39 def quit_opera driver.quitOpera end |
#reset_prefs(new_prefs) ⇒ Object
Reset prefs
Quits Opera and copies prefs from src to dest, then restarts Opera with the new Prefs
738 739 740 |
# File 'lib/operawatir/desktop_browser.rb', line 738 def reset_prefs(new_prefs) driver.resetOperaPrefs(new_prefs) end |
#restart ⇒ Object
Restarts Opera
46 47 48 49 |
# File 'lib/operawatir/desktop_browser.rb', line 46 def restart driver.quitOpera driver.startOpera end |
#set_alignment_with_action(toolbar_name, alignment) ⇒ Object
Sets the alignment of a toolbar or panel
251 252 253 254 |
# File 'lib/operawatir/desktop_browser.rb', line 251 def set_alignment_with_action(, alignment) opera_desktop_action("Set alignment", , alignment) sleep(0.1) end |
#set_preference(prefs_section, pref, value) ⇒ Object
Set preference pref in prefs section prefs_section to value specified.
758 759 760 |
# File 'lib/operawatir/desktop_browser.rb', line 758 def set_preference(prefs_section, pref, value) driver.setPref(prefs_section, pref, value.to_s) end |
#small_preferences_path ⇒ String
Returns the full path to the Opera small preferences folder
541 542 543 |
# File 'lib/operawatir/desktop_browser.rb', line 541 def small_preferences_path driver.getSmallPreferencesPath() end |
#string(string_id, skip_ampersand = true) ⇒ String
Returns the language string corresponding to the string_id provided
568 569 570 |
# File 'lib/operawatir/desktop_browser.rb', line 568 def string(string_id, skip_ampersand = true) string = driver.getString(string_id, skip_ampersand) end |
#widgets(window) ⇒ Array Also known as: quick_widgets
Retrieves an array of all widgets in the window with window name win_name
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/operawatir/desktop_browser.rb', line 269 def (window) # If window specifies window name, and the active window has this name # use its id to get the widgets, if window.is_a? String active_win_id = driver.getActiveQuickWindowID() active_win_name = driver.getQuickWindowName(active_win_id) #If the active window is of same type, then grab that one, not first if active_win_name == window #e.g. Both Document Window window = active_win_id end end driver.getQuickWidgetList(window).map do || case .getType when QuickWidget::WIDGET_ENUM_MAP[:button] QuickButton.new(self,) when QuickWidget::WIDGET_ENUM_MAP[:checkbox] QuickCheckbox.new(self,) when QuickWidget::WIDGET_ENUM_MAP[:dialogtab] QuickDialogTab.new(self,) when QuickWidget::WIDGET_ENUM_MAP[:dropdown] QuickDropdown.new(self,) when QuickWidget::WIDGET_ENUM_MAP[:editfield] QuickEditField.new(self,) when QuickWidget::WIDGET_ENUM_MAP[:label] QuickLabel.new(self,) when QuickWidget::WIDGET_ENUM_MAP[:radiobutton] QuickRadioButton.new(self,) when QuickWidget::WIDGET_ENUM_MAP[:treeview] QuickTreeView.new(self,) when QuickWidget::WIDGET_ENUM_MAP[:treeitem] QuickTreeItem.new(self,) when QuickWidget::WIDGET_ENUM_MAP[:thumbnail] QuickTreeItem.new(self,) else QuickWidget.new(self,) end end.to_a end |
#window_name(win_id) ⇒ String
Retrieves the name of a window based on it’s id
427 428 429 |
# File 'lib/operawatir/desktop_browser.rb', line 427 def window_name(win_id) driver.getQuickWindowName(win_id) end |