Skip to content

Commit c904940

Browse files
authored
Merge pull request #697 from seleniumbase/improve-file-downloads
Improve file downloads - disable automation prompts
2 parents 54410d9 + e060090 commit c904940

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

examples/test_download_files.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class DownloadTests(BaseCase):
5+
6+
def test_download_files(self):
7+
self.open("https://pypi.org/project/seleniumbase/#files")
8+
pkg_header = self.get_text("h1.package-header__name")
9+
pkg_name = pkg_header.replace(" ", "-")
10+
whl_file = pkg_name + "-py2.py3-none-any.whl"
11+
self.click('div#files a[href$="%s"]' % whl_file)
12+
self.assert_downloaded_file(whl_file)
13+
tar_gz_file = pkg_name + ".tar.gz"
14+
self.click('div#files a[href$="%s"]' % tar_gz_file)
15+
self.assert_downloaded_file(tar_gz_file)

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ ipython==7.16.1;python_version>="3.6" and python_version<"3.7"
5454
ipython==7.18.1;python_version>="3.7"
5555
colorama==0.4.3
5656
pymysql==0.10.1
57-
coverage==5.2.1
57+
coverage==5.3
5858
brython==3.8.10
5959
pyotp==2.4.0
6060
boto==2.49.0
6161
cffi==1.14.2
62-
rich==6.1.2;python_version>="3.6" and python_version<"4.0"
62+
rich==6.2.0;python_version>="3.6" and python_version<"4.0"
6363
flake8==3.7.9;python_version<"3.5"
6464
flake8==3.8.3;python_version>="3.5"
6565
pyflakes==2.1.1;python_version<"3.5"

seleniumbase/core/browser_launcher.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ def _set_chrome_options(
145145
"safebrowsing.enabled": False,
146146
"safebrowsing.disable_download_protection": True,
147147
"profile": {
148-
"password_manager_enabled": False
148+
"password_manager_enabled": False,
149+
"default_content_setting_values.automatic_downloads": 1
149150
}
150151
}
151152
if locale_code:
@@ -349,11 +350,14 @@ def _create_firefox_profile(
349350
"browser.download.animateNotifications", False)
350351
profile.set_preference("browser.download.dir", downloads_path)
351352
profile.set_preference("browser.download.folderList", 2)
353+
profile.set_preference("browser.helperApps.alwaysAsk.force", False)
354+
profile.set_preference(
355+
"browser.download.manager.showWhenStarting", False)
352356
profile.set_preference(
353357
"browser.helperApps.neverAsk.saveToDisk",
354358
("application/pdf, application/zip, application/octet-stream, "
355359
"text/csv, text/xml, application/xml, text/plain, "
356-
"text/octet-stream, "
360+
"text/octet-stream, application/x-gzip, application/x-tar "
357361
"application/"
358362
"vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
359363
return profile
@@ -761,7 +765,8 @@ def get_local_driver(
761765
"safebrowsing.enabled": False,
762766
"safebrowsing.disable_download_protection": True,
763767
"profile": {
764-
"password_manager_enabled": False
768+
"password_manager_enabled": False,
769+
"default_content_setting_values.automatic_downloads": 1
765770
}
766771
}
767772
if locale_code:

seleniumbase/fixtures/base_case.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,8 +2853,8 @@ def is_downloaded_file_present(self, file):
28532853
def assert_downloaded_file(self, file, timeout=None):
28542854
""" Asserts that the file exists in the Downloads Folder. """
28552855
if not timeout:
2856-
timeout = settings.SMALL_TIMEOUT
2857-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
2856+
timeout = settings.LARGE_TIMEOUT
2857+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
28582858
timeout = self.__get_new_timeout(timeout)
28592859
start_ms = time.time() * 1000.0
28602860
stop_ms = start_ms + (timeout * 1000.0)

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
setup(
5656
name='seleniumbase',
57-
version='1.49.12',
57+
version='1.49.13',
5858
description='Web Automation and Test Framework - https://seleniumbase.io',
5959
long_description=long_description,
6060
long_description_content_type='text/markdown',
@@ -146,12 +146,12 @@
146146
'ipython==7.18.1;python_version>="3.7"',
147147
'colorama==0.4.3',
148148
'pymysql==0.10.1',
149-
'coverage==5.2.1',
149+
'coverage==5.3',
150150
'brython==3.8.10',
151151
'pyotp==2.4.0',
152152
'boto==2.49.0',
153153
'cffi==1.14.2',
154-
'rich==6.1.2;python_version>="3.6" and python_version<"4.0"',
154+
'rich==6.2.0;python_version>="3.6" and python_version<"4.0"',
155155
'flake8==3.7.9;python_version<"3.5"',
156156
'flake8==3.8.3;python_version>="3.5"',
157157
'pyflakes==2.1.1;python_version<"3.5"',

0 commit comments

Comments
 (0)