@@ -2527,11 +2527,36 @@ def is_downloaded_file_present(self, file):
2527
2527
""" Checks if the file exists in the Downloads Folder. """
2528
2528
return os .path .exists (self .get_path_of_downloaded_file (file ))
2529
2529
2530
- def assert_downloaded_file (self , file ):
2530
+ def assert_downloaded_file (self , file , timeout = None ):
2531
2531
""" Asserts that the file exists in the Downloads Folder. """
2532
- self .assertTrue (os .path .exists (self .get_path_of_downloaded_file (file )),
2533
- "File [%s] was not found in the downloads folder [%s]!"
2534
- "" % (file , self .get_downloads_folder ()))
2532
+ if not timeout :
2533
+ timeout = settings .SMALL_TIMEOUT
2534
+ if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
2535
+ timeout = self .__get_new_timeout (timeout )
2536
+ start_ms = time .time () * 1000.0
2537
+ stop_ms = start_ms + (timeout * 1000.0 )
2538
+ for x in range (int (timeout )):
2539
+ shared_utils .check_if_time_limit_exceeded ()
2540
+ try :
2541
+ self .assertTrue (
2542
+ os .path .exists (self .get_path_of_downloaded_file (file )),
2543
+ "File [%s] was not found in the downloads folder [%s]!"
2544
+ "" % (file , self .get_downloads_folder ()))
2545
+ if self .demo_mode :
2546
+ messenger_post = ("ASSERT DOWNLOADED FILE: [%s]" % file )
2547
+ js_utils .post_messenger_success_message (
2548
+ self .driver , messenger_post , self .message_duration )
2549
+ return
2550
+ except Exception :
2551
+ now_ms = time .time () * 1000.0
2552
+ if now_ms >= stop_ms :
2553
+ break
2554
+ time .sleep (1 )
2555
+ self .assertTrue (
2556
+ os .path .exists (self .get_path_of_downloaded_file (file )),
2557
+ "File [%s] was not found in the downloads folder [%s] "
2558
+ "after %s seconds! (Or the download didn't complete!)"
2559
+ "" % (file , self .get_downloads_folder (), timeout ))
2535
2560
if self .demo_mode :
2536
2561
messenger_post = ("ASSERT DOWNLOADED FILE: [%s]" % file )
2537
2562
js_utils .post_messenger_success_message (
0 commit comments