selenium-webdriver 4.0.0.beta2 → 4.0.0.rc2

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +1947 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE +202 -0
  5. data/NOTICE +2 -0
  6. data/README.md +34 -0
  7. data/lib/selenium/webdriver/atoms/findElements.js +0 -0
  8. data/lib/selenium/webdriver/atoms/getAttribute.js +25 -25
  9. data/lib/selenium/webdriver/atoms/isDisplayed.js +0 -0
  10. data/lib/selenium/webdriver/chrome/driver.rb +16 -4
  11. data/lib/selenium/webdriver/chrome/features.rb +44 -4
  12. data/lib/selenium/webdriver/chrome/options.rb +25 -2
  13. data/lib/selenium/webdriver/chrome/profile.rb +5 -2
  14. data/lib/selenium/webdriver/common/driver.rb +5 -1
  15. data/lib/selenium/webdriver/common/driver_extensions/full_page_screenshot.rb +43 -0
  16. data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +51 -0
  17. data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +77 -0
  18. data/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb +38 -0
  19. data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +45 -0
  20. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +0 -17
  21. data/lib/selenium/{devtools.rb → webdriver/common/driver_extensions/has_launching.rb} +16 -8
  22. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +1 -6
  23. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +8 -0
  24. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +87 -18
  25. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +11 -11
  26. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +77 -0
  27. data/lib/selenium/webdriver/common/driver_extensions/prints_page.rb +28 -1
  28. data/lib/selenium/webdriver/common/element.rb +35 -6
  29. data/lib/selenium/webdriver/common/error.rb +12 -0
  30. data/lib/selenium/webdriver/common/log_entry.rb +2 -2
  31. data/lib/selenium/webdriver/common/manager.rb +3 -13
  32. data/lib/selenium/webdriver/common/options.rb +31 -12
  33. data/lib/selenium/webdriver/common/proxy.rb +2 -2
  34. data/lib/selenium/webdriver/common/shadow_root.rb +87 -0
  35. data/lib/selenium/webdriver/common/socket_poller.rb +19 -30
  36. data/lib/selenium/webdriver/common/takes_screenshot.rb +9 -6
  37. data/lib/selenium/webdriver/common/target_locator.rb +28 -0
  38. data/lib/selenium/webdriver/common/window.rb +0 -4
  39. data/lib/selenium/webdriver/common.rb +8 -0
  40. data/lib/selenium/webdriver/devtools/pinned_script.rb +59 -0
  41. data/lib/selenium/webdriver/devtools/request.rb +27 -17
  42. data/lib/selenium/webdriver/devtools/response.rb +66 -0
  43. data/lib/selenium/webdriver/devtools.rb +50 -12
  44. data/lib/selenium/webdriver/edge/features.rb +5 -0
  45. data/lib/selenium/webdriver/edge/options.rb +0 -0
  46. data/lib/selenium/webdriver/edge/profile.rb +0 -0
  47. data/lib/selenium/webdriver/firefox/driver.rb +15 -2
  48. data/lib/selenium/webdriver/firefox/features.rb +20 -1
  49. data/lib/selenium/webdriver/firefox/options.rb +24 -1
  50. data/lib/selenium/webdriver/firefox.rb +0 -1
  51. data/lib/selenium/webdriver/ie/options.rb +3 -1
  52. data/lib/selenium/webdriver/ie/service.rb +1 -1
  53. data/lib/selenium/webdriver/remote/bridge.rb +43 -13
  54. data/lib/selenium/webdriver/remote/capabilities.rb +97 -53
  55. data/lib/selenium/webdriver/remote/commands.rb +5 -0
  56. data/lib/selenium/webdriver/remote/driver.rb +7 -7
  57. data/lib/selenium/webdriver/remote.rb +1 -1
  58. data/lib/selenium/webdriver/safari/driver.rb +1 -1
  59. data/lib/selenium/webdriver/safari/options.rb +7 -0
  60. data/lib/selenium/webdriver/support/cdp/domain.rb.erb +63 -0
  61. data/lib/selenium/webdriver/support/cdp_client_generator.rb +108 -0
  62. data/lib/selenium/webdriver/support/event_firing_bridge.rb +2 -2
  63. data/lib/selenium/webdriver/version.rb +1 -1
  64. data/lib/selenium/webdriver.rb +1 -1
  65. data/selenium-webdriver.gemspec +63 -0
  66. metadata +60 -44
@@ -0,0 +1,43 @@
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
+ module DriverExtensions
23
+ module FullPageScreenshot
24
+ #
25
+ # Save a PNG screenshot of the full page to the given path
26
+ #
27
+ # @api public
28
+ #
29
+
30
+ def save_full_page_screenshot(path)
31
+ save_screenshot(path, full_page: true)
32
+ end
33
+
34
+ private
35
+
36
+ def full_screenshot
37
+ @bridge.full_screenshot
38
+ end
39
+
40
+ end # FullPageScreenshot
41
+ end # DriverExtensions
42
+ end # WebDriver
43
+ end # Selenium
@@ -0,0 +1,51 @@
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
+ module DriverExtensions
23
+ module HasApplePermissions
24
+
25
+ #
26
+ # Returns permissions.
27
+ #
28
+ # @return [Hash]
29
+ #
30
+
31
+ def permissions
32
+ @bridge.permissions
33
+ end
34
+
35
+ #
36
+ # Sets permissions.
37
+ #
38
+ # @example
39
+ # driver.permissions = {'getUserMedia' => true}
40
+ #
41
+ # @param [Hash<Symbol, Boolean>] permissions
42
+ #
43
+
44
+ def permissions=(permissions)
45
+ @bridge.permissions = permissions
46
+ end
47
+
48
+ end # HasPermissions
49
+ end # DriverExtensions
50
+ end # WebDriver
51
+ end # Selenium
@@ -0,0 +1,77 @@
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
+ module DriverExtensions
23
+ module HasCasting
24
+
25
+ #
26
+ # What devices ("sinks") are available to be cast to.
27
+ #
28
+ # @return [Array] list of sinks available for casting with id and name values
29
+ #
30
+
31
+ def cast_sinks
32
+ @bridge.cast_sinks
33
+ end
34
+
35
+ #
36
+ # Sets a specific sink, using its name, as a Cast session receiver target.
37
+ #
38
+ # @param [String] name the sink to use as the target
39
+ #
40
+
41
+ def cast_sink_to_use=(name)
42
+ @bridge.cast_sink_to_use = name
43
+ end
44
+
45
+ #
46
+ # Starts a tab mirroring session on a specific receiver target.
47
+ #
48
+ # @param [String] name the sink to use as the target
49
+ #
50
+
51
+ def start_cast_tab_mirroring(name)
52
+ @bridge.start_cast_tab_mirroring(name)
53
+ end
54
+
55
+ #
56
+ # Gets error messages when there is any issue in a Cast session.
57
+ #
58
+ # @return [String] the error message
59
+ #
60
+
61
+ def cast_issue_message
62
+ @bridge.cast_issue_message
63
+ end
64
+
65
+ #
66
+ # Stops the existing Cast session on a specific receiver target.
67
+ #
68
+ # @param [String] name the sink to stop the Cast session
69
+ #
70
+
71
+ def stop_casting(name)
72
+ @bridge.stop_casting(name)
73
+ end
74
+ end # HasCasting
75
+ end # DriverExtensions
76
+ end # WebDriver
77
+ end # Selenium
@@ -0,0 +1,38 @@
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
+ module DriverExtensions
23
+ module HasCDP
24
+
25
+ #
26
+ # Returns network conditions.
27
+ #
28
+ # @return [Hash]
29
+ #
30
+
31
+ def execute_cdp(cmd, **params)
32
+ @bridge.send_command(cmd: cmd, params: params)
33
+ end
34
+
35
+ end # HasCDP
36
+ end # DriverExtensions
37
+ end # WebDriver
38
+ end # Selenium
@@ -0,0 +1,45 @@
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
+ module DriverExtensions
23
+ module HasContext
24
+
25
+ #
26
+ # Sets the context that Selenium commands are running in using
27
+ # a `with` statement. The state of the context on the server is
28
+ # saved before entering the block, and restored upon exiting it.
29
+ #
30
+ # @param [String] name which permission to set
31
+ # @param [String] value what to set the permission to
32
+ #
33
+
34
+ def context=(value)
35
+ @bridge.context = value
36
+ end
37
+
38
+ def context
39
+ @bridge.context
40
+ end
41
+
42
+ end # HasContext
43
+ end # DriverExtensions
44
+ end # WebDriver
45
+ end # Selenium
@@ -37,23 +37,6 @@ module Selenium
37
37
  end
38
38
  end
39
39
 
40
- private
41
-
42
- def devtools_version
43
- return Firefox::DEVTOOLS_VERSION if browser == :firefox
44
-
45
- Integer(capabilities.browser_version.split('.').first)
46
- end
47
-
48
- def devtools_url
49
- return devtools_address if devtools_address.include?('/session/')
50
-
51
- uri = URI(devtools_address)
52
- response = Net::HTTP.get(uri.hostname, '/json/version', uri.port)
53
-
54
- JSON.parse(response)['webSocketDebuggerUrl']
55
- end
56
-
57
40
  end # HasDevTools
58
41
  end # DriverExtensions
59
42
  end # WebDriver
@@ -18,13 +18,21 @@
18
18
  # under the License.
19
19
 
20
20
  module Selenium
21
- module DevTools
22
- class << self
23
- attr_accessor :version
21
+ module WebDriver
22
+ module DriverExtensions
23
+ module HasLaunching
24
24
 
25
- def load_version
26
- require "selenium/devtools/v#{@version}"
27
- end
28
- end
29
- end # DevTools
25
+ #
26
+ # Launches Chromium app specified by id.
27
+ #
28
+ # @param [String] id
29
+ #
30
+
31
+ def launch_app(id)
32
+ @bridge.launch_app(id)
33
+ end
34
+
35
+ end # HasLaunching
36
+ end # DriverExtensions
37
+ end # WebDriver
30
38
  end # Selenium
@@ -112,8 +112,7 @@ module Selenium
112
112
 
113
113
  devtools.runtime.add_binding(name: '__webdriver_attribute')
114
114
  execute_script(mutation_listener)
115
- script = devtools.page.add_script_to_evaluate_on_new_document(source: mutation_listener)
116
- pinned_scripts[mutation_listener] = script['identifier']
115
+ devtools.page.add_script_to_evaluate_on_new_document(source: mutation_listener)
117
116
 
118
117
  devtools.runtime.on(:binding_called, &method(:log_mutation_event))
119
118
  end
@@ -139,10 +138,6 @@ module Selenium
139
138
  @mutation_listener ||= read_atom(:mutationListener)
140
139
  end
141
140
 
142
- def pinned_scripts
143
- @pinned_scripts ||= {}
144
- end
145
-
146
141
  end # HasLogEvents
147
142
  end # DriverExtensions
148
143
  end # WebDriver
@@ -45,6 +45,14 @@ module Selenium
45
45
  @bridge.network_conditions = conditions
46
46
  end
47
47
 
48
+ #
49
+ # Resets Chromium network emulation settings.
50
+ #
51
+
52
+ def delete_network_conditions
53
+ @bridge.delete_network_conditions
54
+ end
55
+
48
56
  end # HasNetworkConditions
49
57
  end # DriverExtensions
50
58
  end # WebDriver
@@ -28,39 +28,108 @@ module Selenium
28
28
  # a stubbed response instead.
29
29
  #
30
30
  # @example Log requests and pass through
31
- # driver.intercept do |request|
31
+ # driver.intercept do |request, &continue|
32
32
  # puts "#{request.method} #{request.url}"
33
- # request.continue
33
+ # continue.call(request)
34
34
  # end
35
35
  #
36
- # @example Stub response for image requests
37
- # driver.intercept do |request|
36
+ # @example Stub requests for images
37
+ # driver.intercept do |request, &continue|
38
38
  # if request.url.match?(/\.png$/)
39
- # request.respond(body: File.read('myfile.png'))
40
- # else
41
- # request.continue
39
+ # request.url = 'https://upload.wikimedia.org/wikipedia/commons/d/d5/Selenium_Logo.png'
42
40
  # end
41
+ # continue.call(request)
43
42
  # end
44
43
  #
45
- # @param [#call] block which is called when request is interecepted
46
- # @yieldparam [DevTools::Request]
44
+ # @example Log responses and pass through
45
+ # driver.intercept do |request, &continue|
46
+ # continue.call(request) do |response|
47
+ # puts "#{response.code} #{response.body}"
48
+ # end
49
+ # end
50
+ #
51
+ # @example Mutate specific response
52
+ # driver.intercept do |request, &continue|
53
+ # continue.call(request) do |response|
54
+ # response.body << 'Added by Selenium!' if request.url.include?('/myurl')
55
+ # end
56
+ # end
57
+ #
58
+ # @param [Proc] block which is called when request is intercepted
59
+ # @yieldparam [DevTools::Request] request
60
+ # @yieldparam [Proc] continue block which proceeds with the request and optionally yields response
47
61
  #
48
62
 
49
- def intercept
63
+ def intercept(&block)
50
64
  devtools.network.set_cache_disabled(cache_disabled: true)
51
65
  devtools.fetch.on(:request_paused) do |params|
52
- request = DevTools::Request.new(
53
- devtools: devtools,
54
- id: params['requestId'],
55
- url: params.dig('request', 'url'),
56
- method: params.dig('request', 'method'),
57
- headers: params.dig('request', 'headers')
66
+ id = params['requestId']
67
+ if params.key?('responseStatusCode') || params.key?('responseErrorReason')
68
+ intercept_response(id, params, &pending_response_requests.delete(id))
69
+ else
70
+ intercept_request(id, params, &block)
71
+ end
72
+ end
73
+ devtools.fetch.enable(patterns: [{requestStage: 'Request'}, {requestStage: 'Response'}])
74
+ end
75
+
76
+ private
77
+
78
+ def pending_response_requests
79
+ @pending_response_requests ||= {}
80
+ end
81
+
82
+ def intercept_request(id, params, &block)
83
+ original = DevTools::Request.from(id, params)
84
+ mutable = DevTools::Request.from(id, params)
85
+
86
+ block.call(mutable) do |&continue| # rubocop:disable Performance/RedundantBlockCall
87
+ pending_response_requests[id] = continue
88
+
89
+ if original == mutable
90
+ devtools.fetch.continue_request(request_id: id)
91
+ else
92
+ devtools.fetch.continue_request(
93
+ request_id: id,
94
+ url: mutable.url,
95
+ method: mutable.method,
96
+ post_data: mutable.post_data,
97
+ headers: mutable.headers.map do |k, v|
98
+ {name: k, value: v}
99
+ end
100
+ )
101
+ end
102
+ end
103
+ end
104
+
105
+ def intercept_response(id, params)
106
+ return devtools.fetch.continue_request(request_id: id) unless block_given?
107
+
108
+ body = fetch_response_body(id)
109
+ original = DevTools::Response.from(id, body, params)
110
+ mutable = DevTools::Response.from(id, body, params)
111
+ yield mutable
112
+
113
+ if original == mutable
114
+ devtools.fetch.continue_request(request_id: id)
115
+ else
116
+ devtools.fetch.fulfill_request(
117
+ request_id: id,
118
+ body: (Base64.strict_encode64(mutable.body) if mutable.body),
119
+ response_code: mutable.code,
120
+ response_headers: mutable.headers.map do |k, v|
121
+ {name: k, value: v}
122
+ end
58
123
  )
59
- yield request
60
124
  end
61
- devtools.fetch.enable
62
125
  end
63
126
 
127
+ def fetch_response_body(id)
128
+ devtools.fetch.get_response_body(request_id: id).dig('result', 'body')
129
+ rescue Error::WebDriverError
130
+ # CDP fails to get body on certain responses (301) and raises:
131
+ # Can only get response body on requests captured after headers received.
132
+ end
64
133
  end # HasNetworkInterception
65
134
  end # DriverExtensions
66
135
  end # WebDriver
@@ -23,26 +23,26 @@ module Selenium
23
23
  module HasPermissions
24
24
 
25
25
  #
26
- # Returns permissions.
26
+ # Set one permission.
27
27
  #
28
- # @return [Hash]
28
+ # @param [String] name which permission to set
29
+ # @param [String] value what to set the permission to
29
30
  #
30
31
 
31
- def permissions
32
- @bridge.permissions
32
+ def add_permission(name, value)
33
+ @bridge.set_permission(name, value)
33
34
  end
34
35
 
35
36
  #
36
- # Sets permissions.
37
+ # Set multiple permissions.
37
38
  #
38
- # @example
39
- # driver.permissions = {'getUserMedia' => true}
40
- #
41
- # @param [Hash<Symbol, Boolean>] permissions
39
+ # @param [Hash] opt key/value pairs to set permissions
42
40
  #
43
41
 
44
- def permissions=(permissions)
45
- @bridge.permissions = permissions
42
+ def add_permissions(opt)
43
+ opt.each do |key, value|
44
+ @bridge.set_permission(key, value)
45
+ end
46
46
  end
47
47
 
48
48
  end # HasPermissions
@@ -0,0 +1,77 @@
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
+ module DriverExtensions
23
+ module HasPinnedScripts
24
+
25
+ #
26
+ # Returns the list of all pinned scripts.
27
+ #
28
+ # @return [Array<DevTools::PinnedScript>]
29
+ #
30
+
31
+ def pinned_scripts
32
+ @pinned_scripts ||= []
33
+ end
34
+
35
+ #
36
+ # Pins JavaScript snippet that is available during the whole
37
+ # session on every page. This allows to store and call
38
+ # scripts without sending them over the wire every time.
39
+ #
40
+ # @example
41
+ # script = driver.pin_script('return window.location.href')
42
+ # driver.execute_script(script)
43
+ # # navigate to a new page
44
+ # driver.execute_script(script)
45
+ #
46
+ # @param [String] script
47
+ # @return [DevTools::PinnedScript]
48
+ #
49
+
50
+ def pin_script(script)
51
+ script = DevTools::PinnedScript.new(script)
52
+ pinned_scripts << script
53
+
54
+ devtools.page.enable
55
+ devtools.runtime.evaluate(expression: script.callable)
56
+ response = devtools.page.add_script_to_evaluate_on_new_document(source: script.callable)
57
+ script.devtools_identifier = response.dig('result', 'identifier')
58
+
59
+ script
60
+ end
61
+
62
+ #
63
+ # Unpins script making it undefined for the subsequent calls.
64
+ #
65
+ # @param [DevTools::PinnedScript]
66
+ #
67
+
68
+ def unpin_script(script)
69
+ devtools.runtime.evaluate(expression: script.remove)
70
+ devtools.page.remove_script_to_evaluate_on_new_document(identifier: script.devtools_identifier)
71
+ pinned_scripts.delete(script)
72
+ end
73
+
74
+ end # HasPinnedScripts
75
+ end # DriverExtensions
76
+ end # WebDriver
77
+ end # Selenium
@@ -21,8 +21,35 @@ module Selenium
21
21
  module WebDriver
22
22
  module DriverExtensions
23
23
  module PrintsPage
24
+ #
25
+ # Save a page as a PDF to the given path
26
+ #
27
+ # @example Save Printed Page
28
+ # driver.save_print_page('../printed_page.pdf')
29
+ #
30
+ # @param [String] path to where the pdf should be saved
31
+ #
32
+ # @api public
33
+ #
34
+
35
+ def save_print_page(path, **options)
36
+ File.open(path, 'wb') do |file|
37
+ content = Base64.decode64 print_page(**options)
38
+ file << content
39
+ end
40
+ end
41
+
42
+ #
43
+ # Return a Base64 encoded Print Page as a string
44
+ #
45
+ # @see https://w3c.github.io/webdriver/#print-page
46
+ #
47
+ # @api public
48
+ #
49
+
24
50
  def print_page(**options)
25
- options[:page_ranges] &&= Array(options[:page_ranges])
51
+ options[:pageRanges] = Array(options.delete(:page_ranges)) || []
52
+ options[:shrinkToFit] = options.delete(:shrink_to_fit) { true }
26
53
 
27
54
  @bridge.print_page(options)
28
55
  end