Skip to content

Commit bd8e0e3

Browse files
committed
Update methods that deal with downloaded files
1 parent 1f232d1 commit bd8e0e3

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,11 +2751,13 @@ def get_pdf_text(self, pdf, page=None, maxpages=None,
27512751
raise Exception("%s is not a PDF file! (Expecting a .pdf)" % pdf)
27522752
file_path = None
27532753
if page_utils.is_valid_url(pdf):
2754+
from seleniumbase.core import download_helper
2755+
downloads_folder = download_helper.get_downloads_folder()
27542756
if nav:
27552757
if self.get_current_url() != pdf:
27562758
self.open(pdf)
27572759
file_name = pdf.split('/')[-1]
2758-
file_path = self.get_downloads_folder() + '/' + file_name
2760+
file_path = downloads_folder + '/' + file_name
27592761
if not os.path.exists(file_path):
27602762
self.download_file(pdf)
27612763
elif override:
@@ -2926,10 +2928,19 @@ def save_data_as(self, data, file_name, destination_folder=None):
29262928
page_utils._save_data_as(data, destination_folder, file_name)
29272929

29282930
def get_downloads_folder(self):
2929-
""" Returns the OS path of the Downloads Folder.
2930-
(Works with Chrome and Firefox only, for now.) """
2931-
from seleniumbase.core import download_helper
2932-
return download_helper.get_downloads_folder()
2931+
""" Returns the OS path of the "downloads/" folder.
2932+
Chromium Guest Mode overwrites the path set by SeleniumBase. """
2933+
sys_plat = sys.platform
2934+
chromium = False
2935+
if self.browser in ("chrome", "edge", "opera"):
2936+
chromium = True
2937+
if chromium and self.guest_mode and "linux" not in sys_plat and (
2938+
not self.headless):
2939+
# Guest Mode (non-headless) can force the default downloads path
2940+
return os.path.join(os.path.expanduser('~'), 'downloads')
2941+
else:
2942+
from seleniumbase.core import download_helper
2943+
return download_helper.get_downloads_folder()
29332944

29342945
def get_path_of_downloaded_file(self, file):
29352946
""" Returns the OS path of the downloaded file. """

0 commit comments

Comments
 (0)