operawatir 0.4-jruby → 0.4.1-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 (222) hide show
  1. data/.gitmodules +3 -3
  2. data/AUTHORS +1 -0
  3. data/CHANGES +454 -0
  4. data/README.md +67 -50
  5. data/Rakefile +6 -10
  6. data/VERSION +1 -1
  7. data/bin/desktopwatir +52 -29
  8. data/bin/operawatir +50 -18
  9. data/lib/operadriver/client-combined-nodeps.jar +0 -0
  10. data/lib/operadriver/webdriver-opera.jar +0 -0
  11. data/lib/operawatir.rb +8 -1
  12. data/lib/operawatir/browser.rb +35 -15
  13. data/lib/operawatir/collection.rb +2 -2
  14. data/lib/operawatir/compat.rb +3 -2
  15. data/lib/operawatir/compat/browser.rb +0 -5
  16. data/lib/operawatir/compat/collection.rb +15 -0
  17. data/lib/operawatir/compat/element.rb +72 -21
  18. data/lib/operawatir/compat/element_finders.rb +6 -0
  19. data/lib/operawatir/compat/selector.rb +7 -0
  20. data/lib/operawatir/compat/window.rb +49 -0
  21. data/lib/operawatir/desktop_browser.rb +88 -14
  22. data/lib/operawatir/desktop_common.rb +0 -2
  23. data/lib/operawatir/desktop_container.rb +82 -29
  24. data/lib/operawatir/desktop_helper.rb +2 -0
  25. data/lib/operawatir/element.rb +49 -25
  26. data/lib/operawatir/helper.rb +5 -3
  27. data/lib/operawatir/keys.rb +19 -6
  28. data/lib/operawatir/preferences.rb +315 -78
  29. data/lib/operawatir/quickwidgets.rb +2 -1
  30. data/lib/operawatir/quickwidgets/quick_addressfield.rb +12 -0
  31. data/lib/operawatir/quickwidgets/quick_button.rb +8 -2
  32. data/lib/operawatir/quickwidgets/quick_checkbox.rb +5 -5
  33. data/lib/operawatir/quickwidgets/quick_editfield.rb +8 -5
  34. data/lib/operawatir/quickwidgets/quick_find.rb +11 -0
  35. data/lib/operawatir/quickwidgets/quick_griditem.rb +11 -0
  36. data/lib/operawatir/quickwidgets/quick_gridlayout.rb +11 -0
  37. data/lib/operawatir/quickwidgets/quick_searchfield.rb +7 -1
  38. data/lib/operawatir/quickwidgets/quick_tab.rb +0 -1
  39. data/lib/operawatir/quickwidgets/quick_treeitem.rb +22 -1
  40. data/lib/operawatir/quickwidgets/quick_widget.rb +62 -23
  41. data/lib/operawatir/quickwidgets/quick_window.rb +32 -2
  42. data/lib/operawatir/screenshot.rb +46 -0
  43. data/lib/operawatir/version.rb +6 -4
  44. data/lib/operawatir/window.rb +53 -67
  45. data/operawatir.gemspec +310 -245
  46. data/spec/operawatir/README.md +4 -0
  47. data/spec/operawatir/core/browser_spec.rb +82 -0
  48. data/spec/operawatir/core/element_spec.rb +88 -0
  49. data/spec/operawatir/core/preferences_spec.rb +438 -0
  50. data/spec/operawatir/core/screenshot_spec.rb +76 -0
  51. data/spec/{new_watirspec → operawatir/core}/spatnav_spec.rb +3 -3
  52. data/spec/operawatir/core/window_spec.rb +76 -0
  53. data/spec/operawatir/desktop/desktopbrowser_spec.rb +316 -0
  54. data/spec/operawatir/desktop/quickaddressfield_spec.rb +59 -0
  55. data/spec/operawatir/desktop/quickbutton_spec.rb +248 -0
  56. data/spec/operawatir/desktop/quickcheckbox_spec.rb +36 -0
  57. data/spec/operawatir/desktop/quickdialogtab_spec.rb +30 -0
  58. data/spec/operawatir/desktop/quickdropdown_spec.rb +39 -0
  59. data/spec/operawatir/desktop/quickeditfield_spec.rb +51 -0
  60. data/spec/operawatir/desktop/quickfind_spec.rb +30 -0
  61. data/spec/operawatir/desktop/quickgriditem_spec.rb +16 -0
  62. data/spec/operawatir/desktop/quickgridlayout_spec.rb +15 -0
  63. data/spec/operawatir/desktop/quicklabel_spec.rb +28 -0
  64. data/spec/operawatir/desktop/quickradiobutton_spec.rb +24 -0
  65. data/spec/operawatir/desktop/quicksearchfield_spec.rb +26 -0
  66. data/spec/operawatir/desktop/quicktab_spec.rb +86 -0
  67. data/spec/operawatir/desktop/quickthumbnail_spec.rb +37 -0
  68. data/spec/operawatir/desktop/quicktreeitem_spec.rb +135 -0
  69. data/spec/operawatir/desktop/quicktreeview_spec.rb +30 -0
  70. data/spec/operawatir/desktop/quickwidget_spec.rb +101 -0
  71. data/spec/operawatir/desktop/quickwindow_spec.rb +108 -0
  72. data/spec/operawatir/desktop/shared/shared.rb +138 -0
  73. data/spec/operawatir/fixtures/boxes.html +22 -0
  74. data/spec/operawatir/fixtures/browsers.svg +367 -0
  75. data/spec/operawatir/fixtures/frames.html +13 -0
  76. data/spec/operawatir/fixtures/grid.html +29 -0
  77. data/spec/operawatir/fixtures/input_fields_value.html +6 -0
  78. data/spec/operawatir/fixtures/onclick.html +20 -0
  79. data/spec/operawatir/fixtures/paragraphs.html +15 -0
  80. data/spec/operawatir/fixtures/two_input_fields.html +6 -0
  81. data/spec/{new_watirspec → operawatir}/guards.rb +0 -0
  82. data/spec/operawatir/matchers.rb +68 -0
  83. data/spec/{legacy_watirspec → operawatir}/server.rb +0 -0
  84. data/spec/operawatir/watirspec.rake +43 -0
  85. data/spec/operawatir/watirspec_desktophelper.rb +14 -0
  86. data/spec/operawatir/watirspec_helper.rb +62 -0
  87. data/spec/{legacy_watirspec → watir2}/area_spec.rb +0 -0
  88. data/spec/{legacy_watirspec → watir2}/areas_spec.rb +0 -0
  89. data/spec/{legacy_watirspec → watir2}/browser_spec.rb +2 -0
  90. data/spec/{legacy_watirspec → watir2}/button_spec.rb +0 -0
  91. data/spec/{legacy_watirspec → watir2}/buttons_spec.rb +0 -0
  92. data/spec/{legacy_watirspec → watir2}/checkbox_spec.rb +0 -0
  93. data/spec/{legacy_watirspec → watir2}/checkboxes_spec.rb +0 -0
  94. data/spec/{legacy_watirspec → watir2}/collections_spec.rb +0 -0
  95. data/spec/{legacy_watirspec → watir2}/dd_spec.rb +0 -0
  96. data/spec/{legacy_watirspec → watir2}/dds_spec.rb +0 -0
  97. data/spec/{legacy_watirspec → watir2}/del_spec.rb +0 -0
  98. data/spec/{legacy_watirspec → watir2}/dels_spec.rb +0 -0
  99. data/spec/{legacy_watirspec → watir2}/div_spec.rb +0 -0
  100. data/spec/{legacy_watirspec → watir2}/divs_spec.rb +0 -0
  101. data/spec/{legacy_watirspec → watir2}/dl_spec.rb +0 -0
  102. data/spec/{legacy_watirspec → watir2}/dls_spec.rb +0 -0
  103. data/spec/{legacy_watirspec → watir2}/dt_spec.rb +0 -0
  104. data/spec/{legacy_watirspec → watir2}/dts_spec.rb +0 -0
  105. data/spec/watir2/element_spec.rb +155 -0
  106. data/spec/{legacy_watirspec → watir2}/em_spec.rb +0 -0
  107. data/spec/{legacy_watirspec → watir2}/ems_spec.rb +0 -0
  108. data/spec/{legacy_watirspec → watir2}/filefield_spec.rb +0 -0
  109. data/spec/{legacy_watirspec → watir2}/filefields_spec.rb +0 -0
  110. data/spec/{legacy_watirspec → watir2}/fixtures/2000_spans.html +0 -0
  111. data/spec/{legacy_watirspec → watir2}/fixtures/bug_duplicate_attributes.html +0 -0
  112. data/spec/{legacy_watirspec → watir2}/fixtures/bug_javascript_001.html +0 -0
  113. data/spec/{legacy_watirspec → watir2}/fixtures/buttons_with_duplicate_ids.html +0 -0
  114. data/spec/{legacy_watirspec → watir2}/fixtures/collections.html +0 -0
  115. data/spec/{legacy_watirspec → watir2}/fixtures/definition_lists.html +0 -0
  116. data/spec/{legacy_watirspec → watir2}/fixtures/euc-jp_text.html +0 -0
  117. data/spec/{legacy_watirspec → watir2}/fixtures/forms_with_input_elements.html +0 -0
  118. data/spec/{legacy_watirspec → watir2}/fixtures/frame_1.html +0 -0
  119. data/spec/{legacy_watirspec → watir2}/fixtures/frame_2.html +0 -0
  120. data/spec/{legacy_watirspec → watir2}/fixtures/frames.html +0 -0
  121. data/spec/{legacy_watirspec → watir2}/fixtures/iframes.html +0 -0
  122. data/spec/{legacy_watirspec → watir2}/fixtures/images.html +0 -0
  123. data/spec/{legacy_watirspec → watir2}/fixtures/images/1.gif +0 -0
  124. data/spec/{legacy_watirspec → watir2}/fixtures/images/2.gif +0 -0
  125. data/spec/{legacy_watirspec → watir2}/fixtures/images/3.gif +0 -0
  126. data/spec/{legacy_watirspec → watir2}/fixtures/images/button.jpg +0 -0
  127. data/spec/{legacy_watirspec → watir2}/fixtures/images/circle.jpg +0 -0
  128. data/spec/{legacy_watirspec → watir2}/fixtures/images/map.gif +0 -0
  129. data/spec/{legacy_watirspec → watir2}/fixtures/images/map2.gif +0 -0
  130. data/spec/{legacy_watirspec → watir2}/fixtures/images/minus.gif +0 -0
  131. data/spec/{legacy_watirspec → watir2}/fixtures/images/originaltriangle.jpg +0 -0
  132. data/spec/{legacy_watirspec → watir2}/fixtures/images/plus.gif +0 -0
  133. data/spec/{legacy_watirspec → watir2}/fixtures/images/square.jpg +0 -0
  134. data/spec/{legacy_watirspec → watir2}/fixtures/images/triangle.jpg +0 -0
  135. data/spec/{legacy_watirspec → watir2}/fixtures/iso-2022-jp_text.html +0 -0
  136. data/spec/{legacy_watirspec → watir2}/fixtures/javascript/helpers.js +0 -0
  137. data/spec/{legacy_watirspec → watir2}/fixtures/jquery.html +0 -0
  138. data/spec/{legacy_watirspec → watir2}/fixtures/latin1_text.html +0 -0
  139. data/spec/{legacy_watirspec → watir2}/fixtures/multiple_ids.html +0 -0
  140. data/spec/{legacy_watirspec → watir2}/fixtures/non_control_elements.html +0 -0
  141. data/spec/{legacy_watirspec → watir2}/fixtures/parser_bug_001.html +0 -0
  142. data/spec/{legacy_watirspec → watir2}/fixtures/prevent_form_submit.html +0 -0
  143. data/spec/{legacy_watirspec → watir2}/fixtures/right_click.html +0 -0
  144. data/spec/{legacy_watirspec → watir2}/fixtures/shift_jis_text.html +0 -0
  145. data/spec/{legacy_watirspec → watir2}/fixtures/tables.html +0 -0
  146. data/spec/{legacy_watirspec → watir2}/fixtures/timeout.html +0 -0
  147. data/spec/{legacy_watirspec → watir2}/fixtures/timeout_window_location.html +0 -0
  148. data/spec/{legacy_watirspec → watir2}/fixtures/tiny_mce.html +0 -0
  149. data/spec/{legacy_watirspec → watir2}/fixtures/utf8_text.html +0 -0
  150. data/spec/{legacy_watirspec → watir2}/fixtures/watirspec.css +0 -0
  151. data/spec/{legacy_watirspec → watir2}/form_spec.rb +0 -0
  152. data/spec/{legacy_watirspec → watir2}/forms_spec.rb +0 -0
  153. data/spec/{legacy_watirspec → watir2}/frame_spec.rb +0 -0
  154. data/spec/{legacy_watirspec → watir2}/frames_spec.rb +0 -0
  155. data/spec/{legacy_watirspec → watir2}/guards.rb +0 -0
  156. data/spec/{legacy_watirspec → watir2}/hidden_spec.rb +0 -0
  157. data/spec/{legacy_watirspec → watir2}/hiddens_spec.rb +0 -0
  158. data/spec/{legacy_watirspec → watir2}/hn_spec.rb +0 -0
  159. data/spec/{legacy_watirspec → watir2}/hns_spec.rb +0 -0
  160. data/spec/{legacy_watirspec → watir2}/image_spec.rb +0 -0
  161. data/spec/{legacy_watirspec → watir2}/images_spec.rb +0 -0
  162. data/spec/{legacy_watirspec → watir2}/ins_spec.rb +0 -0
  163. data/spec/{legacy_watirspec → watir2}/inses_spec.rb +0 -0
  164. data/spec/{legacy_watirspec → watir2}/label_spec.rb +0 -0
  165. data/spec/{legacy_watirspec → watir2}/labels_spec.rb +0 -0
  166. data/spec/{legacy_watirspec → watir2}/li_spec.rb +0 -0
  167. data/spec/{legacy_watirspec → watir2}/link_spec.rb +0 -0
  168. data/spec/{legacy_watirspec → watir2}/links_spec.rb +0 -0
  169. data/spec/{legacy_watirspec → watir2}/lis_spec.rb +0 -0
  170. data/spec/{legacy_watirspec → watir2}/map_spec.rb +0 -0
  171. data/spec/{legacy_watirspec → watir2}/maps_spec.rb +0 -0
  172. data/spec/{legacy_watirspec → watir2}/meta_spec.rb +0 -0
  173. data/spec/{legacy_watirspec → watir2}/metas_spec.rb +0 -0
  174. data/spec/{legacy_watirspec → watir2}/ol_spec.rb +0 -0
  175. data/spec/{legacy_watirspec → watir2}/ols_spec.rb +0 -0
  176. data/spec/{legacy_watirspec → watir2}/option_spec.rb +0 -0
  177. data/spec/{legacy_watirspec → watir2}/p_spec.rb +0 -0
  178. data/spec/{legacy_watirspec → watir2}/pre_spec.rb +0 -0
  179. data/spec/{legacy_watirspec → watir2}/pres_spec.rb +0 -0
  180. data/spec/{legacy_watirspec → watir2}/ps_spec.rb +0 -0
  181. data/spec/{legacy_watirspec → watir2}/radio_spec.rb +0 -0
  182. data/spec/{legacy_watirspec → watir2}/radios_spec.rb +0 -0
  183. data/spec/{legacy_watirspec → watir2}/select_list_spec.rb +84 -71
  184. data/spec/{legacy_watirspec → watir2}/select_lists_spec.rb +0 -0
  185. data/spec/{new_watirspec → watir2}/server.rb +0 -0
  186. data/spec/{legacy_watirspec → watir2}/span_spec.rb +0 -0
  187. data/spec/{legacy_watirspec → watir2}/spans_spec.rb +0 -0
  188. data/spec/{legacy_watirspec → watir2}/spec_helper.rb +0 -0
  189. data/spec/{legacy_watirspec → watir2}/strong_spec.rb +0 -0
  190. data/spec/{legacy_watirspec → watir2}/strongs_spec.rb +0 -0
  191. data/spec/{legacy_watirspec → watir2}/table_bodies_spec.rb +0 -0
  192. data/spec/{legacy_watirspec → watir2}/table_body_spec.rb +0 -0
  193. data/spec/{legacy_watirspec → watir2}/table_cell_spec.rb +0 -0
  194. data/spec/{legacy_watirspec → watir2}/table_cells_spec.rb +0 -0
  195. data/spec/{legacy_watirspec → watir2}/table_footer_spec.rb +0 -0
  196. data/spec/{legacy_watirspec → watir2}/table_footers_spec.rb +0 -0
  197. data/spec/{legacy_watirspec → watir2}/table_header_spec.rb +0 -0
  198. data/spec/{legacy_watirspec → watir2}/table_headers_spec.rb +0 -0
  199. data/spec/{legacy_watirspec → watir2}/table_row_spec.rb +0 -0
  200. data/spec/{legacy_watirspec → watir2}/table_rows_spec.rb +0 -0
  201. data/spec/{legacy_watirspec → watir2}/table_spec.rb +0 -0
  202. data/spec/{legacy_watirspec → watir2}/tables_spec.rb +0 -0
  203. data/spec/{legacy_watirspec → watir2}/text_field_spec.rb +0 -0
  204. data/spec/{legacy_watirspec → watir2}/text_fields_spec.rb +0 -0
  205. data/spec/{legacy_watirspec → watir2}/ul_spec.rb +0 -0
  206. data/spec/{legacy_watirspec → watir2}/uls_spec.rb +0 -0
  207. data/spec/{legacy_watirspec → watir2}/watir_compatibility_spec.rb +0 -0
  208. data/spec/{legacy_watirspec → watir2}/watirspec_helper.rb +0 -0
  209. data/spec/{new_watirspec → watir3}/browser_spec.rb +11 -21
  210. data/spec/{new_watirspec → watir3}/clipboard_spec.rb +2 -2
  211. data/spec/{new_watirspec → watir3}/collection_spec.rb +0 -0
  212. data/spec/{new_watirspec → watir3}/element_spec.rb +30 -12
  213. data/spec/watir3/guards.rb +39 -0
  214. data/spec/{new_watirspec → watir3}/keys_spec.rb +0 -0
  215. data/spec/watir3/server.rb +91 -0
  216. data/spec/{new_watirspec → watir3}/watirspec_helper.rb +0 -0
  217. data/spec/{new_watirspec → watir3}/window_spec.rb +8 -83
  218. metadata +315 -280
  219. data/lib/operadriver/selenium-common.jar +0 -0
  220. data/spec/legacy_watirspec/element_spec.rb +0 -86
  221. data/spec/new_watirspec/preferences_spec.rb +0 -144
  222. data/spec/new_watirspec/screenshot_spec.rb +0 -34
Binary file
data/lib/operawatir.rb CHANGED
@@ -4,7 +4,7 @@ require 'deprecated'
4
4
  require 'java'
5
5
  include Java
6
6
 
7
- %w(commons-jxpath-1.3.jar protobuf-java-2.3.0.jar selenium-common.jar
7
+ %w(commons-jxpath-1.3.jar protobuf-java-2.3.0.jar client-combined-nodeps.jar
8
8
  webdriver-opera.jar commons-io-2.0.1.jar).each { |jar| require "operadriver/#{jar}" }
9
9
 
10
10
  include_class org.openqa.selenium.WebDriver
@@ -22,6 +22,12 @@ include_class com.opera.core.systems.QuickWidget
22
22
 
23
23
  $KCODE = 'u' # UTF-8 support
24
24
 
25
+ class Object
26
+ def truthy?
27
+ self && [true, 'true', 'yes', 'y', '1', 1].include?(self)
28
+ end
29
+ end
30
+
25
31
  # TODO This should be replaced when we decide upon a better way of
26
32
  # enabling the Watir 3 API.
27
33
  module OperaWatir
@@ -47,6 +53,7 @@ end
47
53
  require 'operawatir/version'
48
54
  require 'operawatir/platform'
49
55
  require 'operawatir/keys'
56
+ require 'operawatir/screenshot'
50
57
  require 'operawatir/preferences'
51
58
  require 'operawatir/spatnav'
52
59
 
@@ -67,21 +67,13 @@ class OperaWatir::Browser
67
67
  driver.getVersion
68
68
  end
69
69
 
70
- # Get process identifier for spawned Opera browser instance. This
71
- # will only work if instance was started through OperaWatir.
72
- #
73
- # @return [Integer] The process ID of the browser instance.
74
- def pid
75
- driver.getPid
76
- end
77
-
78
70
  # Get the target device's platform. This is not equivalent of the
79
71
  # platform the OperaWatir server might be running on.
80
72
  #
81
73
  # @return [String] Operating system flavour of the device we're
82
74
  # testing on.
83
75
  def platform
84
- driver.getPlatform
76
+ window.execute_script('navigator.platform')
85
77
  end
86
78
 
87
79
  # Get the full path to the attached browser binary.
@@ -95,7 +87,7 @@ class OperaWatir::Browser
95
87
  #
96
88
  # @return [String] User agent string.
97
89
  def ua_string
98
- driver.getUaString
90
+ window.execute_script('navigator.userAgent')
99
91
  end
100
92
 
101
93
  # Is attached browser instance of type internal build or public
@@ -112,7 +104,7 @@ class OperaWatir::Browser
112
104
  # @param [String] Name of the action.
113
105
  # @return [String] Optional return from the performed action.
114
106
  def opera_action(name, *args)
115
- driver.operaAction(name, param.to_java(:string))
107
+ driver.operaAction(name, args.to_java(:string))
116
108
  end
117
109
  deprecated :opera_action
118
110
 
@@ -132,7 +124,6 @@ class OperaWatir::Browser
132
124
  # to pressing C-a in a desktop browser. To select content in a
133
125
  # <textarea> or an <input> field, remember to click it first.
134
126
  def select_all
135
-
136
127
  # FIXME
137
128
  driver.operaAction('Select all')
138
129
  end
@@ -177,14 +168,43 @@ class OperaWatir::Browser
177
168
  end
178
169
  end
179
170
 
171
+
172
+ # Keyboard
173
+
174
+ def key(key)
175
+ driver.key(key)
176
+ end
177
+
178
+ deprecated :key, 'browser.keys.send'
179
+
180
+ def key_down(key)
181
+ driver.keyDown(key)
182
+ end
183
+
184
+ deprecated :key, 'browser.keys.down'
185
+
186
+ def key_up(key)
187
+ driver.keyUp(key)
188
+ end
189
+
190
+ deprecated :key, 'browser.keys.up or browser.keys.release'
191
+
192
+ def type(text)
193
+ driver.type(text)
194
+ end
195
+
196
+ deprecated :key, 'browser.keys.send'
197
+
180
198
  private
181
199
 
182
200
  def self.opera_driver_settings
183
- @opera_driver_settings ||= OperaDriverSettings.new.tap {|s|
184
- s.setRunOperaLauncherFromOperaDriver true
201
+ @opera_driver_settings ||= OperaDriverSettings.new.tap { |s|
202
+ s.setAutostart false if self.settings[:manual]
185
203
  s.setOperaLauncherBinary self.settings[:launcher] if self.settings[:launcher]
186
204
  s.setOperaBinaryLocation self.settings[:path] if self.settings[:path]
187
- s.setOperaBinaryArguments self.settings[:args].to_s + ' opera:debug' #+ ' -watirtest'
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?
188
208
  }
189
209
  end
190
210
 
@@ -51,7 +51,7 @@ class OperaWatir::Collection
51
51
  # Public interface to elms, used in Selector
52
52
  def raw_elements
53
53
  _elms.tap do |e|
54
- raise(OperaWatir::Exceptions::UnknownObjectException) if e.empty?
54
+ #raise(OperaWatir::Exceptions::UnknownObjectException) if e.empty?
55
55
  end
56
56
  end
57
57
 
@@ -63,7 +63,7 @@ class OperaWatir::Collection
63
63
  end
64
64
 
65
65
  def attr(name)
66
- raw_elements[0].attr(name)
66
+ raw_elements.first.attr(name)
67
67
  end
68
68
 
69
69
  def attrs(name)
@@ -2,7 +2,7 @@ module OperaWatir
2
2
 
3
3
  module Compat; end
4
4
 
5
- # Switches on compatibility layer (Watir 1 API).
5
+ # Switches on compatibility layer (Watir 2 API).
6
6
  def self.compatibility!
7
7
  require 'operawatir/compat/browser'
8
8
  require 'operawatir/compat/element_finders'
@@ -16,7 +16,8 @@ module OperaWatir
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.
19
-
19
+
20
+ require 'operawatir/compat/selector'
20
21
  require 'operawatir/compat/collection'
21
22
  require 'operawatir/compat/element'
22
23
  end
@@ -11,11 +11,6 @@ module OperaWatir
11
11
  end
12
12
  end
13
13
 
14
- # Quits the browser
15
- def quit
16
- browser.quit!
17
- end
18
-
19
14
  # Class#type is defined by Ruby, it will never reach
20
15
  # #method_missing.
21
16
  def_delegator :active_window, :type
@@ -79,6 +79,10 @@ class OperaWatir::Collection
79
79
  define_method(name) {method_missing(name)}
80
80
  end
81
81
 
82
+ =begin
83
+ This only applies to Watir 1. #to_s is in Watir 2 treated the same
84
+ way as Object#to_s (which will give you a Collection instance).
85
+
82
86
  # Fetches the string representation of this collection.
83
87
  #
84
88
  # @return [String] the string representation of this collection
@@ -95,6 +99,15 @@ class OperaWatir::Collection
95
99
  " text: #{el.text}"
96
100
  end.join("\n")
97
101
  end
102
+ =end
103
+
104
+ def select(option_text)
105
+ option(:text => option_text).node.setSelected
106
+ end
107
+
108
+ def selected?(option_text)
109
+ option(:text => option_text).node.isSelected
110
+ end
98
111
 
99
112
  private
100
113
 
@@ -102,4 +115,6 @@ private
102
115
  blk.call(raw_elements.first)
103
116
  end
104
117
 
118
+ alias_method :find_elements_by_selector, :find_elements_by_css
119
+
105
120
  end
@@ -1,17 +1,24 @@
1
1
  class OperaWatir::Element
2
+ include Deprecated
2
3
 
4
+ #
3
5
  # Gets the attribute called name.
4
6
  #
5
- # @param [String, Symbol] name The name of the attribute to get
6
- # @return [String] The value of the attribute
7
+ # @param [String, Symbol] name The name of the attribute to get.
8
+ # @return [String] The value of the attribute.
9
+ #
10
+
7
11
  def attr(name)
8
12
  node.getAttribute(name.to_s) || ''
9
13
  end
10
14
 
15
+ #
11
16
  # Check the existence of the attribute on the element.
12
17
  #
13
- # @return [Boolean] true if the attribute exists on the element,
14
- # false otherwise
18
+ # @return [Boolean] True if the attribute exists on the element,
19
+ # false otherwise.
20
+ #
21
+
15
22
  def attr?(name)
16
23
  !node.getAttribute(name.to_s).nil?
17
24
  end
@@ -24,24 +31,32 @@ class OperaWatir::Element
24
31
  end
25
32
  end
26
33
 
34
+ #
27
35
  # Gets the text content of the element.
28
36
  #
29
- # @return [String] the text content
37
+ # @return [String] The text content.
38
+ #
39
+
30
40
  def text
31
- node.getText.strip
41
+ if node.tag_name =~ /input|textarea|select/i
42
+ node.value.strip
43
+ else
44
+ node.getText.strip
45
+ end
32
46
  end
33
47
 
34
- alias_method :to_s, :text
35
-
48
+ #
36
49
  # Checks whether the text content of the element contains the given
37
50
  # string In the compatibility layer as the preferred way of doing
38
51
  # this is.
39
52
  #
40
53
  # elm.text.should include('My string')
41
54
  #
42
- # @param [String] String to search for
43
- # @param [Boolean] true if the element's text contains str, false
44
- # otherwise
55
+ # @param [String] String to search for.
56
+ # @param [Boolean] True if the element's text contains str, false
57
+ # otherwise.
58
+ #
59
+
45
60
  def verify_contains(str)
46
61
  text.include?(str)
47
62
  end
@@ -50,11 +65,15 @@ class OperaWatir::Element
50
65
 
51
66
  alias_method :caption, :text
52
67
 
68
+ #
53
69
  # Clicks on the top left of the element, or the given x, y offset.
70
+ # Asserts whether element is enabled first.
54
71
  #
55
72
  # @param [optional, Fixnum] x The offset from the left of the
56
73
  # element
57
74
  # @param [optional, Fixnum] y The offset from the top of the element
75
+ #
76
+
58
77
  def click(x=0, y=0)
59
78
  assert_enabled!
60
79
  node.click(x.to_i, y.to_i)
@@ -62,27 +81,40 @@ class OperaWatir::Element
62
81
 
63
82
  alias_method :click_no_wait, :click_async
64
83
 
84
+ #
65
85
  # Focuses the element
86
+ #
87
+
66
88
  def focus
67
89
  fire_event :focus
68
90
  end
69
91
 
92
+ #
70
93
  # Submits a form, or the form the elment is contained in.
94
+ #
95
+
71
96
  def submit
72
97
  assert_exists
73
98
  node.submit
74
99
  end
75
100
 
101
+ #
76
102
  # Clears a text input or textarea of any text.
103
+ #
104
+
77
105
  def clear
78
106
  assert_enabled!
79
- uncheck!
107
+ click
108
+ node.clear
80
109
  end
81
110
 
111
+ #
82
112
  # If passed a value it will type text into the element, otherwise it
83
113
  # will check a radio button or checkbox.
84
114
  #
85
- # @param [optional, String] value Text to type
115
+ # @param [String] value (Optional.) Text to type.
116
+ #
117
+
86
118
  def set(value=nil)
87
119
  if value
88
120
  self.text = value
@@ -92,31 +124,40 @@ class OperaWatir::Element
92
124
  end
93
125
  end
94
126
 
127
+ #
95
128
  # Gets the href of an `<a>` element, or the url attribute of any
96
129
  # other element.
97
130
  #
98
- # @return [String] an href or the url attribute
131
+ # @return [String] An href or the @url attribute.
132
+ #
133
+
99
134
  def url
100
135
  attr(tag_name == 'A' ? :href : :url)
101
136
  end
102
137
 
138
+ #
103
139
  # Gets the selected `<option>` elements in a `<select>` element.
104
140
  #
105
- # @return [OperaWatir::Collection] a collection of the selected
106
- # `<option>`s
141
+ # @return [Collection] a collection of the selected
142
+ # `<option>`s
143
+ #
144
+
107
145
  def selected_options
108
146
  options(:selected?, true)
109
147
  end
110
148
 
149
+ #
111
150
  # On checkboxes, radio buttons, and option elements returns whether
112
151
  # the element is checked/selected. On a select element, when passed
113
152
  # an value it checks whether the selected option contains the given
114
153
  # text.
115
154
  #
116
- # @param [optional, String] value Text the selected option should
117
- # contain
118
- # @return [Boolean] true if the element is selected/selected option
119
- # contains value, false otherwise
155
+ # @param [String] value (Optional.) Text the selected option should
156
+ # contain.
157
+ # @return [Boolean] True if the element is selected/selected
158
+ # option contains value, false otherwise.
159
+ #
160
+
120
161
  def selected?(value=nil)
121
162
  if option.nil?
122
163
  selected_options.text.include?(value)
@@ -127,10 +168,13 @@ class OperaWatir::Element
127
168
 
128
169
  alias_method :set?, :checked?
129
170
 
171
+ #
130
172
  # For `<select>` elements returns either 'select-one' for
131
173
  # `<select>`s where only a single `<option>` can be selected, or
132
174
  # 'select-multiple' otherwise. For non-`<select>` elements returns
133
175
  # the `type` attribute.
176
+ #
177
+
134
178
  def type
135
179
  if tag_name == 'SELECT'
136
180
  attr(:multiple) == 'multiple' ? 'select-multiple' : 'select-one'
@@ -139,9 +183,12 @@ class OperaWatir::Element
139
183
  end
140
184
  end
141
185
 
186
+ #
142
187
  # Gets the colspan attribute as an integer.
143
188
  #
144
- # @return [Fixnum] the colspan
189
+ # @return [Fixnum] The colspan.
190
+ #
191
+
145
192
  def colspan
146
193
  attr(:colspan).to_i
147
194
  end
@@ -151,6 +198,10 @@ class OperaWatir::Element
151
198
  def compare_hash(other)
152
199
  visual_hash == other.visual_hash
153
200
  end
201
+ deprecated :compare_hash, 'element.visual_hash'
202
+
203
+ alias_method :get_hash, :visual_hash
204
+ deprecated :get_hash, 'element.visual_hash'
154
205
 
155
206
  private
156
207
 
@@ -52,6 +52,10 @@ module OperaWatir::Compat::ElementFinders
52
52
 
53
53
  def_element :dt, :dts
54
54
 
55
+ def_element :element, :elements do |selector|
56
+ selector.xpath '//*'
57
+ end
58
+
55
59
  def_element :em, :ems
56
60
 
57
61
  def_element :file_field, :file_fields, :how => :name do |selector|
@@ -76,6 +80,8 @@ module OperaWatir::Compat::ElementFinders
76
80
 
77
81
  def_element :h6, :h6s
78
82
 
83
+ def_element :iframe, :iframes
84
+
79
85
  def_element :image, :images, :how => :src do |selector|
80
86
  selector.tag :img
81
87
  end
@@ -0,0 +1,7 @@
1
+ class OperaWatir::Selector
2
+ include Deprecated
3
+
4
+ BASE_TYPES << :selector
5
+ alias_method :selector, :css
6
+ deprecated :selector, "element(:css, 'foo')"
7
+ end