Skip to content

Commit

Permalink
Added ability to direct headless chrome to save files in ruby Driver
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Rodionov <[email protected]>
  • Loading branch information
pelly authored and p0deje committed May 25, 2018
1 parent 894b67a commit f77d2f9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rb/lib/selenium/webdriver/chrome/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module Bridge

COMMANDS = {
get_network_conditions: [:get, '/session/:session_id/chromium/network_conditions'.freeze],
set_network_conditions: [:post, '/session/:session_id/chromium/network_conditions'.freeze]
set_network_conditions: [:post, '/session/:session_id/chromium/network_conditions'.freeze],
send_command: [:post, '/session/:session_id/chromium/send_command'.freeze]
}.freeze

def commands(command)
Expand All @@ -33,6 +34,10 @@ def network_conditions
execute :get_network_conditions
end

def send_command(command_params)
execute :send_command, {}, command_params
end

def network_conditions=(conditions)
execute :set_network_conditions, {}, {network_conditions: conditions}
end
Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/chrome/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Driver < WebDriver::Driver
include DriverExtensions::HasTouchScreen
include DriverExtensions::HasWebStorage
include DriverExtensions::TakesScreenshot
include DriverExtensions::DownloadsFiles

def initialize(opts = {})
opts[:desired_capabilities] = create_capabilities(opts)
Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
require 'selenium/webdriver/common/driver_extensions/takes_screenshot'
require 'selenium/webdriver/common/driver_extensions/rotatable'
require 'selenium/webdriver/common/driver_extensions/has_web_storage'
require 'selenium/webdriver/common/driver_extensions/downloads_files'
require 'selenium/webdriver/common/driver_extensions/has_location'
require 'selenium/webdriver/common/driver_extensions/has_session_id'
require 'selenium/webdriver/common/driver_extensions/has_touch_screen'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

module Selenium
module WebDriver
module DriverExtensions
module DownloadsFiles

#
# sets downloading of files to spcified location
#
#

def downloads_files_to(path:"tmp")
params = {
'cmd' =>'Page.setDownloadBehavior',
"params" => {"behavior" => 'allow', 'downloadPath' => path }
}
@bridge.send_command(params)
end

end # HasNetworkConditions
end # DriverExtensions
end # WebDriver
end # Selenium

0 comments on commit f77d2f9

Please sign in to comment.