selenium-webdriver 2.53.4 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/CHANGES +24 -18
  2. data/README.md +2 -3
  3. data/lib/selenium/server.rb +64 -68
  4. data/lib/selenium/webdriver.rb +5 -9
  5. data/lib/selenium/webdriver/chrome.rb +18 -3
  6. data/lib/selenium/webdriver/chrome/bridge.rb +13 -16
  7. data/lib/selenium/webdriver/chrome/profile.rb +7 -9
  8. data/lib/selenium/webdriver/chrome/service.rb +8 -84
  9. data/lib/selenium/webdriver/common.rb +1 -2
  10. data/lib/selenium/webdriver/common/action_builder.rb +28 -38
  11. data/lib/selenium/webdriver/common/alert.rb +7 -10
  12. data/lib/selenium/webdriver/common/bridge_helper.rb +10 -15
  13. data/lib/selenium/webdriver/common/driver.rb +19 -28
  14. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +0 -3
  15. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +4 -6
  16. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +4 -5
  17. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +0 -2
  18. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +0 -2
  19. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +0 -2
  20. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +0 -3
  21. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +3 -6
  22. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +2 -5
  23. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +2 -5
  24. data/lib/selenium/webdriver/common/element.rb +27 -29
  25. data/lib/selenium/webdriver/common/error.rb +17 -20
  26. data/lib/selenium/webdriver/common/file_reaper.rb +3 -9
  27. data/lib/selenium/webdriver/common/html5/local_storage.rb +6 -8
  28. data/lib/selenium/webdriver/common/html5/session_storage.rb +6 -8
  29. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +6 -15
  30. data/lib/selenium/webdriver/common/keyboard.rb +7 -12
  31. data/lib/selenium/webdriver/common/keys.rb +67 -69
  32. data/lib/selenium/webdriver/common/log_entry.rb +3 -4
  33. data/lib/selenium/webdriver/common/logs.rb +2 -4
  34. data/lib/selenium/webdriver/common/mouse.rb +9 -12
  35. data/lib/selenium/webdriver/common/navigation.rb +2 -4
  36. data/lib/selenium/webdriver/common/options.rb +16 -19
  37. data/lib/selenium/webdriver/common/platform.rb +61 -90
  38. data/lib/selenium/webdriver/common/port_prober.rb +1 -2
  39. data/lib/selenium/webdriver/common/profile_helper.rb +5 -8
  40. data/lib/selenium/webdriver/common/proxy.rb +58 -70
  41. data/lib/selenium/webdriver/common/search_context.rb +15 -19
  42. data/lib/selenium/webdriver/common/service.rb +127 -0
  43. data/lib/selenium/webdriver/common/socket_lock.rb +5 -11
  44. data/lib/selenium/webdriver/common/socket_poller.rb +4 -9
  45. data/lib/selenium/webdriver/common/target_locator.rb +11 -13
  46. data/lib/selenium/webdriver/common/timeouts.rb +4 -6
  47. data/lib/selenium/webdriver/common/touch_action_builder.rb +2 -4
  48. data/lib/selenium/webdriver/common/touch_screen.rb +15 -18
  49. data/lib/selenium/webdriver/common/w3c_error.rb +3 -6
  50. data/lib/selenium/webdriver/common/wait.rb +6 -11
  51. data/lib/selenium/webdriver/common/window.rb +12 -15
  52. data/lib/selenium/webdriver/common/zipper.rb +6 -8
  53. data/lib/selenium/webdriver/edge.rb +18 -3
  54. data/lib/selenium/webdriver/edge/bridge.rb +11 -16
  55. data/lib/selenium/webdriver/edge/legacy_support.rb +38 -39
  56. data/lib/selenium/webdriver/edge/service.rb +8 -82
  57. data/lib/selenium/webdriver/firefox.rb +25 -6
  58. data/lib/selenium/webdriver/firefox/binary.rb +37 -53
  59. data/lib/selenium/webdriver/firefox/bridge.rb +3 -6
  60. data/lib/selenium/webdriver/firefox/extension.rb +4 -6
  61. data/lib/selenium/webdriver/firefox/extension/prefs.json +1 -10
  62. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  63. data/lib/selenium/webdriver/firefox/launcher.rb +8 -11
  64. data/lib/selenium/webdriver/firefox/profile.rb +40 -42
  65. data/lib/selenium/webdriver/firefox/profiles_ini.rb +8 -15
  66. data/lib/selenium/webdriver/firefox/service.rb +23 -79
  67. data/lib/selenium/webdriver/firefox/util.rb +0 -2
  68. data/lib/selenium/webdriver/firefox/w3c_bridge.rb +2 -4
  69. data/lib/selenium/webdriver/ie.rb +16 -7
  70. data/lib/selenium/webdriver/ie/bridge.rb +16 -23
  71. data/lib/selenium/webdriver/{iphone.rb → ie/service.rb} +26 -4
  72. data/lib/selenium/webdriver/phantomjs.rb +8 -3
  73. data/lib/selenium/webdriver/phantomjs/bridge.rb +9 -11
  74. data/lib/selenium/webdriver/phantomjs/service.rb +17 -81
  75. data/lib/selenium/webdriver/remote.rb +0 -2
  76. data/lib/selenium/webdriver/remote/bridge.rb +193 -191
  77. data/lib/selenium/webdriver/remote/capabilities.rb +60 -90
  78. data/lib/selenium/webdriver/remote/commands.rb +197 -192
  79. data/lib/selenium/webdriver/remote/http/common.rb +15 -13
  80. data/lib/selenium/webdriver/remote/http/curb.rb +5 -9
  81. data/lib/selenium/webdriver/remote/http/default.rb +32 -37
  82. data/lib/selenium/webdriver/remote/http/persistent.rb +4 -6
  83. data/lib/selenium/webdriver/remote/response.rb +13 -21
  84. data/lib/selenium/webdriver/remote/server_error.rb +1 -3
  85. data/lib/selenium/webdriver/remote/w3c_bridge.rb +200 -195
  86. data/lib/selenium/webdriver/remote/w3c_capabilities.rb +38 -46
  87. data/lib/selenium/webdriver/remote/w3c_commands.rb +116 -113
  88. data/lib/selenium/webdriver/safari.rb +23 -7
  89. data/lib/selenium/{client/javascript_frameworks/jquery.rb → webdriver/safari/apple_bridge.rb} +28 -9
  90. data/lib/selenium/webdriver/safari/browser.rb +0 -2
  91. data/lib/selenium/webdriver/safari/{bridge.rb → legacy_bridge.rb} +12 -9
  92. data/lib/selenium/webdriver/safari/options.rb +3 -4
  93. data/lib/selenium/webdriver/safari/resources/client.js +56 -7255
  94. data/lib/selenium/webdriver/safari/server.rb +18 -24
  95. data/lib/selenium/{client/javascript_frameworks/prototype.rb → webdriver/safari/service.rb} +27 -9
  96. data/lib/selenium/webdriver/support.rb +1 -0
  97. data/lib/selenium/webdriver/support/abstract_event_listener.rb +17 -2
  98. data/lib/selenium/webdriver/support/block_event_listener.rb +1 -3
  99. data/lib/selenium/webdriver/support/color.rb +55 -38
  100. data/lib/selenium/webdriver/{android.rb → support/escaper.rb} +19 -4
  101. data/lib/selenium/webdriver/support/event_firing_bridge.rb +36 -38
  102. data/lib/selenium/webdriver/support/select.rb +33 -84
  103. data/selenium-webdriver.gemspec +23 -23
  104. metadata +19 -30
  105. data/lib/selenium-client.rb +0 -21
  106. data/lib/selenium/client.rb +0 -57
  107. data/lib/selenium/client/base.rb +0 -151
  108. data/lib/selenium/client/driver.rb +0 -29
  109. data/lib/selenium/client/errors.rb +0 -28
  110. data/lib/selenium/client/extensions.rb +0 -132
  111. data/lib/selenium/client/idiomatic.rb +0 -507
  112. data/lib/selenium/client/javascript_expression_builder.rb +0 -135
  113. data/lib/selenium/client/legacy_driver.rb +0 -1722
  114. data/lib/selenium/client/protocol.rb +0 -123
  115. data/lib/selenium/client/selenium_helper.rb +0 -49
  116. data/lib/selenium/rake/server_task.rb +0 -176
  117. data/lib/selenium/webdriver/android/bridge.rb +0 -68
  118. data/lib/selenium/webdriver/common/core_ext/base64.rb +0 -28
  119. data/lib/selenium/webdriver/common/core_ext/dir.rb +0 -61
  120. data/lib/selenium/webdriver/common/html5/location.rb +0 -19
  121. data/lib/selenium/webdriver/ie/server.rb +0 -133
  122. data/lib/selenium/webdriver/iphone/bridge.rb +0 -64
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Safari
23
-
24
23
  class Server
25
24
  SOCKET_LOCK_TIMEOUT = 45
26
25
 
@@ -47,16 +46,17 @@ module Selenium
47
46
  json = JSON.generate(command)
48
47
  puts ">>> #{json}" if $DEBUG
49
48
 
50
- frame = WebSocket::Frame::Outgoing::Server.new(:version => @version, :data => json, :type => :text)
49
+ frame = WebSocket::Frame::Outgoing::Server.new(version: @version, data: json, type: :text)
51
50
 
52
51
  @ws.write frame.to_s
53
52
  @ws.flush
54
53
  end
55
54
 
56
55
  def receive
57
- @frame ||= WebSocket::Frame::Incoming::Server.new(:version => @version)
56
+ @frame ||= WebSocket::Frame::Incoming::Server.new(version: @version)
58
57
 
59
- until msg = @frame.next
58
+ msg = nil
59
+ until msg
60
60
  end_time = Time.now + @command_timeout
61
61
 
62
62
  begin
@@ -64,7 +64,7 @@ module Selenium
64
64
  rescue Errno::EWOULDBLOCK, Errno::EAGAIN
65
65
  now = Time.now
66
66
  if now >= end_time
67
- raise Error::TimeOutError, "timed out waiting for Safari to respond"
67
+ raise Error::TimeOutError, 'timed out waiting for Safari to respond'
68
68
  end
69
69
 
70
70
  IO.select([@ws], nil, nil, end_time - now)
@@ -72,6 +72,7 @@ module Selenium
72
72
  end
73
73
 
74
74
  @frame << data
75
+ msg = @frame.next
75
76
  end
76
77
 
77
78
  puts "<<< #{msg}" if $DEBUG
@@ -93,13 +94,14 @@ module Selenium
93
94
  process_handshake
94
95
  end
95
96
 
96
- HEADERS = <<-HEADERS
97
+ def headers
98
+ headers = <<-headers
97
99
  HTTP/1.1 %d %s
98
100
  Content-Type: text/html; charset=utf-8
99
101
  Server: safaridriver-ruby
100
- HEADERS
101
-
102
- HEADERS.gsub!("\n", "\r\n")
102
+ headers
103
+ headers.gsub!("\n", "\r\n")
104
+ end
103
105
 
104
106
  def html
105
107
  "<!DOCTYPE html><script>#{Safari.resource_path.join('client.js').read}</script>"
@@ -109,19 +111,17 @@ Server: safaridriver-ruby
109
111
  http = @server.accept
110
112
 
111
113
  req = ''
112
- until req.include?("\r\n\r\n")
113
- req << http.read(1)
114
- end
114
+ req << http.read(1) until req.include?("\r\n\r\n")
115
115
 
116
- if !req.include?("?url=")
117
- http << HEADERS % [302, 'Moved Temporarily']
116
+ if !req.include?('?url=')
117
+ http << format(headers, 302, 'Moved Temporarily')
118
118
  http << "Location: #{uri}?url=#{encode_form_component ws_uri}\r\n"
119
119
  http << "\r\n\r\n"
120
120
  http.close
121
121
 
122
122
  process_initial_http_request
123
123
  else
124
- http << HEADERS % [200, 'OK']
124
+ http << format(headers, 200, 'OK')
125
125
  http << "\r\n\r\n"
126
126
  http << html
127
127
  http.close
@@ -130,7 +130,7 @@ Server: safaridriver-ruby
130
130
 
131
131
  def process_handshake
132
132
  @ws = @server.accept
133
- hs = WebSocket::Handshake::Server.new
133
+ hs = WebSocket::Handshake::Server.new
134
134
 
135
135
  req = ''
136
136
  until hs.finished?
@@ -141,7 +141,7 @@ Server: safaridriver-ruby
141
141
  end
142
142
 
143
143
  unless hs.valid?
144
- if req.include? "favicon.ico"
144
+ if req.include? 'favicon.ico'
145
145
  @ws.close
146
146
  process_handshake
147
147
  return
@@ -159,12 +159,7 @@ Server: safaridriver-ruby
159
159
  end
160
160
 
161
161
  def encode_form_component(str)
162
- if URI.respond_to?(:encode_www_form_component) # >= 1.9
163
- URI.encode_www_form_component(str)
164
- else
165
- # best effort for 1.8
166
- str.gsub(":", '%3A').gsub('/', '%2F')
167
- end
162
+ URI.encode_www_form_component(str)
168
163
  end
169
164
 
170
165
  private
@@ -180,7 +175,6 @@ Server: safaridriver-ruby
180
175
  def socket_lock
181
176
  @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
182
177
  end
183
-
184
178
  end # Server
185
179
  end # Safari
186
180
  end # WebDriver
@@ -18,15 +18,33 @@
18
18
  # under the License.
19
19
 
20
20
  module Selenium
21
- module Client
22
- module JavascriptFrameworks
23
- module Prototype
21
+ module WebDriver
22
+ module Safari
23
+ #
24
+ # @api private
25
+ #
24
26
 
25
- def self.ajax_request_tracker
26
- "Ajax.activeRequestCount"
27
+ class Service < WebDriver::Service
28
+ DEFAULT_PORT = 7050
29
+
30
+ private
31
+
32
+ def start_process
33
+ server_command = [@executable_path, "--port=#{@port}", *@extra_args]
34
+ @process = ChildProcess.build(*server_command)
35
+
36
+ @process.io.inherit! if $DEBUG
37
+ @process.start
27
38
  end
28
39
 
29
- end
30
- end
31
- end
32
- end
40
+ def stop_server
41
+ connect_to_server { |http| http.head('/shutdown') }
42
+ end
43
+
44
+ def cannot_connect_error_text
45
+ "unable to connect to safaridriver #{@host}:#{@port}"
46
+ end
47
+ end # Service
48
+ end # Safari
49
+ end # WebDriver
50
+ end # Selenium
@@ -20,5 +20,6 @@
20
20
  require 'selenium/webdriver/support/event_firing_bridge'
21
21
  require 'selenium/webdriver/support/abstract_event_listener'
22
22
  require 'selenium/webdriver/support/block_event_listener'
23
+ require 'selenium/webdriver/support/escaper'
23
24
  require 'selenium/webdriver/support/select'
24
25
  require 'selenium/webdriver/support/color'
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Support
23
-
24
23
  #
25
24
  # Subclass and override methods from this class
26
25
  # to implement your own event listener.
@@ -48,24 +47,40 @@ module Selenium
48
47
 
49
48
  class AbstractEventListener
50
49
  def before_navigate_to(url, driver) end
50
+
51
51
  def after_navigate_to(url, driver) end
52
+
52
53
  def before_navigate_back(driver) end
54
+
53
55
  def after_navigate_back(driver) end
56
+
54
57
  def before_navigate_forward(driver) end
58
+
55
59
  def after_navigate_forward(driver) end
60
+
56
61
  def before_find(by, what, driver) end
62
+
57
63
  def after_find(by, what, driver) end
64
+
58
65
  def before_click(element, driver) end
66
+
59
67
  def after_click(element, driver) end
68
+
60
69
  def before_change_value_of(element, driver) end
70
+
61
71
  def after_change_value_of(element, driver) end
72
+
62
73
  def before_execute_script(script, driver) end
74
+
63
75
  def after_execute_script(script, driver) end
76
+
64
77
  def before_quit(driver) end
78
+
65
79
  def after_quit(driver) end
80
+
66
81
  def before_close(driver) end
67
- def after_close(driver) end
68
82
 
83
+ def after_close(driver) end
69
84
  end # AbstractEventListener
70
85
  end # Support
71
86
  end # WebDriver
@@ -20,16 +20,14 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Support
23
-
24
23
  class BlockEventListener
25
24
  def initialize(callback)
26
25
  @callback = callback
27
26
  end
28
27
 
29
- def method_missing(meth, *args, &blk)
28
+ def method_missing(meth, *args)
30
29
  @callback.call meth, *args
31
30
  end
32
-
33
31
  end # BlockEventListener
34
32
  end # Support
35
33
  end # WebDriver
@@ -21,33 +21,52 @@ module Selenium
21
21
  module WebDriver
22
22
  module Support
23
23
  class Color
24
- RGB_PATTERN = /^\s*rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)\s*$/
25
- RGB_PCT_PATTERN = /^\s*rgb\(\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,\s*(\d{1,3}|\d{1,2}\.\d+)%\s*\)\s*$/
26
- RGBA_PATTERN = /^\s*rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0\.\d+)\s*\)\s*$/
27
- RGBA_PCT_PATTERN = /^\s*rgba\(\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,\s*(0|1|0\.\d+)\s*\)\s*$/
28
- HEX_PATTERN = /#([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})/ # \p{XDigit} or \h only works on Ruby 1.9
29
- HEX3_PATTERN = /#([A-Fa-f0-9])([A-Fa-f0-9])([A-Fa-f0-9])/ # \p{XDigit} or \h only works on Ruby 1.9
30
- HSL_PATTERN = /^\s*hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)\s*$/
31
- HSLA_PATTERN = /^\s*hsla\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*,\s*(0|1|0\.\d+)\s*\)\s*$/
24
+ RGB_PATTERN = %r{^\s*rgb\(\s*(\d{1,3})\s*,
25
+ \s*(\d{1,3})\s*,
26
+ \s*(\d{1,3})\s*\)\s*$}x
27
+ RGB_PCT_PATTERN = %r{^\s*rgb\(\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,
28
+ \s*(\d{1,3}|\d{1,2}\.\d+)%\s*,
29
+ \s*(\d{1,3}|\d{1,2}\.\d+)%\s*\)\s*$}x
30
+ RGBA_PATTERN = %r{^\s*rgba\(\s*(\d{1,3})\s*,
31
+ \s*(\d{1,3})\s*,
32
+ \s*(\d{1,3})\s*,
33
+ \s*(0|1|0\.\d+)\s*\)\s*$}x
34
+ RGBA_PCT_PATTERN = %r{^\s*rgba\(\s*(\d{1,3}|\d{1,2}\.\d+)
35
+ %\s*,\s*(\d{1,3}|\d{1,2}\.\d+)
36
+ %\s*,\s*(\d{1,3}|\d{1,2}\.\d+)
37
+ %\s*,\s*(0|1|0\.\d+)\s*\)\s*$}x
38
+ HEX_PATTERN = /#(\h{2})(\h{2})(\h{2})/
39
+ HEX3_PATTERN = /#(\h)(\h)(\h)/
40
+ HSL_PATTERN = %r{^\s*hsl\(\s*(\d{1,3})\s*,
41
+ \s*(\d{1,3})%\s*,
42
+ \s*(\d{1,3})%\s*\)\s*$}x
43
+ HSLA_PATTERN = %r{^\s*hsla\(\s*(\d{1,3})\s*,
44
+ \s*(\d{1,3})%\s*,
45
+ \s*(\d{1,3})%\s*,
46
+ \s*(0|1|0\.\d+)\s*\)\s*$}x
32
47
 
33
48
  attr_reader :red, :green, :blue, :alpha
34
49
 
35
50
  def self.from_string(str)
36
51
  case str
37
52
  when RGB_PATTERN
38
- new $1, $2, $3
53
+ new Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)
39
54
  when RGB_PCT_PATTERN
40
- new(*[$1, $2, $3].map { |e| Float(e) / 100 * 255 })
55
+ array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)]
56
+ new(*array.map { |e| Float(e) / 100 * 255 })
41
57
  when RGBA_PATTERN
42
- new $1, $2, $3, $4
58
+ new Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3), Regexp.last_match(4)
43
59
  when RGBA_PCT_PATTERN
44
- new(*[$1, $2, $3].map { |e| Float(e) / 100 * 255 } << $4)
60
+ array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)]
61
+ new(*array.map { |e| Float(e) / 100 * 255 } << Regexp.last_match(4))
45
62
  when HEX_PATTERN
46
- new(*[$1, $2, $3].map { |e| e.to_i(16) })
63
+ array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)]
64
+ new(*array.map { |e| e.to_i(16) })
47
65
  when HEX3_PATTERN
48
- new(*[$1, $2, $3].map { |e| (e * 2).to_i(16) })
66
+ array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)]
67
+ new(*array.map { |e| (e * 2).to_i(16) })
49
68
  when HSL_PATTERN, HSLA_PATTERN
50
- from_hsl($1, $2, $3, $4)
69
+ from_hsl(Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3), Regexp.last_match(4))
51
70
  else
52
71
  raise ArgumentError, "could not convert #{str.inspect} into color"
53
72
  end
@@ -67,40 +86,39 @@ module Selenium
67
86
  luminocity2 = (l < 0.5) ? l * (1 + s) : l + s - l * s
68
87
  luminocity1 = 2 * l - luminocity2
69
88
 
70
- hue_to_rgb = lambda do |lum1, lum2, hue|
71
- hue += 1 if hue < 0.0
72
- hue -= 1 if hue > 1.0
73
-
74
- if hue < 1.0 / 6.0
75
- (lum1 + (lum2 - lum1) * 6.0 * hue)
76
- elsif hue < 1.0 / 2.0
77
- lum2
78
- elsif hue < 2.0 / 3.0
79
- lum1 + (lum2 - lum1) * ((2.0 / 3.0) - hue) * 6.0
80
- else
81
- lum1
82
- end
83
- end
84
-
85
- r = hue_to_rgb.call(luminocity1, luminocity2, h + 1.0 / 3.0)
86
- g = hue_to_rgb.call(luminocity1, luminocity2, h)
87
- b = hue_to_rgb.call(luminocity1, luminocity2, h - 1.0 / 3.0)
89
+ r = hue_to_rgb(luminocity1, luminocity2, h + 1.0 / 3.0)
90
+ g = hue_to_rgb(luminocity1, luminocity2, h)
91
+ b = hue_to_rgb(luminocity1, luminocity2, h - 1.0 / 3.0)
88
92
  end
89
93
 
90
94
  new (r * 255).round, (g * 255).round, (b * 255).round, a
91
95
  end
92
96
 
97
+ def self.hue_to_rgb(lum1, lum2, hue)
98
+ hue += 1 if hue < 0.0
99
+ hue -= 1 if hue > 1.0
100
+
101
+ if hue < 1.0 / 6.0
102
+ (lum1 + (lum2 - lum1) * 6.0 * hue)
103
+ elsif hue < 1.0 / 2.0
104
+ lum2
105
+ elsif hue < 2.0 / 3.0
106
+ lum1 + (lum2 - lum1) * ((2.0 / 3.0) - hue) * 6.0
107
+ else
108
+ lum1
109
+ end
110
+ end
93
111
 
94
112
  def initialize(red, green, blue, alpha = 1)
95
- @red = Integer(red)
113
+ @red = Integer(red)
96
114
  @green = Integer(green)
97
- @blue = Integer(blue)
115
+ @blue = Integer(blue)
98
116
  @alpha = Float(alpha)
99
117
  end
100
118
 
101
119
  def ==(other)
102
120
  return true if equal?(other)
103
- return false unless other.kind_of?(self.class)
121
+ return false unless other.is_a?(self.class)
104
122
 
105
123
  [red, green, blue, alpha] == [other.red, other.green, other.blue, other.alpha]
106
124
  end
@@ -120,9 +138,8 @@ module Selenium
120
138
  end
121
139
 
122
140
  def hex
123
- "#%02x%02x%02x" % [red, green, blue]
141
+ format '#%02x%02x%02x', red, green, blue
124
142
  end
125
-
126
143
  end # Color
127
144
  end # Support
128
145
  end # WebDriver
@@ -19,10 +19,25 @@
19
19
 
20
20
  module Selenium
21
21
  module WebDriver
22
- module Android
22
+ module Support
23
+ module Escaper
24
+ def self.escape(str)
25
+ if str.include?('"') && str.include?("'")
26
+ parts = str.split('"', -1).map { |part| %("#{part}") }
23
27
 
24
- end # Android
28
+ quoted = parts.join(%(, '"', ))
29
+ .gsub(/^"", |, ""$/, '')
30
+
31
+ "concat(#{quoted})"
32
+ elsif str.include?('"')
33
+ # escape string with just a quote into being single quoted: f"oo -> 'f"oo'
34
+ "'#{str}'"
35
+ else
36
+ # otherwise return the quoted string
37
+ %("#{str}")
38
+ end
39
+ end
40
+ end # Escaper
41
+ end # Support
25
42
  end # WebDriver
26
43
  end # Selenium
27
-
28
- require 'selenium/webdriver/android/bridge'
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Support
23
-
24
23
  #
25
24
  # @api private
26
25
  #
@@ -29,69 +28,69 @@ module Selenium
29
28
  def initialize(delegate, listener)
30
29
  @delegate = delegate
31
30
 
32
- if listener.respond_to? :call
33
- @listener = BlockEventListener.new(listener)
34
- else
35
- @listener = listener
36
- end
31
+ @listener = if listener.respond_to? :call
32
+ BlockEventListener.new(listener)
33
+ else
34
+ listener
35
+ end
37
36
  end
38
37
 
39
38
  def get(url)
40
- dispatch(:navigate_to, url, driver) {
39
+ dispatch(:navigate_to, url, driver) do
41
40
  @delegate.get(url)
42
- }
41
+ end
43
42
  end
44
43
 
45
- def goForward
46
- dispatch(:navigate_forward, driver) {
47
- @delegate.goForward
48
- }
44
+ def go_forward
45
+ dispatch(:navigate_forward, driver) do
46
+ @delegate.go_forward
47
+ end
49
48
  end
50
49
 
51
- def goBack
52
- dispatch(:navigate_back, driver) {
53
- @delegate.goBack
54
- }
50
+ def go_back
51
+ dispatch(:navigate_back, driver) do
52
+ @delegate.go_back
53
+ end
55
54
  end
56
55
 
57
- def clickElement(ref)
58
- dispatch(:click, create_element(ref), driver) {
59
- @delegate.clickElement(ref)
60
- }
56
+ def click_element(ref)
57
+ dispatch(:click, create_element(ref), driver) do
58
+ @delegate.click_element(ref)
59
+ end
61
60
  end
62
61
 
63
- def clearElement(ref)
64
- dispatch(:change_value_of, create_element(ref), driver) {
65
- @delegate.clearElement(ref)
66
- }
62
+ def clear_element(ref)
63
+ dispatch(:change_value_of, create_element(ref), driver) do
64
+ @delegate.clear_element(ref)
65
+ end
67
66
  end
68
67
 
69
- def sendKeysToElement(ref, keys)
70
- dispatch(:change_value_of, create_element(ref), driver) {
71
- @delegate.sendKeysToElement(ref, keys)
72
- }
68
+ def send_keys_to_element(ref, keys)
69
+ dispatch(:change_value_of, create_element(ref), driver) do
70
+ @delegate.send_keys_to_element(ref, keys)
71
+ end
73
72
  end
74
73
 
75
74
  def find_element_by(how, what, parent = nil)
76
- e = dispatch(:find, how, what, driver) {
75
+ e = dispatch(:find, how, what, driver) do
77
76
  @delegate.find_element_by how, what, parent
78
- }
77
+ end
79
78
 
80
79
  Element.new self, e.ref
81
80
  end
82
81
 
83
82
  def find_elements_by(how, what, parent = nil)
84
- es = dispatch(:find, how, what, driver) {
83
+ es = dispatch(:find, how, what, driver) do
85
84
  @delegate.find_elements_by(how, what, parent)
86
- }
85
+ end
87
86
 
88
87
  es.map { |e| Element.new self, e.ref }
89
88
  end
90
89
 
91
- def executeScript(script, *args)
92
- dispatch(:execute_script, script, driver) {
93
- @delegate.executeScript(script, *args)
94
- }
90
+ def execute_script(script, *args)
91
+ dispatch(:execute_script, script, driver) do
92
+ @delegate.execute_script(script, *args)
93
+ end
95
94
  end
96
95
 
97
96
  def quit
@@ -113,7 +112,7 @@ module Selenium
113
112
  @driver ||= Driver.new(self)
114
113
  end
115
114
 
116
- def dispatch(name, *args, &blk)
115
+ def dispatch(name, *args)
117
116
  @listener.__send__("before_#{name}", *args)
118
117
  returned = yield
119
118
  @listener.__send__("after_#{name}", *args)
@@ -125,7 +124,6 @@ module Selenium
125
124
  @delegate.__send__(meth, *args, &blk)
126
125
  end
127
126
  end # EventFiringBridge
128
-
129
127
  end # Support
130
128
  end # WebDriver
131
129
  end # Selenium