Skip to content

Improve file downloads - disable automation prompts #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/test_download_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from seleniumbase import BaseCase


class DownloadTests(BaseCase):

def test_download_files(self):
self.open("https://pypi.org/project/seleniumbase/#files")
pkg_header = self.get_text("h1.package-header__name")
pkg_name = pkg_header.replace(" ", "-")
whl_file = pkg_name + "-py2.py3-none-any.whl"
self.click('div#files a[href$="%s"]' % whl_file)
self.assert_downloaded_file(whl_file)
tar_gz_file = pkg_name + ".tar.gz"
self.click('div#files a[href$="%s"]' % tar_gz_file)
self.assert_downloaded_file(tar_gz_file)
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ ipython==7.16.1;python_version>="3.6" and python_version<"3.7"
ipython==7.18.1;python_version>="3.7"
colorama==0.4.3
pymysql==0.10.1
coverage==5.2.1
coverage==5.3
brython==3.8.10
pyotp==2.4.0
boto==2.49.0
cffi==1.14.2
rich==6.1.2;python_version>="3.6" and python_version<"4.0"
rich==6.2.0;python_version>="3.6" and python_version<"4.0"
flake8==3.7.9;python_version<"3.5"
flake8==3.8.3;python_version>="3.5"
pyflakes==2.1.1;python_version<"3.5"
Expand Down
11 changes: 8 additions & 3 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ def _set_chrome_options(
"safebrowsing.enabled": False,
"safebrowsing.disable_download_protection": True,
"profile": {
"password_manager_enabled": False
"password_manager_enabled": False,
"default_content_setting_values.automatic_downloads": 1
}
}
if locale_code:
Expand Down Expand Up @@ -349,11 +350,14 @@ def _create_firefox_profile(
"browser.download.animateNotifications", False)
profile.set_preference("browser.download.dir", downloads_path)
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.helperApps.alwaysAsk.force", False)
profile.set_preference(
"browser.download.manager.showWhenStarting", False)
profile.set_preference(
"browser.helperApps.neverAsk.saveToDisk",
("application/pdf, application/zip, application/octet-stream, "
"text/csv, text/xml, application/xml, text/plain, "
"text/octet-stream, "
"text/octet-stream, application/x-gzip, application/x-tar "
"application/"
"vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
return profile
Expand Down Expand Up @@ -761,7 +765,8 @@ def get_local_driver(
"safebrowsing.enabled": False,
"safebrowsing.disable_download_protection": True,
"profile": {
"password_manager_enabled": False
"password_manager_enabled": False,
"default_content_setting_values.automatic_downloads": 1
}
}
if locale_code:
Expand Down
4 changes: 2 additions & 2 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -2853,8 +2853,8 @@ def is_downloaded_file_present(self, file):
def assert_downloaded_file(self, file, timeout=None):
""" Asserts that the file exists in the Downloads Folder. """
if not timeout:
timeout = settings.SMALL_TIMEOUT
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
timeout = settings.LARGE_TIMEOUT
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
timeout = self.__get_new_timeout(timeout)
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

setup(
name='seleniumbase',
version='1.49.12',
version='1.49.13',
description='Web Automation and Test Framework - https://seleniumbase.io',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down Expand Up @@ -146,12 +146,12 @@
'ipython==7.18.1;python_version>="3.7"',
'colorama==0.4.3',
'pymysql==0.10.1',
'coverage==5.2.1',
'coverage==5.3',
'brython==3.8.10',
'pyotp==2.4.0',
'boto==2.49.0',
'cffi==1.14.2',
'rich==6.1.2;python_version>="3.6" and python_version<"4.0"',
'rich==6.2.0;python_version>="3.6" and python_version<"4.0"',
'flake8==3.7.9;python_version<"3.5"',
'flake8==3.8.3;python_version>="3.5"',
'pyflakes==2.1.1;python_version<"3.5"',
Expand Down