selenium-webdriver 4.0.0.alpha2 → 4.0.0.alpha7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +172 -4
  3. data/LICENSE +1 -1
  4. data/lib/selenium/server.rb +25 -9
  5. data/lib/selenium/webdriver.rb +12 -8
  6. data/lib/selenium/webdriver/atoms/findElements.js +121 -0
  7. data/lib/selenium/webdriver/atoms/getAttribute.js +104 -7
  8. data/lib/selenium/webdriver/atoms/isDisplayed.js +76 -78
  9. data/lib/selenium/webdriver/atoms/mutationListener.js +38 -0
  10. data/lib/selenium/webdriver/chrome.rb +10 -9
  11. data/lib/selenium/webdriver/chrome/bridge.rb +20 -4
  12. data/lib/selenium/webdriver/chrome/driver.rb +7 -49
  13. data/lib/selenium/webdriver/chrome/options.rb +97 -57
  14. data/lib/selenium/webdriver/chrome/profile.rb +3 -3
  15. data/lib/selenium/webdriver/chrome/service.rb +0 -4
  16. data/lib/selenium/webdriver/common.rb +6 -1
  17. data/lib/selenium/webdriver/common/driver.rb +81 -17
  18. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +89 -0
  19. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +39 -0
  20. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +143 -0
  21. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +2 -1
  22. data/lib/selenium/webdriver/common/element.rb +5 -0
  23. data/lib/selenium/webdriver/common/logger.rb +48 -16
  24. data/lib/selenium/webdriver/common/manager.rb +5 -0
  25. data/lib/selenium/webdriver/common/options.rb +116 -0
  26. data/lib/selenium/webdriver/common/platform.rb +4 -1
  27. data/lib/selenium/webdriver/common/port_prober.rb +4 -6
  28. data/lib/selenium/webdriver/common/profile_helper.rb +10 -2
  29. data/lib/selenium/webdriver/common/proxy.rb +0 -0
  30. data/lib/selenium/webdriver/common/search_context.rb +3 -2
  31. data/lib/selenium/webdriver/common/service.rb +30 -113
  32. data/lib/selenium/webdriver/common/service_manager.rb +151 -0
  33. data/lib/selenium/webdriver/common/socket_lock.rb +2 -2
  34. data/lib/selenium/webdriver/common/takes_screenshot.rb +63 -0
  35. data/lib/selenium/webdriver/common/wait.rb +1 -1
  36. data/lib/selenium/webdriver/devtools.rb +132 -0
  37. data/lib/selenium/webdriver/devtools/console_event.rb +38 -0
  38. data/lib/selenium/webdriver/devtools/exception_event.rb +36 -0
  39. data/lib/selenium/webdriver/devtools/mutation_event.rb +37 -0
  40. data/lib/selenium/webdriver/devtools/v84/accessibility.rb +64 -0
  41. data/lib/selenium/webdriver/devtools/v84/animation.rb +100 -0
  42. data/lib/selenium/webdriver/devtools/v84/application_cache.rb +66 -0
  43. data/lib/selenium/webdriver/devtools/v84/audits.rb +63 -0
  44. data/lib/selenium/webdriver/devtools/v84/background_service.rb +69 -0
  45. data/lib/selenium/webdriver/devtools/v84/browser.rb +125 -0
  46. data/lib/selenium/webdriver/devtools/v84/cache_storage.rb +75 -0
  47. data/lib/selenium/webdriver/devtools/v84/cast.rb +72 -0
  48. data/lib/selenium/webdriver/devtools/v84/console.rb +59 -0
  49. data/lib/selenium/webdriver/devtools/v84/css.rb +167 -0
  50. data/lib/selenium/webdriver/devtools/v84/database.rb +66 -0
  51. data/lib/selenium/webdriver/devtools/v84/debugger.rb +231 -0
  52. data/lib/selenium/webdriver/devtools/v84/device_orientation.rb +55 -0
  53. data/lib/selenium/webdriver/devtools/v84/dom.rb +322 -0
  54. data/lib/selenium/webdriver/devtools/v84/dom_debugger.rb +95 -0
  55. data/lib/selenium/webdriver/devtools/v84/dom_snapshot.rb +67 -0
  56. data/lib/selenium/webdriver/devtools/v84/dom_storage.rb +81 -0
  57. data/lib/selenium/webdriver/devtools/v84/emulation.rb +182 -0
  58. data/lib/selenium/webdriver/devtools/v84/fetch.rb +99 -0
  59. data/lib/selenium/webdriver/devtools/v84/headless_experimental.rb +63 -0
  60. data/lib/selenium/webdriver/devtools/v84/heap_profiler.rb +109 -0
  61. data/lib/selenium/webdriver/devtools/v84/indexed_db.rb +102 -0
  62. data/lib/selenium/webdriver/devtools/v84/input.rb +142 -0
  63. data/lib/selenium/webdriver/devtools/v84/inspector.rb +57 -0
  64. data/lib/selenium/webdriver/devtools/v84/io.rb +61 -0
  65. data/lib/selenium/webdriver/devtools/v84/layer_tree.rb +97 -0
  66. data/lib/selenium/webdriver/devtools/v84/log.rb +68 -0
  67. data/lib/selenium/webdriver/devtools/v84/media.rb +59 -0
  68. data/lib/selenium/webdriver/devtools/v84/memory.rb +88 -0
  69. data/lib/selenium/webdriver/devtools/v84/network.rb +230 -0
  70. data/lib/selenium/webdriver/devtools/v84/overlay.rb +159 -0
  71. data/lib/selenium/webdriver/devtools/v84/page.rb +376 -0
  72. data/lib/selenium/webdriver/devtools/v84/performance.rb +65 -0
  73. data/lib/selenium/webdriver/devtools/v84/profiler.rb +113 -0
  74. data/lib/selenium/webdriver/devtools/v84/runtime.rb +195 -0
  75. data/lib/selenium/webdriver/devtools/v84/schema.rb +48 -0
  76. data/lib/selenium/webdriver/devtools/v84/security.rb +73 -0
  77. data/lib/selenium/webdriver/devtools/v84/service_worker.rb +118 -0
  78. data/lib/selenium/webdriver/devtools/v84/storage.rb +97 -0
  79. data/lib/selenium/webdriver/devtools/v84/system_info.rb +52 -0
  80. data/lib/selenium/webdriver/devtools/v84/target.rb +143 -0
  81. data/lib/selenium/webdriver/devtools/v84/tethering.rb +57 -0
  82. data/lib/selenium/webdriver/devtools/v84/tracing.rb +78 -0
  83. data/lib/selenium/webdriver/devtools/v84/web_audio.rb +72 -0
  84. data/lib/selenium/webdriver/devtools/v84/web_authn.rb +96 -0
  85. data/lib/selenium/webdriver/devtools/v85/accessibility.rb +64 -0
  86. data/lib/selenium/webdriver/devtools/v85/animation.rb +100 -0
  87. data/lib/selenium/webdriver/devtools/v85/application_cache.rb +66 -0
  88. data/lib/selenium/webdriver/devtools/v85/audits.rb +63 -0
  89. data/lib/selenium/webdriver/devtools/v85/background_service.rb +69 -0
  90. data/lib/selenium/webdriver/devtools/v85/browser.rb +125 -0
  91. data/lib/selenium/webdriver/devtools/v85/cache_storage.rb +75 -0
  92. data/lib/selenium/webdriver/devtools/v85/cast.rb +72 -0
  93. data/lib/selenium/webdriver/devtools/v85/console.rb +59 -0
  94. data/lib/selenium/webdriver/devtools/v85/css.rb +167 -0
  95. data/lib/selenium/webdriver/devtools/v85/database.rb +66 -0
  96. data/lib/selenium/webdriver/devtools/v85/debugger.rb +231 -0
  97. data/lib/selenium/webdriver/devtools/v85/device_orientation.rb +55 -0
  98. data/lib/selenium/webdriver/devtools/v85/dom.rb +322 -0
  99. data/lib/selenium/webdriver/devtools/v85/dom_debugger.rb +95 -0
  100. data/lib/selenium/webdriver/devtools/v85/dom_snapshot.rb +67 -0
  101. data/lib/selenium/webdriver/devtools/v85/dom_storage.rb +81 -0
  102. data/lib/selenium/webdriver/devtools/v85/emulation.rb +182 -0
  103. data/lib/selenium/webdriver/devtools/v85/fetch.rb +99 -0
  104. data/lib/selenium/webdriver/devtools/v85/headless_experimental.rb +63 -0
  105. data/lib/selenium/webdriver/devtools/v85/heap_profiler.rb +109 -0
  106. data/lib/selenium/webdriver/devtools/v85/indexed_db.rb +102 -0
  107. data/lib/selenium/webdriver/devtools/v85/input.rb +143 -0
  108. data/lib/selenium/webdriver/devtools/v85/inspector.rb +57 -0
  109. data/lib/selenium/webdriver/devtools/v85/io.rb +61 -0
  110. data/lib/selenium/webdriver/devtools/v85/layer_tree.rb +97 -0
  111. data/lib/selenium/webdriver/devtools/v85/log.rb +68 -0
  112. data/lib/selenium/webdriver/devtools/v85/media.rb +59 -0
  113. data/lib/selenium/webdriver/devtools/v85/memory.rb +88 -0
  114. data/lib/selenium/webdriver/devtools/v85/network.rb +230 -0
  115. data/lib/selenium/webdriver/devtools/v85/overlay.rb +160 -0
  116. data/lib/selenium/webdriver/devtools/v85/page.rb +376 -0
  117. data/lib/selenium/webdriver/devtools/v85/performance.rb +65 -0
  118. data/lib/selenium/webdriver/devtools/v85/profiler.rb +113 -0
  119. data/lib/selenium/webdriver/devtools/v85/runtime.rb +196 -0
  120. data/lib/selenium/webdriver/devtools/v85/schema.rb +48 -0
  121. data/lib/selenium/webdriver/devtools/v85/security.rb +73 -0
  122. data/lib/selenium/webdriver/devtools/v85/service_worker.rb +118 -0
  123. data/lib/selenium/webdriver/devtools/v85/storage.rb +97 -0
  124. data/lib/selenium/webdriver/devtools/v85/system_info.rb +52 -0
  125. data/lib/selenium/webdriver/devtools/v85/target.rb +145 -0
  126. data/lib/selenium/webdriver/devtools/v85/tethering.rb +57 -0
  127. data/lib/selenium/webdriver/devtools/v85/tracing.rb +78 -0
  128. data/lib/selenium/webdriver/devtools/v85/web_audio.rb +72 -0
  129. data/lib/selenium/webdriver/devtools/v85/web_authn.rb +96 -0
  130. data/lib/selenium/webdriver/devtools/v86/accessibility.rb +64 -0
  131. data/lib/selenium/webdriver/devtools/v86/animation.rb +100 -0
  132. data/lib/selenium/webdriver/devtools/v86/application_cache.rb +66 -0
  133. data/lib/selenium/webdriver/devtools/v86/audits.rb +63 -0
  134. data/lib/selenium/webdriver/devtools/v86/background_service.rb +69 -0
  135. data/lib/selenium/webdriver/devtools/v86/browser.rb +125 -0
  136. data/lib/selenium/webdriver/devtools/v86/cache_storage.rb +75 -0
  137. data/lib/selenium/webdriver/devtools/v86/cast.rb +72 -0
  138. data/lib/selenium/webdriver/devtools/v86/console.rb +59 -0
  139. data/lib/selenium/webdriver/devtools/v86/css.rb +181 -0
  140. data/lib/selenium/webdriver/devtools/v86/database.rb +66 -0
  141. data/lib/selenium/webdriver/devtools/v86/debugger.rb +233 -0
  142. data/lib/selenium/webdriver/devtools/v86/device_orientation.rb +55 -0
  143. data/lib/selenium/webdriver/devtools/v86/dom.rb +329 -0
  144. data/lib/selenium/webdriver/devtools/v86/dom_debugger.rb +95 -0
  145. data/lib/selenium/webdriver/devtools/v86/dom_snapshot.rb +67 -0
  146. data/lib/selenium/webdriver/devtools/v86/dom_storage.rb +81 -0
  147. data/lib/selenium/webdriver/devtools/v86/emulation.rb +193 -0
  148. data/lib/selenium/webdriver/devtools/v86/fetch.rb +99 -0
  149. data/lib/selenium/webdriver/devtools/v86/headless_experimental.rb +63 -0
  150. data/lib/selenium/webdriver/devtools/v86/heap_profiler.rb +109 -0
  151. data/lib/selenium/webdriver/devtools/v86/indexed_db.rb +102 -0
  152. data/lib/selenium/webdriver/devtools/v86/input.rb +143 -0
  153. data/lib/selenium/webdriver/devtools/v86/inspector.rb +57 -0
  154. data/lib/selenium/webdriver/devtools/v86/io.rb +61 -0
  155. data/lib/selenium/webdriver/devtools/v86/layer_tree.rb +97 -0
  156. data/lib/selenium/webdriver/devtools/v86/log.rb +68 -0
  157. data/lib/selenium/webdriver/devtools/v86/media.rb +59 -0
  158. data/lib/selenium/webdriver/devtools/v86/memory.rb +88 -0
  159. data/lib/selenium/webdriver/devtools/v86/network.rb +235 -0
  160. data/lib/selenium/webdriver/devtools/v86/overlay.rb +183 -0
  161. data/lib/selenium/webdriver/devtools/v86/page.rb +376 -0
  162. data/lib/selenium/webdriver/devtools/v86/performance.rb +65 -0
  163. data/lib/selenium/webdriver/devtools/v86/profiler.rb +113 -0
  164. data/lib/selenium/webdriver/devtools/v86/runtime.rb +196 -0
  165. data/lib/selenium/webdriver/devtools/v86/schema.rb +48 -0
  166. data/lib/selenium/webdriver/devtools/v86/security.rb +73 -0
  167. data/lib/selenium/webdriver/devtools/v86/service_worker.rb +118 -0
  168. data/lib/selenium/webdriver/devtools/v86/storage.rb +97 -0
  169. data/lib/selenium/webdriver/devtools/v86/system_info.rb +52 -0
  170. data/lib/selenium/webdriver/devtools/v86/target.rb +145 -0
  171. data/lib/selenium/webdriver/devtools/v86/tethering.rb +57 -0
  172. data/lib/selenium/webdriver/devtools/v86/tracing.rb +78 -0
  173. data/lib/selenium/webdriver/devtools/v86/web_audio.rb +72 -0
  174. data/lib/selenium/webdriver/devtools/v86/web_authn.rb +102 -0
  175. data/lib/selenium/webdriver/devtools/v87/accessibility.rb +73 -0
  176. data/lib/selenium/webdriver/devtools/v87/animation.rb +100 -0
  177. data/lib/selenium/webdriver/devtools/v87/application_cache.rb +66 -0
  178. data/lib/selenium/webdriver/devtools/v87/audits.rb +63 -0
  179. data/lib/selenium/webdriver/devtools/v87/background_service.rb +69 -0
  180. data/lib/selenium/webdriver/devtools/v87/browser.rb +125 -0
  181. data/lib/selenium/webdriver/devtools/v87/cache_storage.rb +75 -0
  182. data/lib/selenium/webdriver/devtools/v87/cast.rb +72 -0
  183. data/lib/selenium/webdriver/devtools/v87/console.rb +59 -0
  184. data/lib/selenium/webdriver/devtools/v87/css.rb +181 -0
  185. data/lib/selenium/webdriver/devtools/v87/database.rb +66 -0
  186. data/lib/selenium/webdriver/devtools/v87/debugger.rb +233 -0
  187. data/lib/selenium/webdriver/devtools/v87/device_orientation.rb +55 -0
  188. data/lib/selenium/webdriver/devtools/v87/dom.rb +329 -0
  189. data/lib/selenium/webdriver/devtools/v87/dom_debugger.rb +95 -0
  190. data/lib/selenium/webdriver/devtools/v87/dom_snapshot.rb +67 -0
  191. data/lib/selenium/webdriver/devtools/v87/dom_storage.rb +81 -0
  192. data/lib/selenium/webdriver/devtools/v87/emulation.rb +193 -0
  193. data/lib/selenium/webdriver/devtools/v87/fetch.rb +99 -0
  194. data/lib/selenium/webdriver/devtools/v87/headless_experimental.rb +63 -0
  195. data/lib/selenium/webdriver/devtools/v87/heap_profiler.rb +109 -0
  196. data/lib/selenium/webdriver/devtools/v87/indexed_db.rb +102 -0
  197. data/lib/selenium/webdriver/devtools/v87/input.rb +143 -0
  198. data/lib/selenium/webdriver/devtools/v87/inspector.rb +57 -0
  199. data/lib/selenium/webdriver/devtools/v87/io.rb +61 -0
  200. data/lib/selenium/webdriver/devtools/v87/layer_tree.rb +97 -0
  201. data/lib/selenium/webdriver/devtools/v87/log.rb +68 -0
  202. data/lib/selenium/webdriver/devtools/v87/media.rb +59 -0
  203. data/lib/selenium/webdriver/devtools/v87/memory.rb +88 -0
  204. data/lib/selenium/webdriver/devtools/v87/network.rb +247 -0
  205. data/lib/selenium/webdriver/devtools/v87/overlay.rb +183 -0
  206. data/lib/selenium/webdriver/devtools/v87/page.rb +376 -0
  207. data/lib/selenium/webdriver/devtools/v87/performance.rb +65 -0
  208. data/lib/selenium/webdriver/devtools/v87/profiler.rb +125 -0
  209. data/lib/selenium/webdriver/devtools/v87/runtime.rb +196 -0
  210. data/lib/selenium/webdriver/devtools/v87/schema.rb +48 -0
  211. data/lib/selenium/webdriver/devtools/v87/security.rb +73 -0
  212. data/lib/selenium/webdriver/devtools/v87/service_worker.rb +118 -0
  213. data/lib/selenium/webdriver/devtools/v87/storage.rb +97 -0
  214. data/lib/selenium/webdriver/devtools/v87/system_info.rb +52 -0
  215. data/lib/selenium/webdriver/devtools/v87/target.rb +145 -0
  216. data/lib/selenium/webdriver/devtools/v87/tethering.rb +57 -0
  217. data/lib/selenium/webdriver/devtools/v87/tracing.rb +78 -0
  218. data/lib/selenium/webdriver/devtools/v87/web_audio.rb +72 -0
  219. data/lib/selenium/webdriver/devtools/v87/web_authn.rb +102 -0
  220. data/lib/selenium/webdriver/edge.rb +29 -9
  221. data/lib/selenium/webdriver/edge_chrome/bridge.rb +37 -0
  222. data/lib/selenium/webdriver/edge_chrome/driver.rb +48 -0
  223. data/lib/selenium/webdriver/edge_chrome/options.rb +37 -0
  224. data/lib/selenium/webdriver/edge_chrome/profile.rb +33 -0
  225. data/lib/selenium/webdriver/edge_chrome/service.rb +36 -0
  226. data/lib/selenium/webdriver/{edge → edge_html}/driver.rb +3 -35
  227. data/lib/selenium/webdriver/{edge → edge_html}/options.rb +26 -22
  228. data/lib/selenium/webdriver/{edge → edge_html}/service.rb +2 -6
  229. data/lib/selenium/webdriver/firefox.rb +18 -15
  230. data/lib/selenium/webdriver/firefox/bridge.rb +1 -1
  231. data/lib/selenium/webdriver/firefox/driver.rb +2 -31
  232. data/lib/selenium/webdriver/firefox/extension.rb +8 -0
  233. data/lib/selenium/webdriver/firefox/options.rb +47 -52
  234. data/lib/selenium/webdriver/firefox/profile.rb +7 -78
  235. data/lib/selenium/webdriver/firefox/service.rb +0 -4
  236. data/lib/selenium/webdriver/ie.rb +8 -7
  237. data/lib/selenium/webdriver/ie/driver.rb +0 -33
  238. data/lib/selenium/webdriver/ie/options.rb +10 -33
  239. data/lib/selenium/webdriver/ie/service.rb +5 -9
  240. data/lib/selenium/webdriver/remote.rb +16 -10
  241. data/lib/selenium/webdriver/remote/bridge.rb +38 -42
  242. data/lib/selenium/webdriver/remote/capabilities.rb +25 -7
  243. data/lib/selenium/webdriver/remote/driver.rb +6 -13
  244. data/lib/selenium/webdriver/remote/http/default.rb +10 -6
  245. data/lib/selenium/webdriver/remote/http/persistent.rb +5 -6
  246. data/lib/selenium/webdriver/safari.rb +16 -8
  247. data/lib/selenium/webdriver/safari/bridge.rb +4 -4
  248. data/lib/selenium/webdriver/safari/driver.rb +3 -30
  249. data/lib/selenium/webdriver/safari/options.rb +18 -19
  250. data/lib/selenium/webdriver/safari/service.rb +0 -4
  251. data/lib/selenium/webdriver/support.rb +1 -0
  252. data/lib/selenium/webdriver/support/color.rb +2 -2
  253. data/lib/selenium/webdriver/support/event_firing_bridge.rb +1 -1
  254. data/lib/selenium/webdriver/support/relative_locator.rb +51 -0
  255. data/lib/selenium/webdriver/version.rb +1 -1
  256. data/selenium-webdriver.gemspec +7 -6
  257. metadata +225 -21
  258. data/lib/selenium/webdriver/firefox/binary.rb +0 -110
  259. data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
@@ -95,7 +95,10 @@ module Selenium
95
95
  def wsl?
96
96
  return false unless linux?
97
97
 
98
- File.read('/proc/version').include?('Microsoft')
98
+ File.read('/proc/version').downcase.include?('microsoft')
99
+ rescue Errno::EACCES
100
+ # the file cannot be accessed on Linux on DeX
101
+ false
99
102
  end
100
103
 
101
104
  def cygwin?
@@ -32,12 +32,10 @@ module Selenium
32
32
 
33
33
  def self.free?(port)
34
34
  Platform.interfaces.each do |host|
35
- begin
36
- TCPServer.new(host, port).close
37
- rescue *IGNORED_ERRORS => ex
38
- WebDriver.logger.debug("port prober could not bind to #{host}:#{port} (#{ex.message})")
39
- # ignored - some machines appear unable to bind to some of their interfaces
40
- end
35
+ TCPServer.new(host, port).close
36
+ rescue *IGNORED_ERRORS => e
37
+ WebDriver.logger.debug("port prober could not bind to #{host}:#{port} (#{e.message})")
38
+ # ignored - some machines appear unable to bind to some of their interfaces
41
39
  end
42
40
 
43
41
  true
@@ -31,8 +31,16 @@ module Selenium
31
31
  base.extend ClassMethods
32
32
  end
33
33
 
34
+ def self.decoded(json)
35
+ JSON.parse(json).fetch('zip')
36
+ end
37
+
38
+ def encoded
39
+ Zipper.zip(layout_on_disk)
40
+ end
41
+
34
42
  def as_json(*)
35
- {"zip" => Zipper.zip(layout_on_disk)}
43
+ {"zip" => encoded}
36
44
  end
37
45
 
38
46
  def to_json(*)
@@ -63,7 +71,7 @@ module Selenium
63
71
 
64
72
  module ClassMethods
65
73
  def from_json(json)
66
- data = JSON.parse(json).fetch('zip')
74
+ data = decoded(json)
67
75
 
68
76
  # can't use Tempfile here since it doesn't support File::BINARY mode on 1.8
69
77
  # can't use Dir.mktmpdir(&blk) because of http://jira.codehaus.org/browse/JRUBY-4082
File without changes
@@ -30,6 +30,7 @@ module Selenium
30
30
  link_text: 'link text',
31
31
  name: 'name',
32
32
  partial_link_text: 'partial link text',
33
+ relative: 'relative',
33
34
  tag_name: 'tag name',
34
35
  xpath: 'xpath'
35
36
  }.freeze
@@ -59,7 +60,7 @@ module Selenium
59
60
  by = FINDERS[how.to_sym]
60
61
  raise ArgumentError, "cannot find element by #{how.inspect}" unless by
61
62
 
62
- bridge.find_element_by by, what.to_s, ref
63
+ bridge.find_element_by by, what, ref
63
64
  rescue Selenium::WebDriver::Error::TimeoutError
64
65
  # Implicit Wait times out in Edge
65
66
  raise Selenium::WebDriver::Error::NoSuchElementError
@@ -77,7 +78,7 @@ module Selenium
77
78
  by = FINDERS[how.to_sym]
78
79
  raise ArgumentError, "cannot find elements by #{how.inspect}" unless by
79
80
 
80
- bridge.find_elements_by by, what.to_s, ref
81
+ bridge.find_elements_by by, what, ref
81
82
  rescue Selenium::WebDriver::Error::TimeoutError
82
83
  # Implicit Wait times out in Edge
83
84
  []
@@ -21,36 +21,40 @@ module Selenium
21
21
  module WebDriver
22
22
  #
23
23
  # Base class implementing default behavior of service object,
24
- # responsible for starting and stopping driver implementations.
24
+ # responsible for storing a service manager configuration.
25
25
  #
26
26
 
27
27
  class Service
28
- START_TIMEOUT = 20
29
- SOCKET_LOCK_TIMEOUT = 45
30
- STOP_TIMEOUT = 20
31
-
32
28
  class << self
33
29
  attr_reader :driver_path
34
30
 
35
- def chrome(*args)
36
- Chrome::Service.new(*args)
31
+ def chrome(**opts)
32
+ Chrome::Service.new(**opts)
37
33
  end
38
34
 
39
- def firefox(*args)
40
- Firefox::Service.new(*args)
35
+ def firefox(**opts)
36
+ Firefox::Service.new(**opts)
41
37
  end
42
38
 
43
- def ie(*args)
44
- IE::Service.new(*args)
39
+ def ie(**opts)
40
+ IE::Service.new(**opts)
45
41
  end
46
42
  alias_method :internet_explorer, :ie
47
43
 
48
- def edge(*args)
49
- Edge::Service.new(*args)
44
+ def edge(**opts)
45
+ Edge::Service.new(**opts)
46
+ end
47
+
48
+ def edge_chrome(**opts)
49
+ EdgeChrome::Service.new(**opts)
50
50
  end
51
51
 
52
- def safari(*args)
53
- Safari::Service.new(*args)
52
+ def edge_html(**opts)
53
+ EdgeHtml::Service.new(**opts)
54
+ end
55
+
56
+ def safari(**opts)
57
+ Safari::Service.new(**opts)
54
58
  end
55
59
 
56
60
  def driver_path=(path)
@@ -60,7 +64,7 @@ module Selenium
60
64
  end
61
65
 
62
66
  attr_accessor :host
63
- attr_reader :executable_path
67
+ attr_reader :executable_path, :port, :extra_args
64
68
 
65
69
  #
66
70
  # End users should use a class method for the desired driver, rather than using this directly.
@@ -82,31 +86,20 @@ module Selenium
82
86
  raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
83
87
  end
84
88
 
85
- def start
86
- raise "already started: #{uri.inspect} #{@executable_path.inspect}" if process_running?
87
-
88
- Platform.exit_hook(&method(:stop)) # make sure we don't leave the server running
89
-
90
- socket_lock.locked do
91
- find_free_port
92
- start_process
93
- connect_until_stable
94
- end
89
+ def launch
90
+ sm = ServiceManager.new(self)
91
+ sm.start
92
+ sm
95
93
  end
96
94
 
97
- def stop
98
- return unless self.class::SHUTDOWN_SUPPORTED
99
-
100
- stop_server
101
- @process.poll_for_exit STOP_TIMEOUT
102
- rescue ChildProcess::TimeoutError
103
- nil # noop
104
- ensure
105
- stop_process
95
+ def shutdown_supported
96
+ self.class::SHUTDOWN_SUPPORTED
106
97
  end
107
98
 
108
- def uri
109
- @uri ||= URI.parse("http://#{@host}:#{@port}")
99
+ protected
100
+
101
+ def extract_service_args(driver_opts)
102
+ driver_opts.key?(:args) ? driver_opts.delete(:args) : []
110
103
  end
111
104
 
112
105
  private
@@ -120,82 +113,6 @@ module Selenium
120
113
  Platform.assert_executable path
121
114
  path
122
115
  end
123
-
124
- def build_process(*command)
125
- WebDriver.logger.debug("Executing Process #{command}")
126
- @process = ChildProcess.build(*command)
127
- if WebDriver.logger.debug?
128
- @process.io.stdout = @process.io.stderr = WebDriver.logger.io
129
- elsif Platform.jruby?
130
- # Apparently we need to read the output of drivers on JRuby.
131
- @process.io.stdout = @process.io.stderr = File.new(Platform.null_device, 'w')
132
- end
133
-
134
- @process
135
- end
136
-
137
- def connect_to_server
138
- Net::HTTP.start(@host, @port) do |http|
139
- http.open_timeout = STOP_TIMEOUT / 2
140
- http.read_timeout = STOP_TIMEOUT / 2
141
-
142
- yield http
143
- end
144
- end
145
-
146
- def find_free_port
147
- @port = PortProber.above(@port)
148
- end
149
-
150
- def start_process
151
- @process = build_process(@executable_path, "--port=#{@port}", *@extra_args)
152
- # Note: this is a bug only in Windows 7
153
- @process.leader = true unless Platform.windows?
154
- @process.start
155
- end
156
-
157
- def stop_process
158
- return if process_exited?
159
-
160
- @process.stop STOP_TIMEOUT
161
- @process.io.stdout.close if Platform.jruby? && !WebDriver.logger.debug?
162
- end
163
-
164
- def stop_server
165
- return if process_exited?
166
-
167
- connect_to_server { |http| http.get('/shutdown') }
168
- end
169
-
170
- def process_running?
171
- defined?(@process) && @process&.alive?
172
- end
173
-
174
- def process_exited?
175
- @process.nil? || @process.exited?
176
- end
177
-
178
- def connect_until_stable
179
- socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
180
- return if socket_poller.connected?
181
-
182
- raise Error::WebDriverError, cannot_connect_error_text
183
- end
184
-
185
- def cannot_connect_error_text
186
- "unable to connect to #{self.class::EXECUTABLE} #{@host}:#{@port}"
187
- end
188
-
189
- def socket_lock
190
- @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
191
- end
192
-
193
- protected
194
-
195
- def extract_service_args(driver_opts)
196
- driver_opts.key?(:args) ? driver_opts.delete(:args) : []
197
- end
198
-
199
116
  end # Service
200
117
  end # WebDriver
201
118
  end # Selenium
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ module Selenium
21
+ module WebDriver
22
+ #
23
+ # Base class implementing default behavior of service_manager object,
24
+ # responsible for starting and stopping driver implementations.
25
+ #
26
+ # @api private
27
+ #
28
+ class ServiceManager
29
+ START_TIMEOUT = 20
30
+ SOCKET_LOCK_TIMEOUT = 45
31
+ STOP_TIMEOUT = 20
32
+
33
+ #
34
+ # End users should use a class method for the desired driver, rather than using this directly.
35
+ #
36
+ # @api private
37
+ #
38
+
39
+ def initialize(config)
40
+ @executable_path = config.executable_path
41
+ @host = Platform.localhost
42
+ @port = config.port
43
+ @extra_args = config.extra_args
44
+ @shutdown_supported = config.shutdown_supported
45
+
46
+ raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
47
+ end
48
+
49
+ def start
50
+ raise "already started: #{uri.inspect} #{@executable_path.inspect}" if process_running?
51
+
52
+ Platform.exit_hook(&method(:stop)) # make sure we don't leave the server running
53
+
54
+ socket_lock.locked do
55
+ find_free_port
56
+ start_process
57
+ connect_until_stable
58
+ end
59
+ end
60
+
61
+ def stop
62
+ return unless @shutdown_supported
63
+
64
+ stop_server
65
+ @process.poll_for_exit STOP_TIMEOUT
66
+ rescue ChildProcess::TimeoutError
67
+ nil # noop
68
+ ensure
69
+ stop_process
70
+ end
71
+
72
+ def uri
73
+ @uri ||= URI.parse("http://#{@host}:#{@port}")
74
+ end
75
+
76
+ private
77
+
78
+ def build_process(*command)
79
+ WebDriver.logger.debug("Executing Process #{command}")
80
+ @process = ChildProcess.build(*command)
81
+ if WebDriver.logger.debug?
82
+ @process.io.stdout = @process.io.stderr = WebDriver.logger.io
83
+ elsif Platform.jruby?
84
+ # Apparently we need to read the output of drivers on JRuby.
85
+ @process.io.stdout = @process.io.stderr = File.new(Platform.null_device, 'w')
86
+ end
87
+
88
+ @process
89
+ end
90
+
91
+ def connect_to_server
92
+ Net::HTTP.start(@host, @port) do |http|
93
+ http.open_timeout = STOP_TIMEOUT / 2
94
+ http.read_timeout = STOP_TIMEOUT / 2
95
+
96
+ yield http
97
+ end
98
+ end
99
+
100
+ def find_free_port
101
+ @port = PortProber.above(@port)
102
+ end
103
+
104
+ def start_process
105
+ @process = build_process(@executable_path, "--port=#{@port}", *@extra_args)
106
+ # Note: this is a bug only in Windows 7
107
+ @process.leader = true unless Platform.windows?
108
+ @process.start
109
+ end
110
+
111
+ def stop_process
112
+ return if process_exited?
113
+
114
+ @process.stop STOP_TIMEOUT
115
+ @process.io.stdout.close if Platform.jruby? && !WebDriver.logger.debug?
116
+ end
117
+
118
+ def stop_server
119
+ return if process_exited?
120
+
121
+ connect_to_server do |http|
122
+ headers = WebDriver::Remote::Http::Common::DEFAULT_HEADERS.dup
123
+ http.get('/shutdown', headers)
124
+ end
125
+ end
126
+
127
+ def process_running?
128
+ defined?(@process) && @process&.alive?
129
+ end
130
+
131
+ def process_exited?
132
+ @process.nil? || @process.exited?
133
+ end
134
+
135
+ def connect_until_stable
136
+ socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
137
+ return if socket_poller.connected?
138
+
139
+ raise Error::WebDriverError, cannot_connect_error_text
140
+ end
141
+
142
+ def cannot_connect_error_text
143
+ "unable to connect to #{@executable_path} #{@host}:#{@port}"
144
+ end
145
+
146
+ def socket_lock
147
+ @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
148
+ end
149
+ end # Service
150
+ end # WebDriver
151
+ end # Selenium
@@ -69,8 +69,8 @@ module Selenium
69
69
  ChildProcess.close_on_exec @server
70
70
 
71
71
  true
72
- rescue SocketError, Errno::EADDRINUSE, Errno::EBADF => ex
73
- WebDriver.logger.debug("#{self}: #{ex.message}")
72
+ rescue SocketError, Errno::EADDRINUSE, Errno::EBADF => e
73
+ WebDriver.logger.debug("#{self}: #{e.message}")
74
74
  false
75
75
  end
76
76
 
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ module Selenium
21
+ module WebDriver
22
+ #
23
+ # @api private
24
+ #
25
+ module TakesScreenshot
26
+ #
27
+ # Save a PNG screenshot to the given path
28
+ #
29
+ # @api public
30
+ #
31
+
32
+ def save_screenshot(png_path)
33
+ extension = File.extname(png_path).downcase
34
+ if extension != '.png'
35
+ WebDriver.logger.warn "name used for saved screenshot does not match file type. "\
36
+ "It should end with .png extension",
37
+ id: :screenshot
38
+ end
39
+ File.open(png_path, 'wb') { |f| f << screenshot_as(:png) }
40
+ end
41
+
42
+ #
43
+ # Return a PNG screenshot in the given format as a string
44
+ #
45
+ # @param [:base64, :png] format
46
+ # @return String screenshot
47
+ #
48
+ # @api public
49
+
50
+ def screenshot_as(format)
51
+ case format
52
+ when :base64
53
+ screenshot
54
+ when :png
55
+ screenshot.unpack1('m')
56
+ else
57
+ raise Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
58
+ end
59
+ end
60
+
61
+ end # TakesScreenshot
62
+ end # WebDriver
63
+ end # Selenium