operawatir 0.3-jruby → 0.3.2-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 (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
data/Gemfile CHANGED
@@ -1,9 +1,13 @@
1
1
  source :rubygems
2
- #gemspec
3
2
 
4
3
  group :development do
5
4
  gem "bundler", "~> 1.0.0"
6
5
  gem "jeweler", "~> 1.5.1"
7
6
  gem "rcov", ">= 0"
7
+ gem "yard", ">= 0.6.3"
8
+ gem "bluecloth", "= 1.0.1"
9
+ gem "rspec", ">= 2.4"
10
+ gem "sinatra", ">= 1.0.0"
11
+ gem "mongrel", ">= 1.1.5"
12
+ gem "rr", ">= 1.0.2"
8
13
  end
9
-
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Opera Software ASA
1
+ Copyright (c) 2010-2011 Opera Software ASA
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/Rakefile CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'rake/clean'
3
3
  require 'jeweler'
4
4
  require 'rspec/core/rake_task'
5
- require 'yard/rake/yardoc_task'
5
+ require 'yard'
6
6
 
7
7
  require './lib/operawatir/version'
8
8
 
@@ -26,11 +26,12 @@ EOF
26
26
 
27
27
  gem.rubyforge_project = gem.name
28
28
 
29
- gem.platform = 'jruby'
30
- gem.has_rdoc = true
31
- gem.extra_rdoc_files = ['README.md']
29
+ gem.platform = 'jruby'
30
+ gem.required_ruby_version = '>= 1.8.7'
31
+ gem.has_rdoc = true
32
+ gem.extra_rdoc_files = ['README.md']
32
33
 
33
- gem.add_dependency 'rspec', '>= 2'
34
+ gem.add_dependency 'rspec', '>= 2.4'
34
35
 
35
36
  gem.add_development_dependency 'jeweler'
36
37
  gem.add_development_dependency 'rake'
@@ -40,9 +41,7 @@ EOF
40
41
  gem.add_development_dependency 'rr'
41
42
 
42
43
  gem.files.exclude '.gitignore'
43
- gem.files.exclude 'bin/desktopwatir'
44
- gem.files.exclude 'lib/operawatir/desktop*.rb'
45
- gem.files.exclude 'lib/operawatir/quickwidgets'
44
+ gem.files.exclude '.gitmodules'
46
45
  end
47
46
 
48
47
  CLEAN.add 'pkg'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3
1
+ 0.3.2
data/bin/desktopwatir CHANGED
@@ -8,6 +8,9 @@ require 'rbconfig'
8
8
  require 'rspec'
9
9
  require 'operawatir'
10
10
 
11
+ # Encoding fix
12
+ $KCODE = "UTF8"
13
+
11
14
  class Options
12
15
 
13
16
  def self.parse(args)
data/bin/operawatir CHANGED
@@ -10,7 +10,7 @@ require 'operawatir/helper'
10
10
  :ng => false,
11
11
  :color_enabled => Config::CONFIG['host_os'] =~ /mswin|mingw|bccwin|wince|emx/ ? false : true,
12
12
  :check_syntax => false,
13
- :formatter => 'progress'
13
+ :format => 'progress'
14
14
  }
15
15
 
16
16
  # TODO
@@ -53,7 +53,7 @@ EOS
53
53
  # 'own JVM') do |ng|
54
54
  # @options[:ng] = ng
55
55
  #end
56
-
56
+
57
57
  opts.on('-f', '--format=FORMAT',
58
58
  'Specify RSpec output formatter (documentation, html, ',
59
59
  'progress (default), textmate)') do |formatter|
Binary file
data/lib/operawatir.rb CHANGED
@@ -19,22 +19,28 @@ $KCODE = 'u' # UTF-8 support
19
19
  # TODO This should be replaced when we decide upon a better way of
20
20
  # enabling the Watir 2 API.
21
21
  module OperaWatir
22
- @shiny = false
22
+ @current_api = 1
23
23
 
24
- # Activates the Watir 2 API.
25
- def self.newandshinyplease!
26
- @shiny = true
24
+ # Set the API version you wish to use. Please note that setting
25
+ # this after OperaWatir::Browser has been initialized will have no
26
+ # affect.
27
+ #
28
+ # @param number [Integer] API version to use
29
+ def self.api=(number)
30
+ @current_api = number.to_i
27
31
  end
28
32
 
29
- # Queries whether the Watir 2 API is enabled.
33
+ # Queries which API to use.
30
34
  #
31
- # @return [Boolean] whether or not Watir 2 API is enabled.
32
- def self.newandshinyplease?
33
- @shiny
35
+ # @return [Integer] Desired API version
36
+ def self.api
37
+ @current_api
34
38
  end
35
39
  end
36
40
 
37
41
  require 'operawatir/version'
42
+ require 'operawatir/platform'
43
+ require 'operawatir/keys'
38
44
 
39
45
  require 'operawatir/exceptions'
40
46
  require 'operawatir/selector'
@@ -4,10 +4,10 @@ class OperaWatir::Browser
4
4
  attr_accessor :driver, :active_window
5
5
 
6
6
  def self.settings=(settings={})
7
- @opera_driver_settings = nil # Bust cache
8
- @settings = settings.merge! :launcher => ENV['OPERA_LAUNCHER'] || '',
9
- :path => ENV['OPERA_PATH'] || '',
10
- :args => ENV['OPERA_ARGS'] || ''
7
+ @opera_driver_settings = nil # Bust cache
8
+ @settings = settings.merge! :launcher => OperaWatir::Platform.launcher,
9
+ :path => OperaWatir::Platform.opera,
10
+ :args => OperaWatir::Platform.args
11
11
  end
12
12
 
13
13
  def self.settings
@@ -15,7 +15,7 @@ class OperaWatir::Browser
15
15
  end
16
16
 
17
17
  def initialize
18
- OperaWatir.compatibility! unless OperaWatir.newandshinyplease?
18
+ OperaWatir.compatibility! unless OperaWatir.api >= 2
19
19
 
20
20
  self.driver = OperaDriver.new(self.class.opera_driver_settings)
21
21
  self.active_window = OperaWatir::Window.new(self)
@@ -62,6 +62,48 @@ class OperaWatir::Browser
62
62
  driver.closeAll
63
63
  end
64
64
 
65
+ # Accesses the keys API in OperaWatir::Keys.
66
+ def keys
67
+ OperaWatir::Keys.new(self)
68
+ end
69
+
70
+ # Set preference pref in prefs section prefs_section to value
71
+ # specified.
72
+ #
73
+ # TODO: This needs to be moved to a separate preference section.
74
+ #
75
+ # @param [String] prefs_section The prefs section the pref belongs to
76
+ # @param [String] pref The preference to set
77
+ # @param [String] value The value to set the preference to
78
+ def set_preference(prefs_section, pref, value)
79
+ @driver.setPref(prefs_section, pref, value.to_s)
80
+ end
81
+
82
+ # Get value of preference pref in prefs section prefs_section.
83
+ #
84
+ # TODO: This needs to be moved to a separate preference section.
85
+ #
86
+ # @param [String] prefs_section The prefs section the pref belongs to
87
+ # @param [String] pref The preference to get
88
+ #
89
+ # @return [String] The value of the preference
90
+ def get_preference(prefs_section, pref)
91
+ @driver.getPref(prefs_section, pref)
92
+ end
93
+
94
+ # Get default value of preference pref in prefs section
95
+ # prefs_section.
96
+ #
97
+ # TODO: This needs to be moved to a separate preference section.
98
+ #
99
+ # @param [String] prefs_section The prefs section the pref belongs to
100
+ # @param [String] pref The preference to get
101
+ #
102
+ # @return [String] The value of the preference
103
+ def get_default_preference(prefs_section, pref)
104
+ @driver.getDefaultPref(prefs_section, pref)
105
+ end
106
+
65
107
  # Get the version number of the driver. This _is not_ the same as
66
108
  # the version number for OperaWatir, which can be retrieved using
67
109
  # +OperaWatir.version+ instead.
@@ -114,38 +156,7 @@ class OperaWatir::Browser
114
156
  # @return [Boolean] true if browser attached is of type desktop,
115
157
  # false otherwise
116
158
  def desktop?
117
- false
118
- end
119
-
120
- # Send key events to the browser instance. I.e. “Down” (arrow
121
- # down), “Space” (space key), “Home”, &c.
122
- #
123
- # @param [String] key to be pressed once
124
- def key(key)
125
- @driver.key(key)
126
- end
127
-
128
- # Enables you to hold down a key, i.e. “Ctrl”, “Alt”, “Shift”, &c.
129
- # Remember to release the keys afterwards with the key_up method.
130
- #
131
- # @param [String] key to be pressed down
132
- def key_down(key)
133
- @driver.keyDown(key)
134
- end
135
-
136
- # Releases a held down key.
137
- #
138
- # @param [String] key to be lifted
139
- def key_up(key)
140
- @driver.keyUp(key)
141
- end
142
-
143
- # Types given text directly in to the browser. The text will be
144
- # inputted to the page depending on where the focus is.
145
- #
146
- # @param [String] text to be typed
147
- def type(text)
148
- @driver.type(text)
159
+ false # FIXME
149
160
  end
150
161
 
151
162
  # Sends an Opera action to the browser.
@@ -174,7 +185,7 @@ private
174
185
  s.setRunOperaLauncherFromOperaDriver true
175
186
  s.setOperaLauncherBinary self.settings[:launcher]
176
187
  s.setOperaBinaryLocation self.settings[:path]
177
- s.setOperaBinaryArguments self.settings[:args] + (Config::CONFIG['host_os'] =~ /mswin|mingw|bccwin|wince|emc/ ? '' : ' -nosession') + ' opera:debug'
188
+ s.setOperaBinaryArguments self.settings[:args] + ' -watirtest'
178
189
  }
179
190
  end
180
191
 
@@ -96,4 +96,10 @@ class OperaWatir::Collection
96
96
  end.join("\n")
97
97
  end
98
98
 
99
+ private
100
+
101
+ def map_or_return(&blk)
102
+ blk.call(raw_elements.first)
103
+ end
104
+
99
105
  end
@@ -89,7 +89,7 @@ class OperaWatir::Element
89
89
  # Clears a text input or textarea of any text.
90
90
  def clear
91
91
  assert_enabled!
92
- node.clear
92
+ uncheck!
93
93
  end
94
94
 
95
95
  # If passed a value it will type text into the element, otherwise it
@@ -100,7 +100,8 @@ class OperaWatir::Element
100
100
  if value
101
101
  self.text = value
102
102
  else
103
- check!
103
+ assert_enabled
104
+ click!
104
105
  end
105
106
  end
106
107
 
@@ -137,6 +138,8 @@ class OperaWatir::Element
137
138
  end
138
139
  end
139
140
 
141
+ alias_method :set?, :checked?
142
+
140
143
  # For `<select>` elements returns either 'select-one' for
141
144
  # `<select>`s where only a single `<option>` can be selected, or
142
145
  # 'select-multiple' otherwise. For non-`<select>` elements returns
@@ -37,6 +37,8 @@ module OperaWatir::Compat::ElementFinders
37
37
  def_element :checkbox, :checkboxes, :how => :name do |selector|
38
38
  selector.tag(:input).attribute :type => 'checkbox'
39
39
  end
40
+ # Override checkbox method to allow (:name, <name>, <value>) selectors
41
+ # see line 113
40
42
 
41
43
  def_element :dd, :dds
42
44
 
@@ -105,6 +107,23 @@ module OperaWatir::Compat::ElementFinders
105
107
  selector.tag(:input).attribute :type => 'radio'
106
108
  end
107
109
 
110
+ # Override checbox and radio methods to allow (:name, <name>, <value>)
111
+ # selectors
112
+ [:checkbox, :radio].each do |tag|
113
+ define_method tag do |*args|
114
+ c = OperaWatir::Collection.new(self)
115
+ c.selector.tag(:input).attribute(:type => tag.to_s)
116
+
117
+ if args.length == 3 and args[0] == :name
118
+ c.selector.attribute(:name => args[1]).attribute(:value => args[2])
119
+ else
120
+ c.add_selector_from_arguments args, :name
121
+ end
122
+
123
+ return c
124
+ end
125
+ end
126
+
108
127
  def_element :select_list, :select_lists do |selector|
109
128
  selector.tag :select
110
129
  end
@@ -0,0 +1,144 @@
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
+