operawatir 0.6.pre1-jruby → 0.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.
- data/Gemfile.lock +58 -0
- data/Rakefile +10 -1
- data/VERSION +1 -1
- data/lib/operadriver/guava-11.0.1.jar +0 -0
- data/lib/operadriver/ini4j-0.5.2.jar +0 -0
- data/lib/operadriver/json-20080701.jar +0 -0
- data/lib/operadriver/operadriver-v0.11.jar +0 -0
- data/lib/operadriver/operalaunchers-0.6.jar +0 -0
- data/lib/operadriver/selenium-java-2.17.jar +0 -0
- data/lib/operawatir.rb +2 -4
- data/lib/operawatir/actions.rb +1 -1
- data/lib/operawatir/browser.rb +23 -14
- data/lib/operawatir/compat/element.rb +1 -1
- data/lib/operawatir/desktop_helper.rb +1 -0
- data/lib/operawatir/element.rb +9 -5
- data/lib/operawatir/keys.rb +24 -11
- data/lib/operawatir/preferences.rb +116 -128
- data/lib/operawatir/utils.rb +1 -1
- data/spec/operawatir/core/actions_spec.rb +8 -8
- data/spec/operawatir/core/browser_spec.rb +4 -3
- data/spec/operawatir/core/preferences_spec.rb +23 -39
- data/spec/operawatir/server.rb +106 -9
- data/spec/operawatir/watirspec_helper.rb +7 -1
- data/utils/formatters/{operahelper_formatter.rb → opera_helper_formatter.rb} +0 -0
- metadata +11 -9
- data/lib/operadriver/guava-10.0.1.jar +0 -0
- data/lib/operadriver/operalaunchers-0.3.jar +0 -0
- data/lib/operadriver/selenium-java-2.13.0.jar +0 -0
- data/operawatir.gemspec +0 -376
- data/utils/Rakefile +0 -79
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
BlueCloth (1.0.1)
|
5
|
+
builder (3.0.0)
|
6
|
+
ci_reporter (1.7.0)
|
7
|
+
builder (>= 2.1.2)
|
8
|
+
clipboard (1.0.1)
|
9
|
+
deprecated (3.0.0)
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
gem_plugin (0.2.3)
|
12
|
+
git (1.2.5)
|
13
|
+
jeweler (1.8.3)
|
14
|
+
bundler (~> 1.0)
|
15
|
+
git (>= 1.2.5)
|
16
|
+
rake
|
17
|
+
rdoc
|
18
|
+
json (1.6.5-java)
|
19
|
+
mongrel (1.1.5-java)
|
20
|
+
gem_plugin (>= 0.2.3)
|
21
|
+
rack (1.4.1)
|
22
|
+
rack-protection (1.2.0)
|
23
|
+
rack
|
24
|
+
rake (0.8.7)
|
25
|
+
rdoc (3.12)
|
26
|
+
json (~> 1.4)
|
27
|
+
rr (1.0.4)
|
28
|
+
rspec (2.6.0)
|
29
|
+
rspec-core (~> 2.6.0)
|
30
|
+
rspec-expectations (~> 2.6.0)
|
31
|
+
rspec-mocks (~> 2.6.0)
|
32
|
+
rspec-core (2.6.4)
|
33
|
+
rspec-expectations (2.6.0)
|
34
|
+
diff-lcs (~> 1.1.2)
|
35
|
+
rspec-mocks (2.6.0)
|
36
|
+
sinatra (1.3.2)
|
37
|
+
rack (~> 1.3, >= 1.3.6)
|
38
|
+
rack-protection (~> 1.2)
|
39
|
+
tilt (~> 1.3, >= 1.3.3)
|
40
|
+
tilt (1.3.3)
|
41
|
+
yard (0.7.5)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
java
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
BlueCloth (= 1.0.1)
|
48
|
+
builder
|
49
|
+
bundler (~> 1.0.0)
|
50
|
+
ci_reporter
|
51
|
+
clipboard
|
52
|
+
deprecated
|
53
|
+
jeweler
|
54
|
+
mongrel (>= 1.1.5)
|
55
|
+
rr
|
56
|
+
rspec (~> 2.6.0)
|
57
|
+
sinatra (>= 1.1)
|
58
|
+
yard
|
data/Rakefile
CHANGED
@@ -4,10 +4,20 @@ require 'jeweler'
|
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
require 'yard'
|
6
6
|
require 'ci/reporter/rake/rspec'
|
7
|
+
require 'rake'
|
8
|
+
|
7
9
|
|
8
10
|
require './lib/operawatir/version'
|
9
11
|
|
10
12
|
Jeweler::Tasks.new do |gem|
|
13
|
+
|
14
|
+
gem.files = FileList['utils/**/*.rb', '.*', 'lib/operadriver/*LICENSE.txt', 'spec/**/*.rb', 'spec/**/**/*.*', 'lib/**/*.rb', 'lib/**/*.jar', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
|
15
|
+
gem.files.exclude '*.gem'
|
16
|
+
gem.files.exclude '.gitignore'
|
17
|
+
gem.files.exclude '*.xml'
|
18
|
+
gem.files.exclude '*.bat'
|
19
|
+
gem.files.exclude '*.py'
|
20
|
+
|
11
21
|
gem.name = 'operawatir'
|
12
22
|
gem.version = OperaWatir.version
|
13
23
|
gem.date = Date.today.to_s
|
@@ -43,7 +53,6 @@ EOF
|
|
43
53
|
gem.add_development_dependency 'rr'
|
44
54
|
gem.add_development_dependency 'clipboard'
|
45
55
|
|
46
|
-
gem.files.exclude '.gitignore'
|
47
56
|
end
|
48
57
|
|
49
58
|
CLEAN.add 'pkg'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.pre1
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/operawatir.rb
CHANGED
@@ -5,17 +5,15 @@ require 'java'
|
|
5
5
|
include Java
|
6
6
|
|
7
7
|
%w(commons-jxpath-1.3.jar commons-exec-1.1.jar protobuf-java-2.4.1.jar
|
8
|
-
selenium-java-2.
|
9
|
-
guava-
|
8
|
+
selenium-java-2.17.jar operalaunchers-0.6.jar operadriver-v0.11.jar
|
9
|
+
guava-11.0.1.jar ini4j-0.5.2.jar json-20080701.jar).each { |jar| require "operadriver/#{jar}" }
|
10
10
|
|
11
11
|
include_class org.openqa.selenium.WebDriver
|
12
12
|
include_class org.openqa.selenium.remote.RemoteWebElement
|
13
13
|
include_class org.openqa.selenium.NoSuchElementException
|
14
|
-
include_class org.openqa.selenium.interactions.Actions
|
15
14
|
include_class org.openqa.selenium.remote.DesiredCapabilities
|
16
15
|
include_class com.opera.core.systems.OperaDriver
|
17
16
|
include_class com.opera.core.systems.OperaWebElement
|
18
|
-
include_class com.opera.core.systems.settings.OperaDriverSettings
|
19
17
|
|
20
18
|
# Desktop stuff
|
21
19
|
include_class com.opera.core.systems.OperaDesktopDriver
|
data/lib/operawatir/actions.rb
CHANGED
data/lib/operawatir/browser.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
class OperaWatir::Browser
|
3
3
|
include Deprecated
|
4
4
|
|
5
|
-
|
5
|
+
attr_reader :driver, :active_window, :preferences, :keys, :spatnav, :utils
|
6
6
|
|
7
7
|
def self.settings=(settings={})
|
8
8
|
@desired_capabilities = nil # Bust cache
|
@@ -22,12 +22,12 @@ class OperaWatir::Browser
|
|
22
22
|
def initialize
|
23
23
|
OperaWatir.compatibility! unless OperaWatir.api >= 3
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
@driver = OperaDriver.new(self.class.desired_capabilities)
|
26
|
+
@active_window = OperaWatir::Window.new(self)
|
27
|
+
@preferences = OperaWatir::Preferences.new(driver)
|
28
|
+
@keys = OperaWatir::Keys.new(self)
|
29
|
+
@spatnav = OperaWatir::Spatnav.new(self)
|
30
|
+
@utils = OperaWatir::Utils.new(self)
|
31
31
|
end
|
32
32
|
|
33
33
|
alias_method :window, :active_window
|
@@ -168,28 +168,33 @@ class OperaWatir::Browser
|
|
168
168
|
# Keyboard
|
169
169
|
|
170
170
|
def key(key)
|
171
|
-
|
171
|
+
keys.key(key)
|
172
|
+
|
173
|
+
if key =~ /enter/
|
174
|
+
sleep Java::ComOperaCoreSystems::OperaIntervals.EXEC_SLEEP.getValue
|
175
|
+
driver.waitForLoadToComplete
|
176
|
+
end
|
172
177
|
end
|
173
178
|
|
174
179
|
deprecated :key, 'browser.keys.send'
|
175
180
|
|
176
181
|
def key_down(key)
|
177
|
-
|
182
|
+
keys.down(key)
|
178
183
|
end
|
179
184
|
|
180
|
-
deprecated :
|
185
|
+
deprecated :key_down, 'browser.keys.down'
|
181
186
|
|
182
187
|
def key_up(key)
|
183
|
-
|
188
|
+
keys.up(key)
|
184
189
|
end
|
185
190
|
|
186
|
-
deprecated :
|
191
|
+
deprecated :key_up, 'browser.keys.up or browser.keys.release'
|
187
192
|
|
188
193
|
def type(text)
|
189
|
-
|
194
|
+
keys.send(text)
|
190
195
|
end
|
191
196
|
|
192
|
-
deprecated :
|
197
|
+
deprecated :type, 'browser.keys.send'
|
193
198
|
|
194
199
|
# actions
|
195
200
|
|
@@ -197,6 +202,10 @@ class OperaWatir::Browser
|
|
197
202
|
OperaWatir::Actions.new(browser)
|
198
203
|
end
|
199
204
|
|
205
|
+
def inspect
|
206
|
+
"#<OperaWatir::Browser:#{object_id}>" # @settings=#{@settings.insepct}, @active_window=#{@active_window.inspect}"
|
207
|
+
end
|
208
|
+
|
200
209
|
private
|
201
210
|
|
202
211
|
def self.desired_capabilities(desktopwatir = false)
|
data/lib/operawatir/element.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
class OperaWatir::Element
|
2
2
|
extend Forwardable
|
3
3
|
|
4
|
+
attr_reader :node
|
5
|
+
|
4
6
|
def initialize(node)
|
5
|
-
|
7
|
+
@node = node
|
6
8
|
end
|
7
9
|
|
8
10
|
# TODO Need support for this in Webdriver
|
@@ -68,9 +70,12 @@ class OperaWatir::Element
|
|
68
70
|
def_delegator :node, :getText, :text
|
69
71
|
def_delegator :node, :getHTML, :html
|
70
72
|
|
71
|
-
def_delegator :node, :getElementName, :tag_name
|
72
73
|
def_delegator :node, :clear, :clear
|
73
74
|
|
75
|
+
def tag_name
|
76
|
+
node.callMethod('locator.nodeName')
|
77
|
+
end
|
78
|
+
|
74
79
|
# On elements of type `input`, `textarea` or `select` it will fetch
|
75
80
|
# the texteditable `value` attribute, on every other element type it
|
76
81
|
# returns the DOM attribute `value`.
|
@@ -87,7 +92,8 @@ class OperaWatir::Element
|
|
87
92
|
end
|
88
93
|
=end
|
89
94
|
|
90
|
-
node.getValue
|
95
|
+
#node.getValue
|
96
|
+
attr('value')
|
91
97
|
end
|
92
98
|
|
93
99
|
#
|
@@ -232,8 +238,6 @@ class OperaWatir::Element
|
|
232
238
|
|
233
239
|
private
|
234
240
|
|
235
|
-
attr_accessor :node
|
236
|
-
|
237
241
|
# Finders
|
238
242
|
|
239
243
|
def find_elements_by_id(value)
|
data/lib/operawatir/keys.rb
CHANGED
@@ -24,7 +24,7 @@ class OperaWatir::Keys
|
|
24
24
|
#
|
25
25
|
|
26
26
|
def down(*args)
|
27
|
-
args.each { |key|
|
27
|
+
args.each { |key| key_down(key) }
|
28
28
|
end
|
29
29
|
|
30
30
|
#
|
@@ -40,7 +40,7 @@ class OperaWatir::Keys
|
|
40
40
|
#
|
41
41
|
|
42
42
|
def up(*args)
|
43
|
-
args.each { |key|
|
43
|
+
args.each { |key| key_up(key) }
|
44
44
|
end
|
45
45
|
|
46
46
|
#
|
@@ -52,7 +52,7 @@ class OperaWatir::Keys
|
|
52
52
|
#
|
53
53
|
|
54
54
|
def release
|
55
|
-
|
55
|
+
exec.releaseKeys
|
56
56
|
end
|
57
57
|
|
58
58
|
#
|
@@ -92,7 +92,7 @@ class OperaWatir::Keys
|
|
92
92
|
when :access
|
93
93
|
access_key item[index + 1]
|
94
94
|
when Symbol
|
95
|
-
|
95
|
+
key_down key
|
96
96
|
else
|
97
97
|
key key
|
98
98
|
end
|
@@ -106,24 +106,37 @@ class OperaWatir::Keys
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
def key(key)
|
110
|
+
key_down(key)
|
111
|
+
key_up(key)
|
112
|
+
end
|
113
|
+
|
109
114
|
private
|
110
115
|
|
111
|
-
def
|
112
|
-
|
116
|
+
def key_down(key)
|
117
|
+
exec.key(key.to_s, false)
|
113
118
|
end
|
114
119
|
|
115
|
-
def
|
116
|
-
|
120
|
+
def key_up(key)
|
121
|
+
exec.key(key.to_s, true)
|
117
122
|
end
|
118
123
|
|
119
124
|
def type(text)
|
120
|
-
|
125
|
+
exec.type(text.to_s)
|
121
126
|
end
|
122
127
|
|
123
128
|
def access_key(key)
|
124
129
|
driver.operaAction 'Enter access key mode'
|
125
|
-
send key
|
130
|
+
send key.to_s
|
126
131
|
driver.operaAction 'Leave access key mode'
|
127
132
|
end
|
128
133
|
|
129
|
-
|
134
|
+
def exec
|
135
|
+
driver.getExecService
|
136
|
+
end
|
137
|
+
|
138
|
+
def driver
|
139
|
+
browser.driver
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
@@ -1,31 +1,38 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
class
|
2
|
+
class Array
|
3
3
|
|
4
4
|
#
|
5
|
-
#
|
6
|
-
# It will remove tabs and spaces at beginning of string, replace
|
7
|
-
# further spaces with an underscore and make the string lower-case.
|
8
|
-
#
|
9
|
-
# The method extends the String object and can be called as a regular
|
10
|
-
# method on any string in Ruby.
|
5
|
+
# Gets the unique entries in an array.
|
11
6
|
#
|
12
7
|
|
13
|
-
def
|
14
|
-
|
8
|
+
def uniq_by(&blk)
|
9
|
+
transforms = {}
|
10
|
+
select do |el|
|
11
|
+
t = blk[el]
|
12
|
+
should_keep = !transforms[t]
|
13
|
+
transforms[t] = true
|
14
|
+
should_keep
|
15
|
+
end
|
15
16
|
end
|
16
17
|
|
18
|
+
end
|
19
|
+
|
20
|
+
class String
|
21
|
+
|
17
22
|
#
|
18
|
-
# Translates a
|
19
|
-
#
|
20
|
-
#
|
23
|
+
# Translates a preference key into a Ruby method name. It will
|
24
|
+
# remove tabs and spaces at beginning and the end of the string, remove
|
25
|
+
# paranthesis, replace further spaces and dots with underscores and make
|
26
|
+
# the final string lower-case.
|
21
27
|
#
|
22
28
|
# The method extends the String object and can be called as a regular
|
23
29
|
# method on any string in Ruby.
|
24
30
|
#
|
25
31
|
|
26
|
-
def
|
27
|
-
self.gsub(
|
32
|
+
def methodize
|
33
|
+
self.strip.gsub(/\(|\)/, '').gsub(/\s+|-+|\./, '_').downcase
|
28
34
|
end
|
35
|
+
|
29
36
|
end
|
30
37
|
|
31
38
|
#
|
@@ -104,8 +111,6 @@ class OperaWatir::Preferences
|
|
104
111
|
extend Forwardable
|
105
112
|
include Enumerable
|
106
113
|
|
107
|
-
attr_accessor :browser, :driver
|
108
|
-
|
109
114
|
#
|
110
115
|
# The OperaWatir::Preferences object is created automatically when you
|
111
116
|
# create an OperaWatir::Browser object, and is available as
|
@@ -118,55 +123,53 @@ class OperaWatir::Preferences
|
|
118
123
|
# @param [Object] browser An OperaWatir::Browser object.
|
119
124
|
#
|
120
125
|
|
121
|
-
def initialize(
|
122
|
-
|
123
|
-
|
124
|
-
raw_prefs = driver.listAllPrefs.to_a
|
125
|
-
@_prefs = {}
|
126
|
-
@_prefs = raw_prefs.map { |s| Section.new(self, s) }.sort_by { |s| s.key }
|
126
|
+
def initialize(driver)
|
127
|
+
raw_prefs = driver.preferences.all.to_a
|
127
128
|
|
128
|
-
@
|
129
|
+
@sections = []
|
130
|
+
raw_prefs.collect { |p| p.get_section }.uniq.each do |section|
|
131
|
+
@sections << Section.new(raw_prefs.find_all { |p| p.get_section == section })
|
132
|
+
end
|
129
133
|
end
|
130
134
|
|
131
|
-
def_delegators
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
135
|
+
def_delegators :@sections, :[],
|
136
|
+
:each,
|
137
|
+
:length,
|
138
|
+
:size,
|
139
|
+
:first,
|
140
|
+
:last,
|
141
|
+
:empty?
|
138
142
|
|
139
143
|
#
|
140
|
-
# When calling Preferences#any_method_name
|
141
|
-
# be caught by this method.
|
144
|
+
# When calling Preferences#any_method_name the `any_method_name` will
|
145
|
+
# be caught by this meta method.
|
142
146
|
#
|
143
147
|
# This is the standard way of looking up sections. `any_method_name`
|
144
|
-
# should be replaced by a
|
148
|
+
# should be replaced by a methodize version of the secion as it
|
145
149
|
# appears in the Opera preferences list which you can find at
|
146
150
|
# `opera:config`.
|
147
151
|
#
|
148
152
|
# @example
|
149
153
|
#
|
150
154
|
# browser.preferences.interface_colors
|
151
|
-
# # will return section
|
155
|
+
# # will return section "Interface Colors"
|
152
156
|
#
|
153
|
-
# @param
|
154
|
-
# @return [Object]
|
157
|
+
# @param section method to look up in preferences
|
158
|
+
# @return [Object] a Preferences::Section object
|
159
|
+
# @throws PreferencesException if section does not exist
|
155
160
|
#
|
156
161
|
|
157
162
|
def method_missing(method)
|
158
163
|
method = method.to_s
|
159
|
-
|
160
|
-
|
161
|
-
_prefs.find { |s| s.method == method }
|
162
|
-
end
|
164
|
+
raise OperaWatir::Exceptions::PreferencesException, "Section does not exist: #{method}" unless @sections.any? { |s| s.method == method }
|
165
|
+
@sections.find { |s| s.method == method }
|
163
166
|
end
|
164
167
|
|
165
168
|
#
|
166
169
|
# Retrieves a human-readable list of Opera preferences available.
|
167
170
|
# This is used for convenience and should never be parsed. Consider
|
168
|
-
# using the
|
169
|
-
#
|
171
|
+
# using the iterator #each (with friends) or Preferences#to_a for
|
172
|
+
# that.
|
170
173
|
#
|
171
174
|
# @return [String] list of preferences
|
172
175
|
#
|
@@ -174,12 +177,11 @@ class OperaWatir::Preferences
|
|
174
177
|
def to_s
|
175
178
|
text = ''
|
176
179
|
|
177
|
-
|
180
|
+
@sections.each do |s|
|
178
181
|
text << "#{s.method}\n"
|
179
182
|
|
180
183
|
s.each do |k|
|
181
184
|
text << " #{k.method}\n"
|
182
|
-
text << " type: #{k.type.inspect}\n"
|
183
185
|
text << " value: #{k.value.inspect}\n"
|
184
186
|
text << " default: #{k.default.inspect}\n"
|
185
187
|
text << " enabled: #{k.enabled?.inspect}\n"
|
@@ -192,16 +194,16 @@ class OperaWatir::Preferences
|
|
192
194
|
end
|
193
195
|
|
194
196
|
#
|
195
|
-
# Returns a list of all preferences in array form. This
|
196
|
-
# for external parsing. If you wish to manipulate or
|
197
|
-
# the list of preferences, consider using the
|
198
|
-
# #each (with friends).
|
197
|
+
# Returns a duplicate list of all preferences in array form. This
|
198
|
+
# can be used for external parsing. If you wish to manipulate or
|
199
|
+
# iterate through the list of preferences, consider using the
|
200
|
+
# iterator #each (with friends).
|
199
201
|
#
|
200
202
|
# @return [Array] list of preferences
|
201
203
|
#
|
202
204
|
|
203
205
|
def to_a
|
204
|
-
|
206
|
+
@sections.dup
|
205
207
|
end
|
206
208
|
|
207
209
|
#
|
@@ -212,36 +214,13 @@ class OperaWatir::Preferences
|
|
212
214
|
#
|
213
215
|
|
214
216
|
def exists?
|
215
|
-
|
217
|
+
!@sections.empty?
|
216
218
|
end
|
217
219
|
|
218
220
|
alias_method :exist?, :exists? # LOL Ruby
|
219
221
|
|
220
|
-
=begin
|
221
|
-
def cleanup
|
222
|
-
@old_prefs.dup
|
223
|
-
end
|
224
|
-
|
225
|
-
def cleanup!
|
226
|
-
@old_prefs.each do |old_section|
|
227
|
-
old_section.each do |old_key|
|
228
|
-
#self.send(old_section.method).send(old_key.method).send(:value, old_key.value)
|
229
|
-
puts "#{old_section.method}.#{old_key.method}.value = #{old_key.value}"
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
_prefs
|
234
|
-
end
|
235
|
-
=end
|
236
|
-
|
237
|
-
private
|
238
|
-
|
239
|
-
def _prefs
|
240
|
-
@_prefs
|
241
|
-
end
|
242
|
-
|
243
222
|
#
|
244
|
-
# OperaWatir::Preferences::Section represents a section in Opera
|
223
|
+
# OperaWatir::Preferences::Section represents a section in the Opera
|
245
224
|
# configuration.
|
246
225
|
#
|
247
226
|
|
@@ -249,30 +228,29 @@ private
|
|
249
228
|
extend Forwardable
|
250
229
|
include Enumerable
|
251
230
|
|
252
|
-
|
231
|
+
attr_reader :key, :method
|
253
232
|
|
254
|
-
def initialize(
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
@_keys = raw_section[1].map { |k| Key.new(self, k) }.sort_by { |k| k.key }
|
233
|
+
def initialize(raw_section)
|
234
|
+
@key = raw_section.first.get_section
|
235
|
+
@method = @key.methodize
|
236
|
+
@keys ||= raw_section.collect { |p| Key.new(self, p) }.sort_by { |p| p.key }
|
259
237
|
end
|
260
238
|
|
261
|
-
def_delegators
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
239
|
+
def_delegators :@keys, :[],
|
240
|
+
:length,
|
241
|
+
:size,
|
242
|
+
:first,
|
243
|
+
:last,
|
244
|
+
:empty?
|
267
245
|
|
268
246
|
def each
|
269
247
|
return unless block_given?
|
270
|
-
|
248
|
+
@keys.each { |k| yield k }
|
271
249
|
end
|
272
250
|
|
273
251
|
#
|
274
252
|
# When calling Preferences::Section#any_method_name, the
|
275
|
-
# `any_method_name` will be caught by this method.
|
253
|
+
# `any_method_name` will be caught by this meta method.
|
276
254
|
#
|
277
255
|
# This is the standard way of looking up preference entries.
|
278
256
|
# `any_method_name` should be replaced by a methodized version of
|
@@ -284,68 +262,58 @@ private
|
|
284
262
|
# browser.preferences.interface_colors.background
|
285
263
|
# # will return the “Background” entry in section “Interface Colors”
|
286
264
|
#
|
287
|
-
# @param
|
288
|
-
# @return [Object]
|
265
|
+
# @param method method to look up in section
|
266
|
+
# @return [Object] a Preferences::Section::Key (entry) object
|
267
|
+
# @throws PreferencesException if key does not exist
|
289
268
|
#
|
290
269
|
|
291
|
-
def method_missing(
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
_keys.find { |k| k.method == method }
|
296
|
-
end
|
270
|
+
def method_missing(m)
|
271
|
+
m = m.to_s
|
272
|
+
raise OperaWatir::Exceptions::PreferencesException, "No such preference: #{method}.#{m}" unless @keys.any? { |k| k.method == m }
|
273
|
+
@keys.find { |k| k.method == m }
|
297
274
|
end
|
298
275
|
|
299
|
-
|
300
|
-
|
301
|
-
def _keys
|
302
|
-
@_keys
|
276
|
+
def inspect
|
277
|
+
"#<OperaWatir::Preferences::Section:#{object_id}> @key=#{key.inspect}, @method=#{method.to_sym.inspect}, @keys=[...]"
|
303
278
|
end
|
304
279
|
|
305
280
|
class Key
|
306
281
|
extend Forwardable
|
307
282
|
include Enumerable
|
308
283
|
|
309
|
-
|
284
|
+
attr_reader :parent, :method
|
310
285
|
|
311
|
-
def initialize(parent,
|
312
|
-
|
313
|
-
|
314
|
-
|
286
|
+
def initialize(parent, raw_pref)
|
287
|
+
@parent = parent
|
288
|
+
@pref = raw_pref
|
289
|
+
@method = key.methodize
|
290
|
+
end
|
315
291
|
|
316
|
-
|
317
|
-
|
292
|
+
def method
|
293
|
+
@method
|
294
|
+
end
|
318
295
|
|
319
|
-
|
320
|
-
@value = $1.to_s
|
296
|
+
def_delegator :@pref, :get_key, :key
|
321
297
|
|
322
|
-
|
323
|
-
|
324
|
-
raw_data =~ /^enabled: (true|false)$/
|
325
|
-
@enabled = $1.truthy?
|
298
|
+
def value
|
299
|
+
ruby_idiomatic(@pref.get_value)
|
326
300
|
end
|
327
301
|
|
328
302
|
#
|
329
|
-
#
|
303
|
+
# Sets the key's value to the specified string.
|
330
304
|
#
|
331
|
-
# @
|
305
|
+
# @param [String] value the value you wish to set for the key
|
332
306
|
#
|
333
307
|
|
334
|
-
|
335
|
-
!!@enabled
|
336
|
-
end
|
308
|
+
def_delegator :@pref, :set_value, :value=
|
337
309
|
|
338
310
|
#
|
339
|
-
#
|
311
|
+
# Whether the current key entry is enabled inside Opera or not.
|
340
312
|
#
|
341
|
-
# @
|
313
|
+
# @return [Boolean] true if enabled, false if otherwise
|
342
314
|
#
|
343
315
|
|
344
|
-
|
345
|
-
value = value.truthy? ? '1' : '0' if type.include?('Boolean')
|
346
|
-
driver.setPref parent.key, key, value.to_s
|
347
|
-
@value = value
|
348
|
-
end
|
316
|
+
def_delegator :@pref, :is_enabled, :enabled?
|
349
317
|
|
350
318
|
#
|
351
319
|
# Returns key's default value.
|
@@ -354,7 +322,7 @@ private
|
|
354
322
|
#
|
355
323
|
|
356
324
|
def default
|
357
|
-
@
|
325
|
+
ruby_idiomatic(@pref.get_default_value)
|
358
326
|
end
|
359
327
|
|
360
328
|
#
|
@@ -364,9 +332,29 @@ private
|
|
364
332
|
#
|
365
333
|
|
366
334
|
def default!
|
367
|
-
|
335
|
+
@pref.reset
|
336
|
+
@pref.value
|
368
337
|
end
|
338
|
+
|
339
|
+
def inspect
|
340
|
+
"#<OperaWatir::Preferences::Section::Key:#{object_id}> @key=#{key.inspect}, @method=#{method.to_sym.inspect}, @parent=#{parent.inspect}, @value=#{value.inspect}, @enabled=#{enabled?.inspect}, @default=#{default.inspect}"
|
341
|
+
end
|
342
|
+
|
343
|
+
private
|
344
|
+
|
345
|
+
def ruby_idiomatic(value)
|
346
|
+
case @pref.get_type.to_string
|
347
|
+
when /Integer/:
|
348
|
+
value.to_i
|
349
|
+
when /Boolean/:
|
350
|
+
!!value
|
351
|
+
else
|
352
|
+
value.to_s
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
369
356
|
end
|
357
|
+
|
370
358
|
end
|
371
359
|
|
372
|
-
end
|
360
|
+
end
|