bbc-selenium-webdriver 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
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,79 @@
1
+ require 'curb'
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Remote
6
+
7
+ # added for rescue
8
+ Bridge::QUIT_ERRORS << Curl::Err::RecvError
9
+
10
+ module Http
11
+
12
+ #
13
+ # An alternative to the default Net::HTTP client.
14
+ #
15
+ # This can be used for the Firefox and Remote drivers if you have Curb
16
+ # installed.
17
+ #
18
+ # @example Using Curb
19
+ # require 'selenium/webdriver/remote/http/curb'
20
+ # include Selenium
21
+ #
22
+ # driver = WebDriver.for :firefox, :http_client => WebDriver::Remote::Http::Curb.new
23
+ #
24
+
25
+ class Curb < Common
26
+
27
+ private
28
+
29
+ def request(verb, url, headers, payload)
30
+ client.url = url.to_s
31
+
32
+ # workaround for http://github.com/taf2/curb/issues/issue/40
33
+ # curb will handle this for us anyway
34
+ headers.delete "Content-Length"
35
+
36
+ client.headers = headers
37
+
38
+ # http://github.com/taf2/curb/issues/issue/33
39
+ client.head = false
40
+ client.delete = false
41
+
42
+ case verb
43
+ when :get
44
+ client.http_get
45
+ when :post
46
+ client.post_body = payload || ""
47
+ client.http_post
48
+ when :put
49
+ client.put_data = payload || ""
50
+ client.http_put
51
+ when :delete
52
+ client.http_delete
53
+ when :head
54
+ client.http_head
55
+ else
56
+ raise Error::WebDriverError, "unknown HTTP verb: #{verb.inspect}"
57
+ end
58
+
59
+ create_response client.response_code, client.body_str, client.content_type
60
+ end
61
+
62
+ def client
63
+ @client ||= (
64
+ c = Curl::Easy.new
65
+
66
+ c.max_redirects = MAX_REDIRECTS
67
+ c.follow_location = true
68
+ c.timeout = @timeout if @timeout
69
+ c.verbose = !!$DEBUG
70
+
71
+ c
72
+ )
73
+ end
74
+
75
+ end # Curb
76
+ end # Http
77
+ end # Remote
78
+ end # WebDriver
79
+ end # Selenium
@@ -0,0 +1,102 @@
1
+ require 'net/https'
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Remote
6
+ module Http
7
+
8
+ # @api private
9
+ class Default < Common
10
+ attr_accessor :proxy
11
+
12
+ private
13
+
14
+ def initialize
15
+ super
16
+ @proxy = nil
17
+ end
18
+
19
+ def http
20
+ @http ||= (
21
+ http = new_http_client
22
+ if server_url.scheme == "https"
23
+ http.use_ssl = true
24
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
25
+ end
26
+
27
+ if @timeout
28
+ http.open_timeout = @timeout
29
+ http.read_timeout = @timeout
30
+ end
31
+
32
+ http
33
+ )
34
+ end
35
+
36
+ MAX_RETRIES = 3
37
+
38
+ def request(verb, url, headers, payload, redirects = 0)
39
+ request = new_request_for(verb, url, headers, payload)
40
+
41
+ retries = 0
42
+ begin
43
+ response = response_for(request)
44
+ rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EADDRINUSE
45
+ # a retry is sometimes needed on Windows XP where we may quickly
46
+ # run out of ephemeral ports
47
+ #
48
+ # A more robust solution is bumping the MaxUserPort setting
49
+ # as described here:
50
+ #
51
+ # http://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx
52
+ raise if retries >= MAX_RETRIES
53
+
54
+ request = new_request_for(verb, url, headers, payload)
55
+ retries += 1
56
+
57
+ retry
58
+ end
59
+
60
+ if response.kind_of? Net::HTTPRedirection
61
+ raise Error::WebDriverError, "too many redirects" if redirects >= MAX_REDIRECTS
62
+ request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)
63
+ else
64
+ create_response response.code, response.body, response.content_type
65
+ end
66
+ end
67
+
68
+ def new_request_for(verb, url, headers, payload)
69
+ req = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)
70
+
71
+ if server_url.userinfo
72
+ req.basic_auth server_url.user, server_url.password
73
+ end
74
+
75
+ req.body = payload if payload
76
+
77
+ req
78
+ end
79
+
80
+ def response_for(request)
81
+ http.request request
82
+ end
83
+
84
+ def new_http_client
85
+ if @proxy
86
+ unless @proxy.respond_to?(:http) && url = @proxy.http
87
+ raise Error::WebDriverError, "expected HTTP proxy, got #{@proxy.inspect}"
88
+ end
89
+ proxy = URI.parse(url)
90
+
91
+ clazz = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password)
92
+ clazz.new(server_url.host, server_url.port)
93
+ else
94
+ Net::HTTP.new server_url.host, server_url.port
95
+ end
96
+ end
97
+
98
+ end # Default
99
+ end # Http
100
+ end # Remote
101
+ end # WebDriver
102
+ end # Selenium
@@ -0,0 +1,38 @@
1
+ require 'net/http/persistent'
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Remote
6
+ module Http
7
+
8
+ # @api private
9
+ class Persistent < Default
10
+
11
+ def close
12
+ @http.shutdown if @http
13
+ end
14
+
15
+ private
16
+
17
+ def new_http_client
18
+ proxy = nil
19
+
20
+ if @proxy
21
+ unless @proxy.respond_to?(:http) && url = @proxy.http
22
+ raise Error::WebDriverError, "expected HTTP proxy, got #{@proxy.inspect}"
23
+ end
24
+ proxy = URI.parse(url)
25
+ end
26
+
27
+ Net::HTTP::Persistent.new "webdriver", proxy
28
+ end
29
+
30
+ def response_for(request)
31
+ http.request server_url, request
32
+ end
33
+
34
+ end # Persistent
35
+ end # Http
36
+ end # Remote
37
+ end # WebDriver
38
+ end # Selenium
@@ -0,0 +1,99 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Remote
4
+
5
+ # @api private
6
+ class Response
7
+
8
+ attr_reader :code, :payload
9
+ attr_writer :payload
10
+
11
+ def initialize(code, payload = nil)
12
+ @code = code
13
+ @payload = payload || {}
14
+
15
+ assert_ok
16
+ end
17
+
18
+ def error
19
+ klass = Error.for_code(status) || return
20
+
21
+ ex = klass.new(error_message)
22
+ ex.set_backtrace(caller)
23
+ add_backtrace ex
24
+
25
+ ex
26
+ end
27
+
28
+ def error_message
29
+ val = value
30
+
31
+ case val
32
+ when Hash
33
+ msg = val['message'] or return "unknown error"
34
+ msg << " (#{ val['class'] })" if val['class']
35
+ when String
36
+ msg = val
37
+ else
38
+ msg = "unknown error, status=#{status}: #{val.inspect}"
39
+ end
40
+
41
+ msg
42
+ end
43
+
44
+ def [](key)
45
+ @payload[key]
46
+ end
47
+
48
+ private
49
+
50
+ def assert_ok
51
+ if @code.nil? || @code >= 400
52
+ if e = error()
53
+ raise e
54
+ else
55
+ raise Error::ServerError, self
56
+ end
57
+ end
58
+ end
59
+
60
+ def add_backtrace(ex)
61
+ unless value.kind_of?(Hash) && value['stackTrace']
62
+ return
63
+ end
64
+
65
+ server_trace = value['stackTrace']
66
+
67
+ backtrace = server_trace.map do |frame|
68
+ next unless frame.kind_of?(Hash)
69
+
70
+ file = frame['fileName']
71
+ line = frame['lineNumber']
72
+ meth = frame['methodName']
73
+
74
+ if class_name = frame['className']
75
+ file = "#{class_name}(#{file})"
76
+ end
77
+
78
+ if meth.nil? || meth.empty?
79
+ meth = 'unknown'
80
+ end
81
+
82
+ "[remote server] #{file}:#{line}:in `#{meth}'"
83
+ end.compact
84
+
85
+ ex.set_backtrace(backtrace + ex.backtrace)
86
+ end
87
+
88
+ def status
89
+ @payload['status']
90
+ end
91
+
92
+ def value
93
+ @payload['value']
94
+ end
95
+
96
+ end # Response
97
+ end # Remote
98
+ end # WebDriver
99
+ end # Selenium
@@ -0,0 +1,17 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Error
4
+ class ServerError < StandardError
5
+
6
+ def initialize(response)
7
+ if response.kind_of? String
8
+ super(response)
9
+ else
10
+ super("status code #{response.code}")
11
+ end
12
+ end
13
+ end
14
+
15
+ end # Error
16
+ end # WebDriver
17
+ end # Selenium
@@ -0,0 +1,4 @@
1
+ require 'selenium/webdriver/support/event_firing_bridge'
2
+ require 'selenium/webdriver/support/abstract_event_listener'
3
+ require 'selenium/webdriver/support/block_event_listener'
4
+ require 'selenium/webdriver/support/select'
@@ -0,0 +1,28 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Support
4
+
5
+ class AbstractEventListener
6
+ def before_navigate_to(url, driver) end
7
+ def after_navigate_to(url, driver) end
8
+ def before_navigate_back(driver) end
9
+ def after_navigate_back(driver) end
10
+ def before_navigate_forward(driver) end
11
+ def after_navigate_forward(driver) end
12
+ def before_find(by, what, driver) end
13
+ def after_find(by, what, driver) end
14
+ def before_click(element, driver) end
15
+ def after_click(element, driver) end
16
+ def before_change_value_of(element, driver) end
17
+ def after_change_value_of(element, driver) end
18
+ def before_execute_script(script, driver) end
19
+ def after_execute_script(script, driver) end
20
+ def before_quit(driver) end
21
+ def after_quit(driver) end
22
+ def before_close(driver) end
23
+ def after_close(driver) end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Support
4
+
5
+ class BlockEventListener
6
+ def initialize(callback)
7
+ @callback = callback
8
+ end
9
+
10
+ def method_missing(meth, *args, &blk)
11
+ @callback.call meth, *args
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,112 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Support
4
+
5
+ #
6
+ # @api private
7
+ #
8
+
9
+ class EventFiringBridge
10
+ def initialize(delegate, listener)
11
+ @delegate = delegate
12
+
13
+ if listener.respond_to? :call
14
+ @listener = BlockEventListener.new(listener)
15
+ else
16
+ @listener = listener
17
+ end
18
+ end
19
+
20
+ def get(url)
21
+ dispatch(:navigate_to, url, driver) {
22
+ @delegate.get(url)
23
+ }
24
+ end
25
+
26
+ def goForward
27
+ dispatch(:navigate_forward, driver) {
28
+ @delegate.goForward
29
+ }
30
+ end
31
+
32
+ def goBack
33
+ dispatch(:navigate_back, driver) {
34
+ @delegate.goBack
35
+ }
36
+ end
37
+
38
+ def clickElement(ref)
39
+ dispatch(:click, create_element(ref), driver) {
40
+ @delegate.clickElement(ref)
41
+ }
42
+ end
43
+
44
+ def clearElement(ref)
45
+ dispatch(:change_value_of, create_element(ref), driver) {
46
+ @delegate.clearElement(ref)
47
+ }
48
+ end
49
+
50
+ def sendKeysToElement(ref, keys)
51
+ dispatch(:change_value_of, create_element(ref), driver) {
52
+ @delegate.sendKeysToElement(ref, keys)
53
+ }
54
+ end
55
+
56
+ def find_element_by(how, what, parent = nil)
57
+ e = dispatch(:find, how, what, driver) {
58
+ @delegate.find_element_by how, what, parent
59
+ }
60
+
61
+ Element.new self, e.ref
62
+ end
63
+
64
+ def find_elements_by(how, what, parent = nil)
65
+ es = dispatch(:find, how, what, driver) {
66
+ @delegate.find_elements_by(how, what, parent)
67
+ }
68
+
69
+ es.map { |e| Element.new self, e.ref }
70
+ end
71
+
72
+ def executeScript(script, *args)
73
+ dispatch(:execute_script, script, driver) {
74
+ @delegate.executeScript(script, *args)
75
+ }
76
+ end
77
+
78
+ def quit
79
+ dispatch(:quit, driver) { @delegate.quit }
80
+ end
81
+
82
+ def close
83
+ dispatch(:close, driver) { @delegate.close }
84
+ end
85
+
86
+ private
87
+
88
+ def create_element(ref)
89
+ # hmm. we're not passing self here to not fire events for potential calls made by the listener
90
+ Element.new @delegate, ref
91
+ end
92
+
93
+ def driver
94
+ @driver ||= Driver.new(self)
95
+ end
96
+
97
+ def dispatch(name, *args, &blk)
98
+ @listener.__send__("before_#{name}", *args)
99
+ returned = yield
100
+ @listener.__send__("after_#{name}", *args)
101
+
102
+ returned
103
+ end
104
+
105
+ def method_missing(meth, *args, &blk)
106
+ @delegate.__send__(meth, *args, &blk)
107
+ end
108
+ end # EventFiringBridge
109
+
110
+ end # Support
111
+ end # WebDriver
112
+ end # Selenium