Skip to content

Commit 3531a3e

Browse files
committed
Allow the Recorder to record methods for file downloads
1 parent bea532f commit 3531a3e

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3350,9 +3350,11 @@ def __process_recorded_actions(self):
33503350
ext_actions.append("hi_li")
33513351
ext_actions.append("as_lt")
33523352
ext_actions.append("as_ti")
3353+
ext_actions.append("as_df")
3354+
ext_actions.append("do_fi")
3355+
ext_actions.append("as_at")
33533356
ext_actions.append("as_te")
33543357
ext_actions.append("as_et")
3355-
ext_actions.append("as_at")
33563358
ext_actions.append("sw_fr")
33573359
ext_actions.append("sw_dc")
33583360
ext_actions.append("s_c_f")
@@ -3539,6 +3541,22 @@ def __process_recorded_actions(self):
35393541
sb_actions.append('self.%s("%s")' % (method, action[1]))
35403542
else:
35413543
sb_actions.append("self.%s('%s')" % (method, action[1]))
3544+
elif action[0] == "as_df":
3545+
method = "assert_downloaded_file"
3546+
if '"' not in action[1]:
3547+
sb_actions.append('self.%s("%s")' % (method, action[1]))
3548+
else:
3549+
sb_actions.append("self.%s('%s')" % (method, action[1]))
3550+
elif action[0] == "do_fi":
3551+
method = "download_file"
3552+
file_url = action[1][0]
3553+
dest = action[1][1]
3554+
if not dest:
3555+
sb_actions.append('self.%s("%s")' % (
3556+
method, file_url))
3557+
else:
3558+
sb_actions.append('self.%s("%s", "%s")' % (
3559+
method, file_url, dest))
35423560
elif action[0] == "as_at":
35433561
method = "assert_attribute"
35443562
if ('"' not in action[1][0]) and action[1][2]:
@@ -4608,6 +4626,16 @@ def download_file(self, file_url, destination_folder=None):
46084626
if not os.path.exists(destination_folder):
46094627
os.makedirs(destination_folder)
46104628
page_utils._download_file_to(file_url, destination_folder)
4629+
if self.recorder_mode:
4630+
url = self.get_current_url()
4631+
if url and len(url) > 0:
4632+
if ("http:") in url or ("https:") in url or ("file:") in url:
4633+
if self.get_session_storage_item("pause_recorder") == "no":
4634+
time_stamp = self.execute_script("return Date.now();")
4635+
origin = self.get_origin()
4636+
url_dest = [file_url, destination_folder]
4637+
action = ["do_fi", url_dest, origin, time_stamp]
4638+
self.__extra_actions.append(action)
46114639

46124640
def save_file_as(self, file_url, new_file_name, destination_folder=None):
46134641
"""Similar to self.download_file(), except that you get to rename the
@@ -4776,6 +4804,15 @@ def assert_downloaded_file(self, file, timeout=None, browser=False):
47764804
% (file, self.get_downloads_folder(), timeout)
47774805
)
47784806
page_actions.timeout_exception("NoSuchFileException", message)
4807+
if self.recorder_mode:
4808+
url = self.get_current_url()
4809+
if url and len(url) > 0:
4810+
if ("http:") in url or ("https:") in url or ("file:") in url:
4811+
if self.get_session_storage_item("pause_recorder") == "no":
4812+
time_stamp = self.execute_script("return Date.now();")
4813+
origin = self.get_origin()
4814+
action = ["as_df", file, origin, time_stamp]
4815+
self.__extra_actions.append(action)
47794816
if self.demo_mode:
47804817
messenger_post = "ASSERT DOWNLOADED FILE: [%s]" % file
47814818
try:

0 commit comments

Comments
 (0)