-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
…ds to Chrome DevTools debugger. For some reason specs for headless mode are not passing. Refer: bayandin/chromedriver@9d18be0
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# 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 CommunicatesToDevTools | ||
|
||
# | ||
# Send commands to the Chrome DevTools Debugger. | ||
# Refer: https://chromedevtools.github.io/devtools-protocol/ | ||
# | ||
# @example | ||
# driver.send_devtools_command('Page.navigate', {url: 'http://www.google.com'}) | ||
# | ||
# @param [String] command The command to send to DevTools. | ||
# @param [Hash] parameters The paramters of the respective command. | ||
# | ||
|
||
def send_devtools_command(command, parameters) | ||
@bridge.send_devtools_command(command, parameters) | ||
end | ||
|
||
# | ||
# Chrome's headless mode has Downloads disabled by default. | ||
# Use this method to enable it and set a download directory | ||
# | ||
# @example | ||
# driver.download_path='/some/dir/which/exists/' | ||
# | ||
# @param [String] path The path to set as the download directory | ||
# | ||
|
||
def download_path=(path) | ||
@bridge.send_devtools_command('Page.setDownloadBehavior', behavior: 'allow', downloadPath: path) | ||
end | ||
|
||
end # CommunicatesToDevTools | ||
end # DriverExtensions | ||
end # WebDriver | ||
end # Selenium |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,57 @@ module Chrome | |
'upload_throughput' => 789 | ||
) | ||
end | ||
|
||
context "DevTools communication" do | ||
it 'can send commands to DevTools' do | ||
driver.send_devtools_command('Page.navigate', url: url_for('blank.html')) | ||
expect(driver.title).to eq('blank') | ||
driver.send_devtools_command('Page.navigate', url: url_for('colorPage.html')) | ||
expect(driver.title).to eq('Color Page') | ||
end | ||
|
||
describe('#set_download_path') do | ||
let(:download_path) { Dir.mktmpdir } | ||
let(:file_to_download) { "blank.html" } | ||
let(:final_path_to_downloaded_file) { download_path + "/" + file_to_download } | ||
let(:page_to_download_from) do | ||
'data:text/html,'\ | ||
'<!DOCTYPE html>'\ | ||
'<div>'\ | ||
'<a download="" href="' + url_for(file_to_download) + '">Go!</a>'\ | ||
'</div>'\ | ||
'</html>' | ||
end | ||
|
||
before(:each) do | ||
File.delete(final_path_to_downloaded_file) if File.exist?(final_path_to_downloaded_file) | ||
end | ||
|
||
it 'can download files in headless mode' do | ||
options = Selenium::WebDriver::Chrome::Options.new | ||
options.headless! | ||
local_driver = WebDriver::Driver.for(:chrome, options: options) | ||
local_driver.download_path = download_path | ||
local_driver.get(page_to_download_from) | ||
|
||
local_driver.find_element(css: 'a').click | ||
|
||
sleep 3 | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pulkitsharma07
Author
Owner
|
||
local_driver.quit | ||
expect(File).to exist(final_path_to_downloaded_file) | ||
end | ||
|
||
it 'can download files in non-headless mode' do | ||
driver.download_path = download_path | ||
driver.get(page_to_download_from) | ||
|
||
driver.find_element(css: 'a').click | ||
|
||
sleep 3 | ||
expect(File).to exist(final_path_to_downloaded_file) | ||
end | ||
end | ||
end | ||
end | ||
end # Chrome | ||
end # WebDriver | ||
|
2 comments
on commit 1142e0b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dreyks - If after the updated chrome releases your specific use case is not fixed. Could you maybe look into raising a separate specific issue, for the specific case with _blank
.
Even if it's a non-issue. It would provide some much needed compartmentalisation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do. thank you for your time
Optimisation, wait for this file not to have a uuid temporary suffix. Will shave a couple of seconds off runtime. (In both areas)