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.
Files changed (168) hide show
  1. data/CHANGES +473 -0
  2. data/README +31 -0
  3. data/lib/selenium-client.rb +2 -0
  4. data/lib/selenium-webdriver.rb +1 -0
  5. data/lib/selenium/client.rb +37 -0
  6. data/lib/selenium/client/base.rb +118 -0
  7. data/lib/selenium/client/driver.rb +10 -0
  8. data/lib/selenium/client/errors.rb +9 -0
  9. data/lib/selenium/client/extensions.rb +118 -0
  10. data/lib/selenium/client/idiomatic.rb +488 -0
  11. data/lib/selenium/client/javascript_expression_builder.rb +116 -0
  12. data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
  13. data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
  14. data/lib/selenium/client/legacy_driver.rb +1720 -0
  15. data/lib/selenium/client/protocol.rb +104 -0
  16. data/lib/selenium/client/selenium_helper.rb +34 -0
  17. data/lib/selenium/rake/server_task.rb +157 -0
  18. data/lib/selenium/server.rb +223 -0
  19. data/lib/selenium/webdriver.rb +64 -0
  20. data/lib/selenium/webdriver/android.rb +9 -0
  21. data/lib/selenium/webdriver/android/bridge.rb +51 -0
  22. data/lib/selenium/webdriver/chrome.rb +26 -0
  23. data/lib/selenium/webdriver/chrome/bridge.rb +106 -0
  24. data/lib/selenium/webdriver/chrome/profile.rb +83 -0
  25. data/lib/selenium/webdriver/chrome/service.rb +74 -0
  26. data/lib/selenium/webdriver/common.rb +30 -0
  27. data/lib/selenium/webdriver/common/action_builder.rb +352 -0
  28. data/lib/selenium/webdriver/common/alert.rb +26 -0
  29. data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
  30. data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
  31. data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
  32. data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
  33. data/lib/selenium/webdriver/common/driver.rb +301 -0
  34. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
  35. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +44 -0
  36. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
  37. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
  38. data/lib/selenium/webdriver/common/element.rb +262 -0
  39. data/lib/selenium/webdriver/common/error.rb +212 -0
  40. data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
  41. data/lib/selenium/webdriver/common/keyboard.rb +52 -0
  42. data/lib/selenium/webdriver/common/keys.rb +109 -0
  43. data/lib/selenium/webdriver/common/mouse.rb +65 -0
  44. data/lib/selenium/webdriver/common/navigation.rb +43 -0
  45. data/lib/selenium/webdriver/common/options.rb +128 -0
  46. data/lib/selenium/webdriver/common/platform.rb +166 -0
  47. data/lib/selenium/webdriver/common/port_prober.rb +25 -0
  48. data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
  49. data/lib/selenium/webdriver/common/proxy.rb +120 -0
  50. data/lib/selenium/webdriver/common/search_context.rb +92 -0
  51. data/lib/selenium/webdriver/common/socket_poller.rb +100 -0
  52. data/lib/selenium/webdriver/common/target_locator.rb +81 -0
  53. data/lib/selenium/webdriver/common/timeouts.rb +29 -0
  54. data/lib/selenium/webdriver/common/wait.rb +60 -0
  55. data/lib/selenium/webdriver/common/window.rb +96 -0
  56. data/lib/selenium/webdriver/common/zipper.rb +82 -0
  57. data/lib/selenium/webdriver/firefox.rb +37 -0
  58. data/lib/selenium/webdriver/firefox/binary.rb +161 -0
  59. data/lib/selenium/webdriver/firefox/bridge.rb +58 -0
  60. data/lib/selenium/webdriver/firefox/extension.rb +52 -0
  61. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  62. data/lib/selenium/webdriver/firefox/launcher.rb +104 -0
  63. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  64. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  65. data/lib/selenium/webdriver/firefox/profile.rb +315 -0
  66. data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
  67. data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
  68. data/lib/selenium/webdriver/firefox/util.rb +29 -0
  69. data/lib/selenium/webdriver/ie.rb +19 -0
  70. data/lib/selenium/webdriver/ie/bridge.rb +60 -0
  71. data/lib/selenium/webdriver/ie/native/win32/IEDriver.dll +0 -0
  72. data/lib/selenium/webdriver/ie/native/x64/IEDriver.dll +0 -0
  73. data/lib/selenium/webdriver/ie/server.rb +64 -0
  74. data/lib/selenium/webdriver/iphone.rb +9 -0
  75. data/lib/selenium/webdriver/iphone/bridge.rb +50 -0
  76. data/lib/selenium/webdriver/opera.rb +24 -0
  77. data/lib/selenium/webdriver/opera/bridge.rb +113 -0
  78. data/lib/selenium/webdriver/opera/service.rb +49 -0
  79. data/lib/selenium/webdriver/remote.rb +21 -0
  80. data/lib/selenium/webdriver/remote/bridge.rb +473 -0
  81. data/lib/selenium/webdriver/remote/capabilities.rb +241 -0
  82. data/lib/selenium/webdriver/remote/commands.rb +181 -0
  83. data/lib/selenium/webdriver/remote/http/common.rb +74 -0
  84. data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
  85. data/lib/selenium/webdriver/remote/http/default.rb +102 -0
  86. data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
  87. data/lib/selenium/webdriver/remote/response.rb +99 -0
  88. data/lib/selenium/webdriver/remote/server_error.rb +17 -0
  89. data/lib/selenium/webdriver/support.rb +4 -0
  90. data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
  91. data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
  92. data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
  93. data/lib/selenium/webdriver/support/select.rb +293 -0
  94. data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
  95. data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
  96. data/spec/integration/selenium/client/api/click_spec.rb +39 -0
  97. data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
  98. data/spec/integration/selenium/client/api/element_spec.rb +14 -0
  99. data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
  100. data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
  101. data/spec/integration/selenium/client/api/screenshot_spec.rb +29 -0
  102. data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
  103. data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
  104. data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
  105. data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
  106. data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
  107. data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
  108. data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
  109. data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
  110. data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
  111. data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
  112. data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
  113. data/spec/integration/selenium/client/spec_helper.rb +125 -0
  114. data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
  115. data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +42 -0
  116. data/spec/integration/selenium/webdriver/driver_spec.rb +253 -0
  117. data/spec/integration/selenium/webdriver/element_spec.rb +185 -0
  118. data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
  119. data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
  120. data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
  121. data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
  122. data/spec/integration/selenium/webdriver/mouse_spec.rb +55 -0
  123. data/spec/integration/selenium/webdriver/navigation_spec.rb +44 -0
  124. data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
  125. data/spec/integration/selenium/webdriver/options_spec.rb +49 -0
  126. data/spec/integration/selenium/webdriver/remote/element_spec.rb +24 -0
  127. data/spec/integration/selenium/webdriver/spec_helper.rb +44 -0
  128. data/spec/integration/selenium/webdriver/spec_support.rb +13 -0
  129. data/spec/integration/selenium/webdriver/spec_support/guards.rb +86 -0
  130. data/spec/integration/selenium/webdriver/spec_support/helpers.rb +46 -0
  131. data/spec/integration/selenium/webdriver/spec_support/jruby_test_environment.rb +29 -0
  132. data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
  133. data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +199 -0
  134. data/spec/integration/selenium/webdriver/target_locator_spec.rb +170 -0
  135. data/spec/integration/selenium/webdriver/timeout_spec.rb +56 -0
  136. data/spec/integration/selenium/webdriver/window_spec.rb +56 -0
  137. data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
  138. data/spec/unit/selenium/client/base_spec.rb +239 -0
  139. data/spec/unit/selenium/client/extensions_spec.rb +174 -0
  140. data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
  141. data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
  142. data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
  143. data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
  144. data/spec/unit/selenium/client/protocol_spec.rb +124 -0
  145. data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
  146. data/spec/unit/selenium/client/spec_helper.rb +24 -0
  147. data/spec/unit/selenium/rake/task_spec.rb +79 -0
  148. data/spec/unit/selenium/server_spec.rb +131 -0
  149. data/spec/unit/selenium/webdriver/action_builder_spec.rb +90 -0
  150. data/spec/unit/selenium/webdriver/android/bridge_spec.rb +31 -0
  151. data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +94 -0
  152. data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
  153. data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
  154. data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
  155. data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +17 -0
  156. data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +30 -0
  157. data/spec/unit/selenium/webdriver/proxy_spec.rb +87 -0
  158. data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
  159. data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +111 -0
  160. data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
  161. data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +46 -0
  162. data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
  163. data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
  164. data/spec/unit/selenium/webdriver/spec_helper.rb +6 -0
  165. data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
  166. data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
  167. data/spec/unit/selenium/webdriver/wait_spec.rb +40 -0
  168. metadata +215 -0
@@ -0,0 +1,62 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Firefox
4
+
5
+ # @api private
6
+ class ProfilesIni
7
+
8
+ def initialize
9
+ @ini_path = File.join(Util.app_data_path, "profiles.ini")
10
+ @profile_paths = {}
11
+
12
+ parse if File.exist?(@ini_path)
13
+ end
14
+
15
+ def [](name)
16
+ path = @profile_paths[name]
17
+ path && Profile.new(path)
18
+ end
19
+
20
+ def refresh
21
+ @profile_paths.clear
22
+ parse
23
+ end
24
+
25
+ private
26
+
27
+ def parse
28
+ string = File.read @ini_path
29
+ name = nil
30
+ is_relative = nil
31
+ path = nil
32
+
33
+ string.split("\n").each do |line|
34
+ case line
35
+ when /^\[Profile/
36
+ if p = path_for(name, is_relative, path)
37
+ @profile_paths[name] = p
38
+ name, path = nil
39
+ end
40
+ when /^Name=(.+)$/
41
+ name = $1.strip
42
+ when /^IsRelative=(.+)$/
43
+ is_relative = $1.strip == "1"
44
+ when /^Path=(.+)$/
45
+ path = $1.strip
46
+ end
47
+ end
48
+
49
+ if p = path_for(name, is_relative, path)
50
+ @profile_paths[name] = p
51
+ end
52
+ end
53
+
54
+ def path_for(name, is_relative, path)
55
+ return unless [name, path].any?
56
+ path = is_relative ? File.join(Util.app_data_path, path) : path
57
+ end
58
+
59
+ end # ProfilesIni
60
+ end # Firefox
61
+ end # WebDriver
62
+ end # Selenium
@@ -0,0 +1,61 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Firefox
4
+
5
+ #
6
+ # @api private
7
+ #
8
+
9
+ class SocketLock
10
+
11
+ def initialize(port, timeout)
12
+ @port = port
13
+ @timeout = timeout
14
+ end
15
+
16
+ def locked(&blk)
17
+ lock
18
+
19
+ begin
20
+ yield
21
+ ensure
22
+ release
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def lock
29
+ max_time = Time.now + @timeout
30
+
31
+ until can_lock? || Time.now >= max_time
32
+ sleep 0.1
33
+ end
34
+
35
+ unless did_lock?
36
+ raise Error::WebDriverError, "unable to bind to locking port #{@port} within #{@timeout} seconds"
37
+ end
38
+ end
39
+
40
+ def release
41
+ @server && @server.close
42
+ end
43
+
44
+ def can_lock?
45
+ @server = TCPServer.new(Platform.localhost, @port)
46
+ ChildProcess.close_on_exec @server
47
+
48
+ true
49
+ rescue SocketError, Errno::EADDRINUSE, Errno::EBADF => ex
50
+ $stderr.puts "#{self}: #{ex.message}" if $DEBUG
51
+ false
52
+ end
53
+
54
+ def did_lock?
55
+ !!@server
56
+ end
57
+
58
+ end # SocketLock
59
+ end # Firefox
60
+ end # WebDriver
61
+ end # Selenium
@@ -0,0 +1,29 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Firefox
4
+
5
+ # @api private
6
+ module Util
7
+ module_function
8
+
9
+ def app_data_path
10
+ case Platform.os
11
+ when :windows
12
+ "#{ENV['APPDATA']}\\Mozilla\\Firefox"
13
+ when :macosx
14
+ "#{Platform.home}/Library/Application Support/Firefox"
15
+ when :unix, :linux
16
+ "#{Platform.home}/.mozilla/firefox"
17
+ else
18
+ raise "Unknown os: #{Platform.os}"
19
+ end
20
+ end
21
+
22
+ def stringified?(str)
23
+ str =~ /^".*"$/
24
+ end
25
+
26
+ end # Util
27
+ end # Firefox
28
+ end # WebDriver
29
+ end # Selenium
@@ -0,0 +1,19 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ # @api private
5
+ module IE
6
+ DLLS = {
7
+ :win32 => "#{WebDriver.root}/selenium/webdriver/ie/native/win32/IEDriver.dll",
8
+ :x64 => "#{WebDriver.root}/selenium/webdriver/ie/native/x64/IEDriver.dll"
9
+ }
10
+
11
+ DLLS.each { |k,v| DLLS[k] = Platform.cygwin_path(v, :dos => true) } if Platform.cygwin?
12
+ end
13
+ end
14
+ end
15
+
16
+ require 'ffi'
17
+
18
+ require 'selenium/webdriver/ie/server'
19
+ require 'selenium/webdriver/ie/bridge'
@@ -0,0 +1,60 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module IE
4
+
5
+ #
6
+ # @api private
7
+ #
8
+
9
+ class Bridge < Remote::Bridge
10
+
11
+ HOST = Platform.localhost
12
+ DEFAULT_PORT = 5555
13
+ DEFAULT_TIMEOUT = 30
14
+
15
+ def initialize(opts = {})
16
+ timeout = opts.delete(:timeout) { DEFAULT_TIMEOUT }
17
+ port = opts.delete(:port) { DEFAULT_PORT }
18
+ http_client = opts.delete(:http_client)
19
+
20
+ unless opts.empty?
21
+ raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
22
+ end
23
+
24
+ @server = Server.new
25
+ @port = @server.start Integer(port)
26
+
27
+ host = Platform.localhost
28
+ unless SocketPoller.new(host, @port, timeout).connected?
29
+ raise Error::WebDriverError, "unable to connect to IE server within #{timeout} seconds"
30
+ end
31
+
32
+ remote_opts = {
33
+ :url => "http://#{host}:#{@port}",
34
+ :desired_capabilities => :internet_explorer
35
+ }
36
+
37
+ remote_opts.merge!(:http_client => http_client) if http_client
38
+
39
+ super(remote_opts)
40
+ end
41
+
42
+ def browser
43
+ :internet_explorer
44
+ end
45
+
46
+ def driver_extensions
47
+ [DriverExtensions::TakesScreenshot, DriverExtensions::HasInputDevices]
48
+ end
49
+
50
+ def quit
51
+ super
52
+ @server.stop
53
+
54
+ nil
55
+ end
56
+
57
+ end # Bridge
58
+ end # IE
59
+ end # WebDriver
60
+ end # Selenium
@@ -0,0 +1,64 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module IE
4
+
5
+ #
6
+ # @api private
7
+ #
8
+
9
+ class Server
10
+ extend FFI::Library
11
+
12
+ if Platform.bitsize == 64
13
+ ffi_lib WebDriver::IE::DLLS[:x64]
14
+ else
15
+ ffi_lib WebDriver::IE::DLLS[:win32]
16
+ end
17
+
18
+ ffi_convention :stdcall
19
+
20
+ attach_function :start_server, :StartServer, [:int], :pointer
21
+ attach_function :stop_server, :StopServer, [:pointer], :void
22
+ attach_function :session_count, :GetServerSessionCount, [], :int
23
+ attach_function :current_port, :GetServerPort, [], :int
24
+ attach_function :is_running, :ServerIsRunning, [], :bool
25
+
26
+ def initialize
27
+ @handle = nil
28
+ end
29
+
30
+ #
31
+ # Starts the server, communicating on the specified port, if it is not already running
32
+ #
33
+
34
+ def start(start_port)
35
+ return port if running?
36
+ @handle = self.class.start_server(start_port)
37
+
38
+ start_port
39
+ end
40
+
41
+ def stop
42
+ return if session_count != 0 || @handle.nil?
43
+ self.class.stop_server @handle
44
+ @handle = nil
45
+ end
46
+
47
+ def running?
48
+ self.class.is_running
49
+ end
50
+
51
+ def port
52
+ self.class.current_port
53
+ end
54
+
55
+ private
56
+
57
+ def session_count
58
+ self.class.session_count
59
+ end
60
+
61
+ end # Server
62
+ end # IE
63
+ end # WebDriver
64
+ end # Selenium
@@ -0,0 +1,9 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module IPhone
4
+
5
+ end # IPhone
6
+ end # WebDriver
7
+ end # Selenium
8
+
9
+ require 'selenium/webdriver/iphone/bridge'
@@ -0,0 +1,50 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module IPhone
4
+ #
5
+ # @api private
6
+ #
7
+
8
+ class Bridge < Remote::Bridge
9
+
10
+ DEFAULT_URL = "http://#{Platform.localhost}:3001/hub/"
11
+
12
+ def initialize(opts = {})
13
+ remote_opts = {
14
+ :url => opts.fetch(:url, DEFAULT_URL),
15
+ :desired_capabilities => opts.fetch(:desired_capabilities, capabilities),
16
+ }
17
+
18
+ remote_opts[:http_client] = opts[:http_client] if opts.has_key?(:http_client)
19
+
20
+ super remote_opts
21
+ end
22
+
23
+ def browser
24
+ :iphone
25
+ end
26
+
27
+ def driver_extensions
28
+ [
29
+ DriverExtensions::TakesScreenshot,
30
+ DriverExtensions::HasInputDevices,
31
+ DriverExtensions::Rotatable
32
+ ]
33
+ end
34
+
35
+ def setScreenOrientation(orientation)
36
+ execute :setScreenOrientation, {}, :orientation => orientation
37
+ end
38
+
39
+ def getScreenOrientation
40
+ execute :getScreenOrientation
41
+ end
42
+
43
+ def capabilities
44
+ @capabilities ||= Remote::Capabilities.iphone
45
+ end
46
+
47
+ end # Bridge
48
+ end # IPhone
49
+ end # WebDriver
50
+ end # Selenium
@@ -0,0 +1,24 @@
1
+ require 'selenium/server'
2
+ require 'selenium/webdriver/opera/service'
3
+ require 'selenium/webdriver/opera/bridge'
4
+
5
+ module Selenium
6
+ module WebDriver
7
+
8
+ module Opera
9
+ def self.driver_path=(path)
10
+ Service.selenium_server_jar = path
11
+ end
12
+
13
+ def self.path=(path)
14
+ Platform.assert_executable path
15
+ @path = path
16
+ end
17
+
18
+ def self.path
19
+ @path ||= nil
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,113 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Opera
4
+
5
+ #
6
+ # @api private
7
+ #
8
+
9
+ LOGGING_LEVELS = [:severe, :warning, :info, :config, :fine, :finer, :finest, :all]
10
+
11
+ class Bridge < Remote::Bridge
12
+
13
+ def initialize(opts = {})
14
+ @service = Service.default_service :log => (opts[:logging_level] ? true : false)
15
+
16
+ http_client = opts.delete(:http_client)
17
+ caps = create_capabilities(opts)
18
+
19
+ @service.start
20
+
21
+ remote_opts = {
22
+ :url => @service.uri,
23
+ :desired_capabilities => caps
24
+ }
25
+
26
+ remote_opts.merge!(:http_client => http_client) if http_client
27
+
28
+ super(remote_opts)
29
+ end
30
+
31
+ def browser
32
+ :opera
33
+ end
34
+
35
+ def driver_extensions
36
+ [
37
+ DriverExtensions::HasInputDevices,
38
+ DriverExtensions::TakesScreenshot
39
+ ]
40
+ end
41
+
42
+ def capabilities
43
+ @capabilities ||= Remote::Capabilities.opera
44
+ end
45
+
46
+ def quit
47
+ super
48
+ ensure
49
+ @service.stop
50
+ end
51
+
52
+ private
53
+
54
+ def create_capabilities(opts)
55
+ original_opts = opts.dup
56
+
57
+ arguments = opts.delete(:arguments)
58
+ logging_level = opts.delete(:logging_level)
59
+ logging_file = opts.delete(:logging_file)
60
+ host = opts.delete(:host)
61
+ port = opts.delete(:port)
62
+ launcher = opts.delete(:launcher)
63
+ profile = opts.delete(:profile)
64
+ idle = opts.delete(:idle)
65
+ display = opts.delete(:display)
66
+ autostart = opts.delete(:autostart)
67
+ no_restart = opts.delete(:no_restart)
68
+ no_quit = opts.delete(:no_quit)
69
+ product = opts.delete(:product)
70
+
71
+ unless opts.empty?
72
+ raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
73
+ end
74
+
75
+ caps = Remote::Capabilities.opera
76
+
77
+ if arguments
78
+ unless arguments.kind_of? Array
79
+ raise ArgumentError, ':arguments must be an Array of Strings'
80
+ end
81
+
82
+ caps.merge! 'opera.arguments' => arguments.join(' ')
83
+ end
84
+
85
+ if logging_level
86
+ unless LOGGING_LEVELS.include?(logging_level)
87
+ raise ArgumentError,
88
+ "unknown logging level #{logging_level.inspect}, available levels: #{LOGGING_LEVELS.inspect}"
89
+ end
90
+
91
+ caps.merge! 'opera.logging.level' => logging_level.to_s.upcase
92
+ end
93
+
94
+ caps.merge! 'opera.logging.file' => logging_file if logging_file
95
+ caps.merge! 'opera.binary' => Opera.path if Opera.path
96
+ caps.merge! 'opera.host' => host if host
97
+ caps.merge! 'opera.port' => port.to_i if port
98
+ caps.merge! 'opera.launcher' => launcher if launcher
99
+ caps.merge! 'opera.profile' => profile if original_opts.has_key?(:profile)
100
+ caps.merge! 'opera.idle' => !!idle unless idle.nil?
101
+ caps.merge! 'opera.display' => display.to_i if display
102
+ caps.merge! 'opera.autostart' => !!autostart unless autostart.nil?
103
+ caps.merge! 'opera.no_restart' => !!no_restart unless no_restart.nil?
104
+ caps.merge! 'opera.no_quit' => !!no_quit unless no_quit.nil?
105
+ caps.merge! 'opera.product' => product if product
106
+
107
+ caps
108
+ end
109
+
110
+ end
111
+ end
112
+ end
113
+ end