operawatir 0.3.2-jruby → 0.3.7.pre1-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 (53) hide show
  1. data/.gitmodules +3 -0
  2. data/.yardopts +0 -3
  3. data/Gemfile +5 -6
  4. data/Rakefile +7 -2
  5. data/VERSION +1 -1
  6. data/bin/desktopwatir +86 -93
  7. data/bin/operawatir +3 -18
  8. data/lib/operadriver/commons-io-2.0.1.jar +0 -0
  9. data/lib/operadriver/selenium-common.jar +0 -0
  10. data/lib/operadriver/webdriver-opera.jar +0 -0
  11. data/lib/operawatir/browser.rb +93 -77
  12. data/lib/operawatir/compat/browser.rb +5 -0
  13. data/lib/operawatir/compat/element.rb +10 -17
  14. data/lib/operawatir/compat.rb +0 -1
  15. data/lib/operawatir/desktop-waiter.rb +1 -143
  16. data/lib/operawatir/desktop_browser.rb +80 -33
  17. data/lib/operawatir/desktop_enums.rb +3 -3
  18. data/lib/operawatir/desktop_helper.rb +84 -0
  19. data/lib/operawatir/element.rb +23 -4
  20. data/lib/operawatir/exceptions.rb +3 -0
  21. data/lib/operawatir/helper.rb +4 -1
  22. data/lib/operawatir/platform.rb +0 -38
  23. data/lib/operawatir/preferences.rb +164 -0
  24. data/lib/operawatir/quickwidgets/quick_addressfield.rb +14 -0
  25. data/lib/operawatir/quickwidgets/quick_button.rb +7 -1
  26. data/lib/operawatir/quickwidgets/quick_checkbox.rb +5 -4
  27. data/lib/operawatir/quickwidgets/quick_dialogtab.rb +1 -1
  28. data/lib/operawatir/quickwidgets/quick_editfield.rb +9 -4
  29. data/lib/operawatir/quickwidgets/quick_thumbnail.rb +1 -1
  30. data/lib/operawatir/quickwidgets/quick_treeitem.rb +2 -2
  31. data/lib/operawatir/quickwidgets/quick_treeview.rb +2 -1
  32. data/lib/operawatir/quickwidgets/quick_widget.rb +51 -21
  33. data/lib/operawatir/quickwidgets/quick_window.rb +34 -19
  34. data/lib/operawatir/spatnav.rb +38 -0
  35. data/lib/operawatir/window.rb +76 -12
  36. data/lib/operawatir.rb +20 -4
  37. data/operawatir.gemspec +48 -28
  38. data/spec/new_watirspec/browser_spec.rb +5 -84
  39. data/spec/new_watirspec/clipboard_spec.rb +41 -56
  40. data/spec/new_watirspec/collection_spec.rb +2 -2
  41. data/spec/new_watirspec/element_spec.rb +8 -8
  42. data/spec/new_watirspec/keys_spec.rb +8 -10
  43. data/spec/new_watirspec/preferences_spec.rb +144 -0
  44. data/spec/new_watirspec/screenshot_spec.rb +34 -0
  45. data/spec/new_watirspec/spatnav_spec.rb +62 -0
  46. data/utils/formatters/operahelper_formatter.rb +50 -0
  47. data/utils/formatters/spartan_formatter.rb +29 -0
  48. metadata +126 -61
  49. data/lib/operawatir/compat/deprecation.rb +0 -46
  50. data/utils/launchers/launcher-linux-i686 +0 -0
  51. data/utils/launchers/launcher-linux-x86_64 +0 -0
  52. data/utils/launchers/launcher-mac +0 -0
  53. data/utils/launchers/launcher-win32-i86pc.exe +0 -0
@@ -1,144 +1,2 @@
1
1
  # -*- coding: utf-8 -*-
2
-
3
- require 'rspec'
4
- require 'rbconfig'
5
- require 'ostruct'
6
-
7
- class Object
8
- def truthy?
9
-
10
- # FIXME: Should we not check for truthfulness instead, and presume
11
- # that anything else passed to be false? Below we are doing the
12
- # opposite.
13
- #self && !['false', 'no', 'n', '0', 0].include?(self)
14
-
15
- self && [true, 'true', 'yes', 'y', '1', 1].include?(self)
16
- end
17
- end
18
-
19
-
20
- module OperaWatir::Waiter
21
- extend self
22
-
23
- def self.default_attr_accessor(attr, default)
24
- define_method attr.to_sym do
25
- default || instance_variable_get("@#{attr}") || ENV["OPERA_#{attr.to_s.upcase}"]
26
- end
27
- attr_writer attr.to_sym
28
- end
29
-
30
- def defaults
31
- configure do |c|
32
- c.path = nil
33
- c.args = ''
34
- c.files = "file://localhost/#{File.expand_path('interactive', File.dirname(RSpec.configuration.files_to_run[0]))}"
35
- c.inspectr = false
36
- c.terminal_size = [80,24]
37
- end
38
- end
39
-
40
- def configure(*args, &block)
41
- HelperConfig.block_to_hash(block).each do |setting, value|
42
- default_attr_accessor setting, value
43
- end
44
- end
45
-
46
- class HelperConfig < OpenStruct
47
- def self.block_to_hash(block=nil)
48
- config = self.new
49
- if block
50
- block.call(config)
51
- config.to_hash
52
- else
53
- {}
54
- end
55
- end
56
-
57
- def to_hash
58
- @table
59
- end
60
- end
61
-
62
- defaults
63
-
64
- def browser
65
- @browser ||= OperaWatir::DesktopBrowser.new(path, *args.split(' ').to_java(:string))
66
- end
67
-
68
- def helper_file
69
- File.expand_path(File.join(Dir.pwd, 'helper.rb'))
70
- end
71
-
72
- def configure_rspec
73
- RSpec.configure do |config|
74
- config.include SpecHelpers
75
-
76
- config.after(:suite) do
77
- # Only exit if the envrionment variable is set
78
- if ENV["OPERA_PATH"].to_s.length > 0
79
- OperaWatir::Waiter.browser.quit
80
- else
81
- # Just shutsdown the driver
82
- OperaWatir::Waiter.browser.quit_driver
83
- end
84
- end
85
- config.before(:all) do
86
- #set_prefs
87
- end
88
- config.after(:all) do
89
- #delete_prefs
90
- end
91
- end
92
- end
93
-
94
- def inspectr_path
95
- File.join File.expand_path('../../../utils', __FILE__),
96
- (Config::CONFIG['host_os'] =~ /mswin|msys|mingw32/ ? 'inspectr.exe' : 'inspectr')
97
- end
98
-
99
- def spawn_inspectr
100
- abort 'operawatir: inspectr is not supported on your operating system' unless Config::CONFIG['host_os'] =~ /linux/
101
- abort 'operawatir: Unable to locate inspectr executable' unless File.exist?(inspectr_path)
102
-
103
- Thread.new do
104
- puts "Attaching inspectr to PID ##{browser.pid}"
105
- exec inspectr_path, browser.pid.to_s
106
- end
107
- end
108
-
109
- def run!
110
- require helper_file if File.exist?(helper_file)
111
- spawn_inspectr if inspectr.truthy?
112
- configure_rspec
113
- RSpec::Core::Runner.autorun
114
- end
115
-
116
-
117
- # Helpers included for each Spec
118
-
119
- module SpecHelpers
120
- def browser
121
- OperaWatir::Waiter.browser
122
- end
123
-
124
- # TODO Not sure of this
125
- def files(new_path=nil)
126
- if new_path
127
- OperaWatir::Waiter.files = new_path
128
- else
129
- OperaWatir::Waiter.files
130
- end
131
- end
132
- alias_method :files=, :files
133
- end
134
- end
135
-
136
- # Overriding trapping in RSpec.
137
- module RSpec
138
- module Core
139
- class Runner
140
- def self.trap_interrupt; end
141
- end
142
- end
143
- end
144
-
2
+ require 'operawatir/desktop_helper'
@@ -8,12 +8,11 @@ module OperaWatir
8
8
  "Open url in new window"]
9
9
 
10
10
  # @private
11
- def initialize (executable_location = nil, *arguments)
12
- if executable_location.nil? or executable_location.length == 0
13
- @driver = OperaDesktopDriver.new
14
- else
15
- @driver = OperaDesktopDriver.new(executable_location, arguments.to_java(:String))
16
- end
11
+ def initialize
12
+ OperaWatir.compatibility! unless OperaWatir.api >= 2
13
+
14
+ self.driver = OperaDesktopDriver.new(self.class.opera_driver_settings)
15
+ self.active_window = OperaWatir::Window.new(self)
17
16
  end
18
17
 
19
18
  # @private
@@ -21,15 +20,30 @@ module OperaWatir
21
20
  # dialogs to autoclose in Dialog.cpp when then OnUrlChanged is fired
22
21
  # after a dialog is opened
23
22
  def goto(url = "")
24
- super
23
+ super #active_window.url = url
25
24
  sleep(1)
26
25
  end
27
26
 
27
+ ######################################################################
28
+ # Quits Opera
29
+ #
30
+ def quit_opera
31
+ driver.quitOpera
32
+ end
33
+
34
+ ######################################################################
35
+ # Restarts Opera
36
+ #
37
+ def restart
38
+ driver.quitOpera
39
+ driver.startOpera
40
+ end
41
+
28
42
  ######################################################################
29
43
  # Quits the driver without exiting Opera
30
44
  #
31
- def quit_driver()
32
- @driver.shutdown
45
+ def quit_driver
46
+ driver.quitDriver
33
47
  end
34
48
 
35
49
  ######################################################################
@@ -226,7 +240,7 @@ module OperaWatir
226
240
  # @return [Array] Array of widgets retrieved from the window
227
241
  #
228
242
  def widgets(win_name)
229
- @driver.getQuickWidgetList(win_name).map do |java_widget|
243
+ driver.getQuickWidgetList(win_name).map do |java_widget|
230
244
  case java_widget.getType
231
245
  when QuickWidget::WIDGET_ENUM_MAP[:button]
232
246
  QuickButton.new(self,java_widget)
@@ -254,13 +268,15 @@ module OperaWatir
254
268
  end.to_a
255
269
  end
256
270
 
271
+ alias_method :quick_widgets, :widgets
272
+
257
273
  ####################################################
258
274
  # Retrieves an array of all windows
259
275
  #
260
276
  # @return [Array] Array of windows
261
277
  #
262
- def windows
263
- @driver.getWindowList.map do |java_window|
278
+ def quick_windows
279
+ driver.getQuickWindowList.map do |java_window|
264
280
  QuickWindow.new(self,java_window)
265
281
  end.to_a
266
282
  end
@@ -268,7 +284,7 @@ module OperaWatir
268
284
  #@private
269
285
  # Retrieve all tabs
270
286
  def open_pages
271
- windows.select { |win| win.name == "Document Window" }
287
+ quick_windows.select { |win| win.name == "Document Window" }
272
288
  end
273
289
 
274
290
  #@private
@@ -304,8 +320,8 @@ module OperaWatir
304
320
  #
305
321
  # @return [String] Name of the window
306
322
  #
307
- def get_window_name(win_id)
308
- @driver.getWindowName(win_id)
323
+ def window_name(win_id)
324
+ driver.getQuickWindowName(win_id)
309
325
  end
310
326
 
311
327
  ######################################################################
@@ -352,8 +368,8 @@ module OperaWatir
352
368
  #
353
369
  # @return [String] Full path to the opera executable
354
370
  #
355
- def get_opera_path
356
- @driver.getOperaPath()
371
+ def path
372
+ driver.getOperaPath()
357
373
  end
358
374
 
359
375
  ######################################################################
@@ -361,8 +377,8 @@ module OperaWatir
361
377
  #
362
378
  # @return [String] Full path to the large preferences folder
363
379
  #
364
- def get_large_preferences_path
365
- @driver.getLargePreferencesPath()
380
+ def large_preferences_path
381
+ driver.getLargePreferencesPath()
366
382
  end
367
383
 
368
384
  ######################################################################
@@ -370,8 +386,8 @@ module OperaWatir
370
386
  #
371
387
  # @return [String] Full path to the small preferences folder
372
388
  #
373
- def get_small_preferences_path
374
- @driver.getSmallPreferencesPath()
389
+ def small_preferences_path
390
+ driver.getSmallPreferencesPath()
375
391
  end
376
392
 
377
393
  ######################################################################
@@ -379,8 +395,8 @@ module OperaWatir
379
395
  #
380
396
  # @return [String] Full path to the cache preferences folder
381
397
  #
382
- def get_cache_preferences_path
383
- @driver.getCachePreferencesPath()
398
+ def cache_preferences_path
399
+ driver.getCachePreferencesPath()
384
400
  end
385
401
 
386
402
  ######################################################################
@@ -392,6 +408,11 @@ module OperaWatir
392
408
  Config::CONFIG['target_os'] == "darwin"
393
409
  end
394
410
 
411
+ ######################################################################
412
+ # Returns true if the test is running on Linux
413
+ #
414
+ # @return [Boolean] true we the operating system is Linux, otherwise false
415
+ #
395
416
  def linux?
396
417
  Config::CONFIG['target_os'] == "linux"
397
418
  end
@@ -469,13 +490,13 @@ module OperaWatir
469
490
  # Close all open dialogs
470
491
  #
471
492
  def close_all_dialogs
472
- win_id = driver.getActiveWindowID()
493
+ win_id = driver.getActiveQuickWindowID()
473
494
  until quick_window(:id, win_id).type != :dialog do
474
- win = quick_window(:id, driver.getActiveWindowID())
495
+ win = quick_window(:id, driver.getActiveQuickWindowID())
475
496
  if win.type == :dialog
476
497
  close_dialog(win.name)
477
- if (driver.getActiveWindowID() != win_id)
478
- win_id = driver.getActiveWindowID()
498
+ if (driver.getActiveQuickWindowID() != win_id)
499
+ win_id = driver.getActiveQuickWindowID()
479
500
  else
480
501
  break
481
502
  end
@@ -483,14 +504,40 @@ module OperaWatir
483
504
  end
484
505
  end
485
506
 
507
+ ############################################################################
508
+ #
509
+ # Reset prefs
510
+ #
511
+ # Quits Opera and copies prefs from src to dest, then restarts Opera with the
512
+ # new Prefs
513
+ #
514
+ def reset_prefs(new_prefs)
515
+ driver.resetOperaPrefs(new_prefs)
516
+ end
517
+
518
+ ##############################################################################
519
+ #
520
+ # Deletes profile for the connected Opera instance.
521
+ # Should only be called after quitting (and before starting) Opera.
522
+ #
523
+ #
524
+ def delete_profile
525
+ driver.deleteOperaPrefs
526
+ end
486
527
 
487
- =begin
488
- TODO:
489
- def delete_cookies
490
- def reset_main_window
491
- =end
492
-
493
528
  private
529
+
530
+ def self.opera_driver_settings
531
+ @opera_driver_settings ||= OperaDriverSettings.new.tap {|s|
532
+ s.setRunOperaLauncherFromOperaDriver true
533
+ s.setOperaLauncherBinary self.settings[:launcher]
534
+ s.setOperaBinaryLocation self.settings[:path]
535
+ s.setOperaBinaryArguments self.settings[:args] + ' -watirtest'
536
+ s.setNoQuit self.settings[:no_quit]
537
+ s.setNoRestart self.settings[:no_restart]
538
+ }
539
+ end
540
+
494
541
  # Gets the parent widget name of which there is none here
495
542
  def parent_widget
496
543
  nil
@@ -17,24 +17,24 @@ module OperaWatir
17
17
 
18
18
  # Enum for the widget types
19
19
  WIDGET_ENUM_MAP = DesktopWmProtos::QuickWidgetInfo::QuickWidgetType.constants.inject({}) do |acc, const|
20
- #puts const.inspect
21
20
  acc[const.to_s.downcase.to_sym] = DesktopWmProtos::QuickWidgetInfo::QuickWidgetType.const_get(const)
22
21
  acc
23
22
  end
24
23
 
24
+ # Enum for window types
25
25
  WINDOW_ENUM_MAP = DesktopWmProtos::DesktopWindowInfo::DesktopWindowType.constants.inject({}) do |acc, const|
26
- #puts const.inspect
27
26
  acc[const.to_s.downcase.to_sym] = DesktopWmProtos::DesktopWindowInfo::DesktopWindowType.const_get(const)
28
27
  acc
29
28
  end
30
29
 
30
+ # Enum for search types
31
31
  WIDGET_SEARCHTYPE_ENUM_MAP = DesktopWmProtos::QuickWidgetSearch::QuickWidgetSearchType.constants.inject({}) do |acc, const|
32
32
  acc[const.to_s.downcase.to_sym] = DesktopWmProtos::QuickWidgetSearch::QuickWidgetSearchType.const_get(const)
33
33
  acc
34
34
  end
35
35
 
36
+ # Enum for drop position types for dropping a widget onto another
36
37
  DROPPOSITION_ENUM_MAP = QuickWidget::DropPosition.constants.inject({}) do |acc, const|
37
- #puts const.inspect
38
38
  acc[const.to_s.downcase.to_sym] = QuickWidget::DropPosition.const_get(const)
39
39
  acc
40
40
  end
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # TODO
4
+ # You need to set the OPERA_LAUNCHER and OPERA_PATH environment variables
5
+ # for this Helper to work.
6
+
7
+ require 'operawatir'
8
+ require 'rspec'
9
+ require 'rbconfig'
10
+
11
+ module OperaWatir::DesktopHelper
12
+ extend self
13
+
14
+ def settings
15
+ OperaWatir::DesktopBrowser.settings
16
+ end
17
+
18
+ def browser
19
+ @browser ||= OperaWatir::DesktopBrowser.new
20
+ end
21
+
22
+ def configure_rspec!
23
+ RSpec.configure do |config|
24
+
25
+ # Set every RSpec option
26
+ settings.each do |key, value|
27
+ config.send("#{key}=", value) if config.respond_to?("#{key}=")
28
+ if key.to_s.eql?("files_to_run")
29
+ @@files = value
30
+ end
31
+ end
32
+
33
+ config.include SpecHelpers
34
+
35
+ config.before(:all) {
36
+ if OperaWatir::DesktopHelper::settings[:no_restart] == false
37
+ unless @@files.empty?
38
+ path = File.join(Dir.getwd, @@files.shift)
39
+ filepath = path.chomp(".rb")
40
+ browser.reset_prefs(filepath)
41
+ end
42
+ else
43
+ # Must create browser object here so that none of the
44
+ # test is run before Opera has been launched
45
+ browser
46
+ end
47
+ }
48
+
49
+ config.after(:suite) {
50
+ # Use the @browser directly because we don't want
51
+ # to launch Opera here if it's not running
52
+ if @browser
53
+
54
+ if settings[:no_quit] == false
55
+ # Shutdown Opera
56
+ @browser.quit_opera
57
+ @browser.delete_profile
58
+ end
59
+
60
+ # Shutdown the driver
61
+ @browser.quit_driver
62
+ end
63
+ }
64
+ end
65
+ end
66
+
67
+ def run!(settings={})
68
+ OperaWatir::DesktopBrowser.settings = settings
69
+ configure_rspec!
70
+ RSpec::Core::Runner.autorun
71
+ end
72
+
73
+ private
74
+
75
+ module SpecHelpers
76
+ def browser
77
+ OperaWatir::DesktopHelper.browser
78
+ end
79
+
80
+ def window
81
+ browser.active_window
82
+ end
83
+ end
84
+ end
@@ -68,10 +68,22 @@ class OperaWatir::Element
68
68
 
69
69
  alias_method :to_s, :text
70
70
 
71
- def_delegator :node, :getValue, :value
72
71
  def_delegator :node, :getElementName, :tag_name
73
72
  def_delegator :node, :clear, :clear
74
73
 
74
+ # On elements of type `input`, `textarea` or `select` it will fetch
75
+ # the texteditable `value` attribute, on every other element type it
76
+ # returns the DOM attribute `value`.
77
+ #
78
+ # @return [String] Value of the element.
79
+ def value
80
+ if tag_name =~ /input|textarea|select/i
81
+ node.getValue
82
+ else
83
+ attr :value
84
+ end
85
+ end
86
+
75
87
  def disabled?
76
88
  !enabled?
77
89
  end
@@ -91,7 +103,7 @@ class OperaWatir::Element
91
103
 
92
104
  # Events
93
105
 
94
- def click!(x=0, y=0)
106
+ def click(x=0, y=0)
95
107
  node.click(x.to_i, y.to_i)
96
108
  end
97
109
 
@@ -127,17 +139,18 @@ class OperaWatir::Element
127
139
 
128
140
  def text=(string)
129
141
  # Focus before typing
130
- node.click
142
+ clear unless value.empty?
131
143
  node.sendKeys(string.split('').to_java(:string))
132
144
  end
133
145
 
134
146
  alias_method :set, :text=
147
+ alias_method :value=, :text=
135
148
 
136
149
  def send_keys(*list)
137
150
  raise Exceptions::NotImplementedException
138
151
  end
139
152
 
140
- def trigger!(event, x = 0, y = 0)
153
+ def fire_event(event, x = 0, y = 0)
141
154
  loc = location
142
155
  x += loc[:x]
143
156
  y += loc[:y]
@@ -225,4 +238,10 @@ private
225
238
  end
226
239
  end
227
240
 
241
+ def find_elements_by_name(value)
242
+ node.findElementsByName(value).to_a.map do |n|
243
+ OperaWatir::Element.new(n)
244
+ end
245
+ end
246
+
228
247
  end
@@ -37,5 +37,8 @@ module OperaWatir::Exceptions
37
37
 
38
38
  # Raised when pressing a modifier key that doesn't exist.
39
39
  class InvalidKeyException < OperaWatirException; end
40
+
41
+ # Raised when an exception occurs in Preferences.
42
+ class PreferencesException < OperaWatirException; end
40
43
 
41
44
  end
@@ -29,7 +29,10 @@ module OperaWatir::Helper
29
29
 
30
30
  config.include SpecHelpers
31
31
 
32
- config.after(:suite) { browser.quit! if browser }
32
+ config.after(:suite) do
33
+ browser.quit if browser
34
+ exit
35
+ end
33
36
  end
34
37
  end
35
38
 
@@ -1,36 +1,6 @@
1
1
  require 'rbconfig'
2
2
 
3
3
  class OperaWatir::Platform
4
- def self.launcher
5
- return ENV['OPERA_LAUNCHER'] if ENV['OPERA_LAUNCHER']
6
-
7
- path = case os
8
- when :windows
9
- raise Exceptions::NotImplementedException, 'only 32-bit windows supported' if bitsize == 64
10
- 'utils/launchers/launcher-win32-i86pc.exe'
11
- when :linux
12
- postfix = bitsize == 64 ? 'x86_64' : 'i686'
13
- "utils/launchers/launcher-linux-#{postfix}"
14
- when :macosx
15
- 'utils/launchers/launcher-mac'
16
- end
17
-
18
- if path
19
- File.join(root, path)
20
- else
21
- raise Exceptions::NotImplementedException, "no known launcher for #{os.inspect}, set OPERA_LAUNCHER to override"
22
- end
23
-
24
- end
25
-
26
- def self.opera
27
- ENV['OPERA_PATH']
28
- end
29
-
30
- def self.args
31
- ENV['OPERA_ARGS'] || ''
32
- end
33
-
34
4
  def self.os
35
5
  @os ||= (
36
6
  host_os = RbConfig::CONFIG['host_os']
@@ -48,12 +18,4 @@ class OperaWatir::Platform
48
18
  end
49
19
  )
50
20
  end
51
-
52
- def self.bitsize
53
- ENV_JAVA['sun.arch.data.model'].to_i
54
- end
55
-
56
- def self.root
57
- @root ||= File.expand_path('../../..', __FILE__)
58
- end
59
21
  end