Skip to content

Commit 85a20d0

Browse files
committed
Add option: "--archive-downloads" to keep downloaded files
1 parent 0bbbde1 commit 85a20d0

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ The code above will leave your browser window open in case there's a failure. (i
359359
--headed # (Run tests with a GUI on Linux OS.)
360360
--locale=LOCALE_CODE # (Set the Language Locale Code for the web browser.)
361361
--start-page=URL # (The starting URL for the web browser when tests begin.)
362-
--archive-logs # (Archive old log files instead of deleting them.)
362+
--archive-logs # (Archive existing log files instead of deleting them.)
363+
--archive-downloads # (Archive old downloads instead of deleting them.)
363364
--time-limit=SECONDS # (Safely fail any test that exceeds the time limit.)
364365
--slow # (Slow down the automation. Faster than using Demo Mode.)
365366
--demo # (Slow down and visually see test actions as they occur.)

help_docs/customizing_test_runs.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ SeleniumBase provides additional ``pytest`` command-line options for tests:
117117
--headed # (Run tests with a GUI on Linux OS.)
118118
--locale=LOCALE_CODE # (Set the Language Locale Code for the web browser.)
119119
--start-page=URL # (The starting URL for the web browser when tests begin.)
120-
--archive-logs # (Archive old log files instead of deleting them.)
120+
--archive-logs # (Archive existing log files instead of deleting them.)
121+
--archive-downloads # (Archive old downloads instead of deleting them.)
121122
--time-limit=SECONDS # (Safely fail any test that exceeds the time limit.)
122123
--slow # (Slow down the automation. Faster than using Demo Mode.)
123124
--demo # (Slow down and visually see test actions as they occur.)

seleniumbase/core/download_helper.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
from seleniumbase.config import settings
55
from seleniumbase.fixtures import constants
66

7-
# Folder for saving downloaded files.
8-
# If initiated by WebDriver clicks, works ONLY for Chrome and Firefox.
9-
# Browser used doesn't matter if done with self.download_file(file_url)
10-
# or self.save_file_as(file_url, new_file_name)
7+
# The "downloads_folder" is a folder for saving downloaded files.
8+
# Works for downloads initiated by Chromium and Firefox WebDriver clicks.
9+
# Browser type doesn't matter if using self.download_file(file_url)
10+
# or self.save_file_as(file_url, new_file_name)
11+
# The "downloads_folder" is cleaned out at the start of each pytest run,
12+
# but there is an option to save existing files in "archived_files".
1113
DOWNLOADS_DIR = constants.Files.DOWNLOADS_FOLDER
1214
ARCHIVE_DIR = constants.Files.ARCHIVED_DOWNLOADS_FOLDER
1315

seleniumbase/plugins/base_plugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time
66
from nose.plugins import Plugin
77
from nose.exc import SkipTest
8+
from seleniumbase.config import settings
89
from seleniumbase.core import log_helper
910
from seleniumbase.core import report_helper
1011
from seleniumbase.fixtures import constants, errors
@@ -20,6 +21,7 @@ class Base(Plugin):
2021
--var3=DATA (Extra test data. Access with "self.var3" in tests.)
2122
--settings-file=FILE (Override default SeleniumBase settings.)
2223
--archive-logs (Archive old log files instead of deleting them.)
24+
--archive-downloads (Archive old downloads instead of deleting.)
2325
--report (Create a fancy nosetests report after tests complete.)
2426
--show-report If self.report is turned on, then the report will
2527
display immediately after tests complete their run.
@@ -83,6 +85,12 @@ def options(self, parser, env):
8385
dest='archive_logs',
8486
default=False,
8587
help="Archive old log files instead of deleting them.")
88+
parser.add_option(
89+
'--archive_downloads', '--archive-downloads',
90+
action="store_true",
91+
dest='archive_downloads',
92+
default=False,
93+
help="Archive old downloads instead of deleting them.")
8694
parser.add_option(
8795
'--report',
8896
action="store_true",
@@ -147,6 +155,8 @@ def beforeTest(self, test):
147155
test.test.var3 = self.options.var3
148156
test.test.settings_file = self.options.settings_file
149157
test.test.log_path = self.options.log_path
158+
if self.options.archive_downloads:
159+
settings.ARCHIVE_EXISTING_DOWNLOADS = True
150160
test.test.args = self.options
151161
test.test.report_on = self.report_on
152162
self.test_count += 1

seleniumbase/plugins/pytest_plugin.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
import time
1010
from seleniumbase import config as sb_config
11+
from seleniumbase.config import settings
1112
from seleniumbase.core import log_helper
1213
from seleniumbase.core import proxy_helper
1314
from seleniumbase.fixtures import constants
@@ -45,7 +46,8 @@ def pytest_addoption(parser):
4546
--headed (Run tests with a GUI on Linux OS.)
4647
--locale=LOCALE_CODE (Set the Language Locale Code for the web browser.)
4748
--start-page=URL (The starting URL for the web browser when tests begin.)
48-
--archive-logs (Archive old log files instead of deleting them.)
49+
--archive-logs (Archive existing log files instead of deleting them.)
50+
--archive-downloads (Archive old downloads instead of deleting them.)
4951
--time-limit=SECONDS (Safely fail any test that exceeds the time limit.)
5052
--slow (Slow down the automation. Faster than using Demo Mode.)
5153
--demo (Slow down and visually see test actions as they occur.)
@@ -210,6 +212,11 @@ def pytest_addoption(parser):
210212
dest='archive_logs',
211213
default=False,
212214
help="Archive old log files instead of deleting them.")
215+
parser.addoption('--archive_downloads', '--archive-downloads',
216+
action="store_true",
217+
dest='archive_downloads',
218+
default=False,
219+
help="Archive old downloads instead of deleting them.")
213220
parser.addoption('--with-db_reporting', '--with-db-reporting',
214221
action="store_true",
215222
dest='with_db_reporting',
@@ -669,6 +676,8 @@ def pytest_configure(config):
669676
sb_config.database_env = config.getoption('database_env')
670677
sb_config.log_path = 'latest_logs/' # (No longer editable!)
671678
sb_config.archive_logs = config.getoption('archive_logs')
679+
if config.getoption('archive_downloads'):
680+
settings.ARCHIVE_EXISTING_DOWNLOADS = True
672681
sb_config._time_limit = config.getoption('time_limit')
673682
sb_config.time_limit = config.getoption('time_limit')
674683
sb_config.slow_mode = config.getoption('slow_mode')

0 commit comments

Comments
 (0)