operawatir 0.3-jruby → 0.3.2-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/Gemfile +6 -2
  2. data/LICENSE +1 -1
  3. data/Rakefile +7 -8
  4. data/VERSION +1 -1
  5. data/bin/desktopwatir +3 -0
  6. data/bin/operawatir +2 -2
  7. data/lib/operadriver/webdriver-opera.jar +0 -0
  8. data/lib/operawatir.rb +14 -8
  9. data/lib/operawatir/browser.rb +49 -38
  10. data/lib/operawatir/compat/collection.rb +6 -0
  11. data/lib/operawatir/compat/element.rb +5 -2
  12. data/lib/operawatir/compat/element_finders.rb +19 -0
  13. data/lib/operawatir/desktop-waiter.rb +144 -0
  14. data/lib/operawatir/desktop_browser.rb +506 -0
  15. data/lib/operawatir/desktop_common.rb +111 -0
  16. data/lib/operawatir/desktop_container.rb +252 -0
  17. data/lib/operawatir/desktop_enums.rb +42 -0
  18. data/lib/operawatir/desktop_exceptions.rb +16 -0
  19. data/lib/operawatir/element.rb +6 -6
  20. data/lib/operawatir/exceptions.rb +3 -0
  21. data/lib/operawatir/keys.rb +116 -0
  22. data/lib/operawatir/platform.rb +59 -0
  23. data/lib/operawatir/quickwidgets.rb +3 -0
  24. data/lib/operawatir/quickwidgets/quick_addressfield.rb +23 -0
  25. data/lib/operawatir/quickwidgets/quick_button.rb +151 -0
  26. data/lib/operawatir/quickwidgets/quick_checkbox.rb +58 -0
  27. data/lib/operawatir/quickwidgets/quick_dialogtab.rb +23 -0
  28. data/lib/operawatir/quickwidgets/quick_dropdown.rb +27 -0
  29. data/lib/operawatir/quickwidgets/quick_editfield.rb +115 -0
  30. data/lib/operawatir/quickwidgets/quick_label.rb +12 -0
  31. data/lib/operawatir/quickwidgets/quick_radiobutton.rb +11 -0
  32. data/lib/operawatir/quickwidgets/quick_searchfield.rb +25 -0
  33. data/lib/operawatir/quickwidgets/quick_tab.rb +66 -0
  34. data/lib/operawatir/quickwidgets/quick_thumbnail.rb +26 -0
  35. data/lib/operawatir/quickwidgets/quick_toolbar.rb +11 -0
  36. data/lib/operawatir/quickwidgets/quick_treeitem.rb +157 -0
  37. data/lib/operawatir/quickwidgets/quick_treeview.rb +27 -0
  38. data/lib/operawatir/quickwidgets/quick_widget.rb +369 -0
  39. data/lib/operawatir/quickwidgets/quick_window.rb +150 -0
  40. data/lib/operawatir/selector.rb +1 -1
  41. data/lib/operawatir/version.rb +0 -1
  42. data/lib/operawatir/window.rb +9 -0
  43. data/operawatir.gemspec +382 -0
  44. data/spec/new_watirspec/browser_spec.rb +279 -0
  45. data/spec/new_watirspec/clipboard_spec.rb +79 -0
  46. data/spec/new_watirspec/collection_spec.rb +387 -0
  47. data/spec/new_watirspec/element_spec.rb +456 -0
  48. data/spec/new_watirspec/guards.rb +39 -0
  49. data/spec/new_watirspec/keys_spec.rb +206 -0
  50. data/spec/new_watirspec/server.rb +91 -0
  51. data/spec/new_watirspec/watirspec_helper.rb +62 -0
  52. data/spec/new_watirspec/window_spec.rb +370 -0
  53. data/utils/launchers/launcher-mac +0 -0
  54. metadata +191 -28
  55. data/.gitmodules +0 -3
@@ -0,0 +1,27 @@
1
+ module OperaWatir
2
+ class QuickDropdown < QuickEditField #QuickWidget
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:dropdown]
8
+ end
9
+
10
+ ######################################################################
11
+ # Checks if the item selected in the dropdown matches the text loaded
12
+ # from Opera using the string_id
13
+ #
14
+ # @param [String] string_id String ID to use to load the string from the current
15
+ # language file (e.g. "D_NEW_PREFERENCES_GENERAL")
16
+ #
17
+ # @return [Boolean] true if the dropdown has the item with the
18
+ # string_id selected, otherwise false
19
+ #
20
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
21
+ # using the specified method
22
+ def selected?(string_id)
23
+ element.isSelected(string_id)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,115 @@
1
+ module OperaWatir
2
+ class QuickEditField < QuickWidget
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:editfield]
8
+ end
9
+
10
+ ######################################################################
11
+ # Set focus to the edit field by clicking on it
12
+ #
13
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the editfield
14
+ # is not visible
15
+ #
16
+ def focus_with_click
17
+ super
18
+ end
19
+
20
+ ######################################################################
21
+ # Types a text string into the edit field
22
+ #
23
+ # @note Only chanracters that appear on the keyboard that is currently
24
+ # selected can be typed, and the edit field must have focus.
25
+ #
26
+ # @param [String] text text string to type in
27
+ #
28
+ # @return [String] contents of the edit field after typing has completed
29
+ #
30
+ def type_text(text)
31
+ text.each_char { | t | key_press_direct t }
32
+
33
+ # No event yet so just cheat and sleep
34
+ sleep(0.2);
35
+
36
+ # Return what is in the field to check
37
+ element(true).getText
38
+ end
39
+
40
+ ######################################################################
41
+ # Clears the contents of the edit field
42
+ #
43
+ # @note The edit field must have focus for this method to work
44
+ #
45
+ def clear
46
+ key_press_direct("a", :ctrl)
47
+ key_press_direct("backspace")
48
+
49
+ # Cheat until we have an event
50
+ sleep(0.1)
51
+ end
52
+
53
+ ######################################################################
54
+ # Presses a key including modifiers
55
+ #
56
+ # @example
57
+ # browser.quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field").key_press("a", :ctrl)
58
+ # browser.quick_toolbar(:name, "Document Toolbar").quick_addressfield(:name, "tba_address_field").key_press("c", :ctrl)
59
+ #
60
+ # @param [String] key key to press (e.g. "a" or "backspace")
61
+ # @param [Symbol] modifiers optional modifier(s) to hold down while pressing the key (e.g. :shift, :ctrl, :alt, :meta)
62
+ #
63
+ # @return [String] Text in the field after the keypress
64
+ #
65
+ # @note The edit field must have focus for this method to work
66
+ # @note WARNING: This method will not wait for page load or window
67
+ # shown events. If you need to wait for these events do not
68
+ # use this method
69
+ #
70
+ def key_press(key, *modifiers)
71
+ key_press_direct(key, *modifiers)
72
+
73
+ # Cheat until we have an event
74
+ sleep(0.1)
75
+
76
+ # Return what is in the field to check
77
+ element(true).getText
78
+ end
79
+
80
+ private
81
+ # @private
82
+ # Presses the key, and waits for loading to finish
83
+ def load_page_with_key_press(key, *modifiers)
84
+ wait_start
85
+ key_press_direct(key, *modifiers)
86
+ wait_for_window_loaded("")
87
+ end
88
+
89
+ # @private
90
+ # Enter some text and hit enter to do the action for the field
91
+ def enter_text_and_hit_enter(text)
92
+ loaded_url = ""
93
+
94
+ # Set focus
95
+ focus_with_click
96
+ # Clear the field
97
+ clear()
98
+ # Type in the text
99
+ typed_text = type_text(text) #Opens dropdown window
100
+ # Check that some text was typed, note the text might be changed in the
101
+ # url field so it might be different
102
+ if typed_text.length > 0
103
+ # Hit Enter to load the typed in url
104
+ win_id = load_page_with_key_press("Enter")
105
+ # Check that the page actually loaded in a window
106
+ if win_id > 0
107
+ # Refresh the control and get the text after the page as loaded
108
+ loaded_url = element(true).getText
109
+ end
110
+ end
111
+ loaded_url
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,12 @@
1
+ module OperaWatir
2
+ class QuickLabel < QuickWidget
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:label]
8
+ end
9
+
10
+ end
11
+ end
12
+
@@ -0,0 +1,11 @@
1
+ module OperaWatir
2
+ class QuickRadioButton < QuickCheckbox
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:radiobutton]
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module OperaWatir
2
+ class QuickSearchField < QuickEditField
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:search]
8
+ end
9
+
10
+ ######################################################################
11
+ # Enters the search text into the search field, and waits for page
12
+ # loading to finish
13
+ #
14
+ # @param [String] url text to search with
15
+ #
16
+ # @return [String] text in the address field after the page is loaded
17
+ # or a blank string
18
+ #
19
+ def search_with_text(search_text)
20
+ # Enters text in a field and then hits enter
21
+ enter_text_and_hit_enter(search_text)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,66 @@
1
+ module OperaWatir
2
+ class QuickTab < QuickButton
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:tabbutton]
8
+ end
9
+
10
+ ######################################################################
11
+ # Drag and drop this tab on tab tab_target
12
+ #
13
+ # @param [QuickTab] tab button to drop this tab on
14
+ #
15
+ #
16
+ # @raise [DesktopExceptions::UnknownObjectException] if the target is not a tab
17
+ #
18
+ def move_with_drag(tab_target)
19
+ raise(Exceptions::UnknownObjectException) unless tab_target.type == :tabbutton
20
+ drag_and_drop_on(tab_target, :center)
21
+
22
+ sleep(0.1)
23
+ end
24
+
25
+ ######################################################################
26
+ # Drag and drop this tab on another tab to add it to its tab group
27
+ #
28
+ # @param [QuickTab] tab (group) button to drop this tab on
29
+ #
30
+ # @raise [DesktopExceptions::UnknownObjectException] if the target is not a tab
31
+ #
32
+ # @return [int] the number of tabs in this tab group, or 1 if this is not a tab group button,
33
+ # in which case it represents only 1 tab, itself
34
+ def group_with_drag(tab_target)
35
+ raise(Exceptions::UnknownObjectException) unless tab_target.type == :tabbutton
36
+
37
+ # Drop on the edge of a tab to make the grouping work
38
+ drag_and_drop_on(tab_target, :edge)
39
+
40
+ sleep(0.1)
41
+
42
+ #Get the number of tabs in the group
43
+ element(true).value
44
+ end
45
+
46
+
47
+ ######################################################################
48
+ # Clicks the tab button, and waits for the tab to be shown / switches to the page
49
+ #
50
+ # @param [String] win_name name of the window that will be opened (Pass a blank string for any window)
51
+ #
52
+ # @return [int] Window ID of the window activated,
53
+ # 0 if the window is already the active one,
54
+ # or if no window is active
55
+ #
56
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the tab button
57
+ # is not visible
58
+ #
59
+ def activate_tab_with_click
60
+ wait_start
61
+ click
62
+ wait_for_window_activated("Document Window")
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ module OperaWatir
2
+ class QuickThumbnail < QuickButton
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:thumbnail]
8
+ end
9
+
10
+ ######################################################################
11
+ # Drag and drop this speeddial
12
+ #
13
+ # @param [QuickThumbnail] Thumbnail to drop this thumbnail on
14
+ #
15
+ # @raise [DesktopExceptions::UnknownObjectException] if the target is not a thumbnail
16
+ #
17
+ #@private
18
+ def move_with_drag(tab_target)
19
+ raise(Exceptions::UnknownObjectException) unless tab_target.type == :thumbnail
20
+ drag_and_drop_on(tab_target, :center)
21
+
22
+ sleep(0.1)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ module OperaWatir
2
+ class QuickToolbar < QuickWidget
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:toolbar]
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,157 @@
1
+ module OperaWatir
2
+ class QuickTreeItem < QuickWidget
3
+
4
+ # @private
5
+ # Checks the type of the widget is correct
6
+ def correct_type?
7
+ @element.getType == WIDGET_ENUM_MAP[:treeitem]
8
+ end
9
+
10
+ ######################################################################
11
+ # Set focus to the tree item by clicking on it
12
+ #
13
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeview
14
+ # the treeitem is in is not visible
15
+ #
16
+ def focus_with_click
17
+ # First scroll the item into view
18
+ scroll_item_into_view unless visible?
19
+ super
20
+ end
21
+
22
+ ######################################################################
23
+ # Expands a tree item when it is clicked
24
+ #
25
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
26
+ # is not visible
27
+ #
28
+ def expand_with_click
29
+ # For now there is no difference to focusing
30
+ focus_with_click
31
+ end
32
+
33
+ ######################################################################
34
+ # Expands a tree item when it is double clicked
35
+ #
36
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
37
+ # is not visible
38
+ #
39
+ def expand_with_double_click
40
+ scroll_item_into_view unless visible?
41
+ double_click
42
+ # No event yet so just cheat and sleep
43
+ sleep(0.1);
44
+ end
45
+
46
+ alias_method :collapse_with_double_click, :expand_with_double_click
47
+
48
+ ######################################################################
49
+ # Presses a key including modifiers
50
+ #
51
+ # @example
52
+ # browser.quick_treeview(:name, "Bookmarks View").quick_treeitem(:text, "Ask.com").key_press("Down")
53
+ # browser.quick_treeview(:name, "Bookmarks View").quick_treeitem(:text, "Ask.com").key_press("Del")
54
+ #
55
+ # @param [String] key key to press (e.g. "a" or "backspace")
56
+ # @param [Symbol] modifiers optional modifier(s) to hold down while pressing the key (e.g. :shift, :ctrl, :alt, :meta)
57
+ #
58
+ # @return [String] Text in the field after the keypress
59
+ #
60
+ # @note The edit field must have focus for this method to work
61
+ # @note WARNING: This method will not wait for page load or window
62
+ # shown events. If you need to wait for these events do not
63
+ # use this method
64
+ #
65
+ def key_press(key, *opts)
66
+ key_press_direct(key, *opts)
67
+ sleep(0.1)
68
+ end
69
+
70
+ ######################################################################
71
+ # Checks if the treeitem is selected
72
+ #
73
+ # @return [Boolean] true if the item is selected
74
+ #
75
+ # @raise [Exceptions::UnknownObjectException] if the widget could not be found
76
+ # using the specified method
77
+ def selected?
78
+ element.isSelected
79
+ end
80
+
81
+
82
+ ######################################################################
83
+ # Switch to the tree view tab by clicking on it (e.g. on the
84
+ # Advanced page of the preferences dialog)
85
+ #
86
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
87
+ # is not visible
88
+ #
89
+ def activate_tab_with_click
90
+ click
91
+
92
+ # No event yet so just cheat and sleep
93
+ sleep(0.1);
94
+ end
95
+
96
+ ######################################################################
97
+ # Double clicks the tree item, and waits for the window with
98
+ # window name win_name to be shown
99
+ #
100
+ # @param [String] win_name name of the window that will be opened (Pass a blank string for any window)
101
+ #
102
+ # @return [int] Window ID of the window shown or 0 if no window is shown
103
+ #
104
+ # @raise [DesktopExceptions::WidgetNotVisibleException] if the treeitem
105
+ # is not visible
106
+ #
107
+ def open_window_with_double_click(win_name)
108
+ wait_start
109
+ click(:left, 2)
110
+ wait_for_window_shown(win_name)
111
+ end
112
+
113
+ alias_method :open_dialog_with_double_click, :open_window_with_double_click
114
+
115
+
116
+ private
117
+ # @private
118
+ # Scrolls the item into view if required
119
+ def scroll_item_into_view
120
+
121
+ # Make sure we have a window id
122
+ win_id = window_id >= 0 ? window_id : driver.getActiveWindowID()
123
+
124
+ # Filter only treeitems in parent_treeview
125
+ treeitems = driver.getQuickWidgetList(win_id).select do |wdg|
126
+ wdg.getType == QuickWidget::WIDGET_ENUM_MAP[:treeitem] && wdg.getParentName == parent_name
127
+ end
128
+
129
+ # Get the first visible item
130
+ lowest = treeitems.find { | item| item.visible? } #This will always be a parent item, not a child
131
+ # Assume list is ordered? => lower row means scroll up, higher row means scroll down
132
+ key = row < lowest.row ? "PageUp" : "PageDown"
133
+
134
+ #Select the first item on visible part of list, and select it
135
+ qw = QuickTreeItem.new(self,lowest)
136
+ qw.focus_with_click
137
+ key_press_direct(key)
138
+
139
+ #First scroll
140
+ key_press_direct(key)
141
+
142
+ visible_treeitems = driver.getQuickWidgetList(win_id).select do |wdg|
143
+ wdg.getType == QuickWidget::WIDGET_ENUM_MAP[:treeitem] && wdg.getParentName == parent_name && wdg.visible?
144
+ end
145
+
146
+ # Stop scrolling if we have run through the whole list, the item is then a child and won't get visible
147
+ max_times = treeitems.length / visible_treeitems.length + 1
148
+ until element(true).visible? || max_times < 0
149
+ key_press_direct(key)
150
+ max_times-=1
151
+ end
152
+
153
+ end
154
+ end
155
+
156
+ end
157
+