bbc-selenium-webdriver 1.17.0
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/CHANGES +473 -0
- data/README +31 -0
- data/lib/selenium-client.rb +2 -0
- data/lib/selenium-webdriver.rb +1 -0
- data/lib/selenium/client.rb +37 -0
- data/lib/selenium/client/base.rb +118 -0
- data/lib/selenium/client/driver.rb +10 -0
- data/lib/selenium/client/errors.rb +9 -0
- data/lib/selenium/client/extensions.rb +118 -0
- data/lib/selenium/client/idiomatic.rb +488 -0
- data/lib/selenium/client/javascript_expression_builder.rb +116 -0
- data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
- data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
- data/lib/selenium/client/legacy_driver.rb +1720 -0
- data/lib/selenium/client/protocol.rb +104 -0
- data/lib/selenium/client/selenium_helper.rb +34 -0
- data/lib/selenium/rake/server_task.rb +157 -0
- data/lib/selenium/server.rb +223 -0
- data/lib/selenium/webdriver.rb +64 -0
- data/lib/selenium/webdriver/android.rb +9 -0
- data/lib/selenium/webdriver/android/bridge.rb +51 -0
- data/lib/selenium/webdriver/chrome.rb +26 -0
- data/lib/selenium/webdriver/chrome/bridge.rb +106 -0
- data/lib/selenium/webdriver/chrome/profile.rb +83 -0
- data/lib/selenium/webdriver/chrome/service.rb +74 -0
- data/lib/selenium/webdriver/common.rb +30 -0
- data/lib/selenium/webdriver/common/action_builder.rb +352 -0
- data/lib/selenium/webdriver/common/alert.rb +26 -0
- data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
- data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
- data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
- data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
- data/lib/selenium/webdriver/common/driver.rb +301 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
- data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +44 -0
- data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
- data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
- data/lib/selenium/webdriver/common/element.rb +262 -0
- data/lib/selenium/webdriver/common/error.rb +212 -0
- data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
- data/lib/selenium/webdriver/common/keyboard.rb +52 -0
- data/lib/selenium/webdriver/common/keys.rb +109 -0
- data/lib/selenium/webdriver/common/mouse.rb +65 -0
- data/lib/selenium/webdriver/common/navigation.rb +43 -0
- data/lib/selenium/webdriver/common/options.rb +128 -0
- data/lib/selenium/webdriver/common/platform.rb +166 -0
- data/lib/selenium/webdriver/common/port_prober.rb +25 -0
- data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
- data/lib/selenium/webdriver/common/proxy.rb +120 -0
- data/lib/selenium/webdriver/common/search_context.rb +92 -0
- data/lib/selenium/webdriver/common/socket_poller.rb +100 -0
- data/lib/selenium/webdriver/common/target_locator.rb +81 -0
- data/lib/selenium/webdriver/common/timeouts.rb +29 -0
- data/lib/selenium/webdriver/common/wait.rb +60 -0
- data/lib/selenium/webdriver/common/window.rb +96 -0
- data/lib/selenium/webdriver/common/zipper.rb +82 -0
- data/lib/selenium/webdriver/firefox.rb +37 -0
- data/lib/selenium/webdriver/firefox/binary.rb +161 -0
- data/lib/selenium/webdriver/firefox/bridge.rb +58 -0
- data/lib/selenium/webdriver/firefox/extension.rb +52 -0
- data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
- data/lib/selenium/webdriver/firefox/launcher.rb +104 -0
- data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
- data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
- data/lib/selenium/webdriver/firefox/profile.rb +315 -0
- data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
- data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
- data/lib/selenium/webdriver/firefox/util.rb +29 -0
- data/lib/selenium/webdriver/ie.rb +19 -0
- data/lib/selenium/webdriver/ie/bridge.rb +60 -0
- data/lib/selenium/webdriver/ie/native/win32/IEDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/native/x64/IEDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/server.rb +64 -0
- data/lib/selenium/webdriver/iphone.rb +9 -0
- data/lib/selenium/webdriver/iphone/bridge.rb +50 -0
- data/lib/selenium/webdriver/opera.rb +24 -0
- data/lib/selenium/webdriver/opera/bridge.rb +113 -0
- data/lib/selenium/webdriver/opera/service.rb +49 -0
- data/lib/selenium/webdriver/remote.rb +21 -0
- data/lib/selenium/webdriver/remote/bridge.rb +473 -0
- data/lib/selenium/webdriver/remote/capabilities.rb +241 -0
- data/lib/selenium/webdriver/remote/commands.rb +181 -0
- data/lib/selenium/webdriver/remote/http/common.rb +74 -0
- data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
- data/lib/selenium/webdriver/remote/http/default.rb +102 -0
- data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
- data/lib/selenium/webdriver/remote/response.rb +99 -0
- data/lib/selenium/webdriver/remote/server_error.rb +17 -0
- data/lib/selenium/webdriver/support.rb +4 -0
- data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
- data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
- data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
- data/lib/selenium/webdriver/support/select.rb +293 -0
- data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
- data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
- data/spec/integration/selenium/client/api/click_spec.rb +39 -0
- data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
- data/spec/integration/selenium/client/api/element_spec.rb +14 -0
- data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
- data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
- data/spec/integration/selenium/client/api/screenshot_spec.rb +29 -0
- data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
- data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
- data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
- data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
- data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
- data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
- data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
- data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
- data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
- data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
- data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
- data/spec/integration/selenium/client/spec_helper.rb +125 -0
- data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
- data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +42 -0
- data/spec/integration/selenium/webdriver/driver_spec.rb +253 -0
- data/spec/integration/selenium/webdriver/element_spec.rb +185 -0
- data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
- data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
- data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
- data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
- data/spec/integration/selenium/webdriver/mouse_spec.rb +55 -0
- data/spec/integration/selenium/webdriver/navigation_spec.rb +44 -0
- data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
- data/spec/integration/selenium/webdriver/options_spec.rb +49 -0
- data/spec/integration/selenium/webdriver/remote/element_spec.rb +24 -0
- data/spec/integration/selenium/webdriver/spec_helper.rb +44 -0
- data/spec/integration/selenium/webdriver/spec_support.rb +13 -0
- data/spec/integration/selenium/webdriver/spec_support/guards.rb +86 -0
- data/spec/integration/selenium/webdriver/spec_support/helpers.rb +46 -0
- data/spec/integration/selenium/webdriver/spec_support/jruby_test_environment.rb +29 -0
- data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
- data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +199 -0
- data/spec/integration/selenium/webdriver/target_locator_spec.rb +170 -0
- data/spec/integration/selenium/webdriver/timeout_spec.rb +56 -0
- data/spec/integration/selenium/webdriver/window_spec.rb +56 -0
- data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
- data/spec/unit/selenium/client/base_spec.rb +239 -0
- data/spec/unit/selenium/client/extensions_spec.rb +174 -0
- data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
- data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
- data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
- data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
- data/spec/unit/selenium/client/protocol_spec.rb +124 -0
- data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
- data/spec/unit/selenium/client/spec_helper.rb +24 -0
- data/spec/unit/selenium/rake/task_spec.rb +79 -0
- data/spec/unit/selenium/server_spec.rb +131 -0
- data/spec/unit/selenium/webdriver/action_builder_spec.rb +90 -0
- data/spec/unit/selenium/webdriver/android/bridge_spec.rb +31 -0
- data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +94 -0
- data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
- data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
- data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
- data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +17 -0
- data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +30 -0
- data/spec/unit/selenium/webdriver/proxy_spec.rb +87 -0
- data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
- data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +111 -0
- data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
- data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +46 -0
- data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
- data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
- data/spec/unit/selenium/webdriver/spec_helper.rb +6 -0
- data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
- data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
- data/spec/unit/selenium/webdriver/wait_spec.rb +40 -0
- metadata +215 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
require 'rbconfig'
|
|
2
|
+
require 'socket'
|
|
3
|
+
|
|
4
|
+
module Selenium
|
|
5
|
+
module WebDriver
|
|
6
|
+
|
|
7
|
+
# @api private
|
|
8
|
+
module Platform
|
|
9
|
+
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def home
|
|
13
|
+
# jruby has an issue with ENV['HOME'] on Windows
|
|
14
|
+
@home ||= jruby? ? ENV_JAVA['user.home'] : ENV['HOME']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def engine
|
|
18
|
+
@engine ||= (
|
|
19
|
+
if defined? RUBY_ENGINE
|
|
20
|
+
RUBY_ENGINE.to_sym
|
|
21
|
+
else
|
|
22
|
+
:ruby
|
|
23
|
+
end
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def os
|
|
28
|
+
@os ||= (
|
|
29
|
+
host_os = RbConfig::CONFIG['host_os']
|
|
30
|
+
case host_os
|
|
31
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
|
32
|
+
:windows
|
|
33
|
+
when /darwin|mac os/
|
|
34
|
+
:macosx
|
|
35
|
+
when /linux/
|
|
36
|
+
:linux
|
|
37
|
+
when /solaris|bsd/
|
|
38
|
+
:unix
|
|
39
|
+
else
|
|
40
|
+
raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
|
|
41
|
+
end
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def bitsize
|
|
46
|
+
@bitsize ||= (
|
|
47
|
+
if defined?(FFI::Platform::ADDRESS_SIZE)
|
|
48
|
+
FFI::Platform::ADDRESS_SIZE
|
|
49
|
+
elsif defined?(FFI)
|
|
50
|
+
FFI.type_size(:pointer) == 4 ? 32 : 64
|
|
51
|
+
elsif jruby?
|
|
52
|
+
Integer(ENV_JAVA['sun.arch.data.model'])
|
|
53
|
+
else
|
|
54
|
+
1.size == 4 ? 32 : 64
|
|
55
|
+
end
|
|
56
|
+
)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def jruby?
|
|
60
|
+
engine == :jruby
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def ironruby?
|
|
64
|
+
engine == :ironruby
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def ruby187?
|
|
68
|
+
!!(RUBY_VERSION =~ /^1\.8\.7/)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def ruby19?
|
|
72
|
+
!!(RUBY_VERSION =~ /^1\.9/)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def windows?
|
|
76
|
+
os == :windows
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def mac?
|
|
80
|
+
os == :macosx
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def linux?
|
|
84
|
+
os == :linux
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def cygwin?
|
|
88
|
+
!!(RUBY_PLATFORM =~ /cygwin/)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def wrap_in_quotes_if_necessary(str)
|
|
92
|
+
windows? && !cygwin? ? %{"#{str}"} : str
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def cygwin_path(path, opts = {})
|
|
96
|
+
flags = []
|
|
97
|
+
opts.each { |k,v| flags << "--#{k}" if v }
|
|
98
|
+
|
|
99
|
+
`cygpath #{flags.join ' '} "#{path}"`.strip
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def make_writable(file)
|
|
103
|
+
File.chmod 0766, file
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def assert_file(path)
|
|
107
|
+
unless File.file? path
|
|
108
|
+
raise Error::WebDriverError, "not a file: #{path.inspect}"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def assert_executable(path)
|
|
113
|
+
assert_file(path)
|
|
114
|
+
|
|
115
|
+
unless File.executable? path
|
|
116
|
+
raise Error::WebDriverError, "not executable: #{path.inspect}"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def exit_hook(&blk)
|
|
121
|
+
pid = Process.pid
|
|
122
|
+
|
|
123
|
+
at_exit do
|
|
124
|
+
yield if Process.pid == pid
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def find_binary(*binary_names)
|
|
129
|
+
paths = ENV['PATH'].split(File::PATH_SEPARATOR)
|
|
130
|
+
binary_names.map! { |n| "#{n}.exe" } if windows?
|
|
131
|
+
|
|
132
|
+
binary_names.each do |binary_name|
|
|
133
|
+
paths.each do |path|
|
|
134
|
+
exe = File.join(path, binary_name)
|
|
135
|
+
return exe if File.executable?(exe)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
nil
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def localhost
|
|
143
|
+
info = Socket.getaddrinfo "localhost", 80, Socket::AF_INET, Socket::SOCK_STREAM
|
|
144
|
+
|
|
145
|
+
if info.empty?
|
|
146
|
+
raise Error::WebDriverError, "unable to translate 'localhost' for TCP + IPv4"
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
info[0][3]
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
end # Platform
|
|
153
|
+
end # WebDriver
|
|
154
|
+
end # Selenium
|
|
155
|
+
|
|
156
|
+
if __FILE__ == $0
|
|
157
|
+
p :engine => Selenium::WebDriver::Platform.engine,
|
|
158
|
+
:os => Selenium::WebDriver::Platform.os,
|
|
159
|
+
:ruby187? => Selenium::WebDriver::Platform.ruby187?,
|
|
160
|
+
:ruby19? => Selenium::WebDriver::Platform.ruby19?,
|
|
161
|
+
:jruby? => Selenium::WebDriver::Platform.jruby?,
|
|
162
|
+
:windows? => Selenium::WebDriver::Platform.windows?,
|
|
163
|
+
:home => Selenium::WebDriver::Platform.home,
|
|
164
|
+
:bitsize => Selenium::WebDriver::Platform.bitsize,
|
|
165
|
+
:localhost => Selenium::WebDriver::Platform.localhost
|
|
166
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Selenium
|
|
2
|
+
module WebDriver
|
|
3
|
+
class PortProber
|
|
4
|
+
def self.above(port)
|
|
5
|
+
port += 1 until free? port
|
|
6
|
+
port
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.random
|
|
10
|
+
server = TCPServer.new(Platform.localhost, 0)
|
|
11
|
+
port = server.addr[1]
|
|
12
|
+
server.close
|
|
13
|
+
|
|
14
|
+
port
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.free?(port)
|
|
18
|
+
TCPServer.new(Platform.localhost, port).close
|
|
19
|
+
true
|
|
20
|
+
rescue SocketError, Errno::EADDRINUSE
|
|
21
|
+
false
|
|
22
|
+
end
|
|
23
|
+
end # PortProber
|
|
24
|
+
end # WebDriver
|
|
25
|
+
end # Selenium
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module Selenium
|
|
2
|
+
module WebDriver
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# @api private
|
|
6
|
+
#
|
|
7
|
+
# Common methods for Chrome::Profile and Firefox::Profile
|
|
8
|
+
# Includers must implement #layout_on_disk
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
module ProfileHelper
|
|
12
|
+
|
|
13
|
+
def self.included(base)
|
|
14
|
+
base.extend ClassMethods
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def as_json(opts = nil)
|
|
18
|
+
{'zip' => Zipper.zip(layout_on_disk)}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_json(*args)
|
|
22
|
+
MultiJson.encode as_json
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def create_tmp_copy(directory)
|
|
28
|
+
tmp_directory = Dir.mktmpdir("webdriver-rb-profilecopy")
|
|
29
|
+
|
|
30
|
+
# TODO: must be a better way..
|
|
31
|
+
FileUtils.rm_rf tmp_directory
|
|
32
|
+
FileUtils.mkdir_p File.dirname(tmp_directory), :mode => 0700
|
|
33
|
+
FileUtils.cp_r directory, tmp_directory
|
|
34
|
+
|
|
35
|
+
tmp_directory
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def verify_model(model)
|
|
39
|
+
return unless model
|
|
40
|
+
|
|
41
|
+
raise Errno::ENOENT, model unless File.exist?(model)
|
|
42
|
+
raise Errno::ENOTDIR, model unless File.directory?(model)
|
|
43
|
+
|
|
44
|
+
model
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
module ClassMethods
|
|
48
|
+
def from_json(json)
|
|
49
|
+
data = MultiJson.decode(json).fetch('zip')
|
|
50
|
+
|
|
51
|
+
# can't use Tempfile here since it doesn't support File::BINARY mode on 1.8
|
|
52
|
+
# can't use Dir.mktmpdir(&blk) because of http://jira.codehaus.org/browse/JRUBY-4082
|
|
53
|
+
tmp_dir = Dir.mktmpdir
|
|
54
|
+
begin
|
|
55
|
+
zip_path = File.join(tmp_dir, "webdriver-profile-duplicate-#{json.hash}.zip")
|
|
56
|
+
File.open(zip_path, "wb") { |zip_file| zip_file << Base64.decode64(data) }
|
|
57
|
+
|
|
58
|
+
new Zipper.unzip(zip_path)
|
|
59
|
+
ensure
|
|
60
|
+
FileUtils.rm_rf tmp_dir
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end # ClassMethods
|
|
64
|
+
|
|
65
|
+
end # ProfileHelper
|
|
66
|
+
end # WebDriver
|
|
67
|
+
end # Selenium
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
module Selenium
|
|
2
|
+
module WebDriver
|
|
3
|
+
class Proxy
|
|
4
|
+
TYPES = {
|
|
5
|
+
:direct => "DIRECT", # Direct connection, no proxy (default on Windows).
|
|
6
|
+
:manual => "MANUAL", # Manual proxy settings (e.g., for httpProxy).
|
|
7
|
+
:pac => "PAC", # Proxy autoconfiguration from URL.
|
|
8
|
+
:auto_detect => "AUTODETECT", # Proxy autodetection (presumably with WPAD).
|
|
9
|
+
:system => "SYSTEM" # Use system settings (default on Linux).
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
attr_reader :type,
|
|
13
|
+
:ftp,
|
|
14
|
+
:http,
|
|
15
|
+
:no_proxy,
|
|
16
|
+
:pac,
|
|
17
|
+
:ssl,
|
|
18
|
+
:auto_detect
|
|
19
|
+
|
|
20
|
+
def initialize(opts = {})
|
|
21
|
+
opts = opts.dup
|
|
22
|
+
|
|
23
|
+
self.type = opts.delete(:type) if opts.has_key? :type
|
|
24
|
+
self.ftp = opts.delete(:ftp) if opts.has_key? :ftp
|
|
25
|
+
self.http = opts.delete(:http) if opts.has_key? :http
|
|
26
|
+
self.no_proxy = opts.delete(:no_proxy) if opts.has_key? :no_proxy
|
|
27
|
+
self.ssl = opts.delete(:ssl) if opts.has_key? :ssl
|
|
28
|
+
self.pac = opts.delete(:pac) if opts.has_key? :pac
|
|
29
|
+
self.auto_detect = opts.delete(:auto_detect) if opts.has_key? :auto_detect
|
|
30
|
+
|
|
31
|
+
unless opts.empty?
|
|
32
|
+
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def ==(other)
|
|
37
|
+
other.kind_of?(self.class) && as_json == other.as_json
|
|
38
|
+
end
|
|
39
|
+
alias_method :eql?, :==
|
|
40
|
+
|
|
41
|
+
def ftp=(value)
|
|
42
|
+
self.type = :manual
|
|
43
|
+
@ftp = value
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def http=(value)
|
|
47
|
+
self.type = :manual
|
|
48
|
+
@http = value
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def no_proxy=(value)
|
|
52
|
+
self.type = :manual
|
|
53
|
+
@no_proxy = value
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def ssl=(value)
|
|
57
|
+
self.type = :manual
|
|
58
|
+
@ssl = value
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def pac=(url)
|
|
62
|
+
self.type = :pac
|
|
63
|
+
@pac = url
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def auto_detect=(bool)
|
|
67
|
+
self.type = :auto_detect
|
|
68
|
+
@auto_detect = bool
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def type=(type)
|
|
72
|
+
unless TYPES.has_key? type
|
|
73
|
+
raise ArgumentError, "invalid proxy type: #{type.inspect}, expected one of #{TYPES.keys.inspect}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
if defined?(@type) && type != @type
|
|
77
|
+
raise ArgumentError, "incompatible proxy type #{type.inspect} (already set to #{@type.inspect})"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
@type = type
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def as_json(opts = nil)
|
|
84
|
+
json_result = {
|
|
85
|
+
"proxyType" => TYPES[type]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
json_result["ftpProxy"] = ftp if ftp
|
|
89
|
+
json_result["httpProxy"] = http if http
|
|
90
|
+
json_result["noProxy"] = no_proxy if no_proxy
|
|
91
|
+
json_result["proxyAutoconfigUrl"] = pac if pac
|
|
92
|
+
json_result["sslProxy"] = ssl if ssl
|
|
93
|
+
json_result["autodetect"] = auto_detect if auto_detect
|
|
94
|
+
|
|
95
|
+
json_result if json_result.length > 1
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def to_json(*args)
|
|
99
|
+
MultiJson.encode as_json
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
class << self
|
|
103
|
+
def json_create(data)
|
|
104
|
+
proxy = new
|
|
105
|
+
|
|
106
|
+
proxy.type = data['proxyType'].downcase.to_sym if data.has_key? 'proxyType'
|
|
107
|
+
proxy.ftp = data['ftpProxy'] if data.has_key? 'ftpProxy'
|
|
108
|
+
proxy.http = data['httpProxy'] if data.has_key? 'httpProxy'
|
|
109
|
+
proxy.no_proxy = data['noProxy'] if data.has_key? 'noProxy'
|
|
110
|
+
proxy.pac = data['proxyAutoconfigUrl'] if data.has_key? 'proxyAutoconfigUrl'
|
|
111
|
+
proxy.ssl = data['sslProxy'] if data.has_key? 'sslProxy'
|
|
112
|
+
proxy.auto_detect = data['autodetect'] if data.has_key? 'autodetect'
|
|
113
|
+
|
|
114
|
+
proxy
|
|
115
|
+
end
|
|
116
|
+
end # class << self
|
|
117
|
+
|
|
118
|
+
end # Proxy
|
|
119
|
+
end # WebDriver
|
|
120
|
+
end # Selenium
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module Selenium
|
|
2
|
+
module WebDriver
|
|
3
|
+
module SearchContext
|
|
4
|
+
|
|
5
|
+
# @api private
|
|
6
|
+
FINDERS = {
|
|
7
|
+
:class => 'class name',
|
|
8
|
+
:class_name => 'class name',
|
|
9
|
+
:css => 'css selector',
|
|
10
|
+
:id => 'id',
|
|
11
|
+
:link => 'link text',
|
|
12
|
+
:link_text => 'link text',
|
|
13
|
+
:name => 'name',
|
|
14
|
+
:partial_link_text => 'partial link text',
|
|
15
|
+
:tag_name => 'tag name',
|
|
16
|
+
:xpath => 'xpath',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#
|
|
20
|
+
# Find the first element matching the given arguments.
|
|
21
|
+
#
|
|
22
|
+
# When using Element#find_element with :xpath, be aware that webdriver
|
|
23
|
+
# follows standard conventions: a search prefixed with "//" will search
|
|
24
|
+
# the entire document, not just the children of this current node. Use
|
|
25
|
+
# ".//" to limit your search to the children of the receiving Element.
|
|
26
|
+
#
|
|
27
|
+
# @param [:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath] how
|
|
28
|
+
# @param [String] what
|
|
29
|
+
# @return [Element]
|
|
30
|
+
#
|
|
31
|
+
# @raise [Error::NoSuchElementError] if the element doesn't exist
|
|
32
|
+
#
|
|
33
|
+
#
|
|
34
|
+
|
|
35
|
+
def find_element(*args)
|
|
36
|
+
how, what = extract_args(args)
|
|
37
|
+
|
|
38
|
+
unless by = FINDERS[how.to_sym]
|
|
39
|
+
raise ArgumentError, "cannot find element by #{how.inspect}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
bridge.find_element_by by, what.to_s, ref
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
#
|
|
46
|
+
# Find all elements matching the given arguments
|
|
47
|
+
#
|
|
48
|
+
# @see SearchContext#find_element
|
|
49
|
+
#
|
|
50
|
+
# @param [:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath] how
|
|
51
|
+
# @param [String] what
|
|
52
|
+
# @return [Array<Element>]
|
|
53
|
+
#
|
|
54
|
+
|
|
55
|
+
def find_elements(*args)
|
|
56
|
+
how, what = extract_args(args)
|
|
57
|
+
|
|
58
|
+
unless by = FINDERS[how.to_sym]
|
|
59
|
+
raise ArgumentError, "cannot find elements by #{how.inspect}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
bridge.find_elements_by by, what.to_s, ref
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def extract_args(args)
|
|
68
|
+
case args.size
|
|
69
|
+
when 2
|
|
70
|
+
args
|
|
71
|
+
when 1
|
|
72
|
+
arg = args.first
|
|
73
|
+
|
|
74
|
+
unless arg.respond_to?(:shift)
|
|
75
|
+
raise ArgumentError, "expected #{arg.inspect}:#{arg.class} to respond to #shift"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# this will be a single-entry hash, so use #shift over #first or #[]
|
|
79
|
+
arr = arg.dup.shift
|
|
80
|
+
unless arr.size == 2
|
|
81
|
+
raise ArgumentError, "expected #{arr.inspect} to have 2 elements"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
arr
|
|
85
|
+
else
|
|
86
|
+
raise ArgumentError, "wrong number of arguments (#{args.size} for 2)"
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end # SearchContext
|
|
91
|
+
end # WebDriver
|
|
92
|
+
end # Selenium
|