1818import  os 
1919import  tempfile 
2020
21+ import  pytest 
22+ 
2123from  selenium .webdriver .common .by  import  By 
2224from  selenium .webdriver .support .wait  import  WebDriverWait 
2325
2426
27+ @pytest .mark .no_driver_after_test  
2528def  test_get_downloadable_files (driver , pages ):
2629    _browser_downloads (driver , pages )
2730    file_names  =  driver .get_downloadable_files ()
2831    # TODO: why is Chrome downloading files as .html??? 
2932    # assert "file_1.txt" in file_names 
3033    # assert "file_2.jpg" in file_names 
31-     assert  any (f  in  file_names  for  f  in  ("file_1.txt" , "file_1.html" ))
32-     assert  any (f  in  file_names  for  f  in  ("file_2.jpg" , "file_2.html" ))
34+     assert  any (f  in  file_names  for  f  in  ("file_1.txt" , "file_1.htm"  ,  "file_1. html" ))
35+     assert  any (f  in  file_names  for  f  in  ("file_2.jpg" , "file_2.htm"  ,  "file_2. html" ))
3336    assert  type (file_names ) is  list 
3437
3538
39+ @pytest .mark .no_driver_after_test  
3640def  test_download_file (driver , pages ):
3741    _browser_downloads (driver , pages )
3842
3943    # Get a list of downloadable files and find the txt file 
4044    downloadable_files  =  driver .get_downloadable_files ()
4145    # TODO: why is Chrome downloading files as .html??? 
4246    # text_file_name = next((file for file in downloadable_files if file.endswith(".txt")), None) 
43-     text_file_name  =  next ((file  for  file  in  downloadable_files  if  file .endswith ((".txt" , ".html" ))), None )
47+     text_file_name  =  next (
48+         (f  for  f  in  downloadable_files  if  all ((f .endswith ((".txt" , ".htm" , ".html" )), f .startswith ("file_1" )))), None 
49+     )
4450    assert  text_file_name  is  not   None , "Could not find file in downloadable files" 
4551
4652    with  tempfile .TemporaryDirectory () as  target_directory :
@@ -51,6 +57,7 @@ def test_download_file(driver, pages):
5157            assert  "Hello, World!"  in  file .read ()
5258
5359
60+ @pytest .mark .no_driver_after_test  
5461def  test_delete_downloadable_files (driver , pages ):
5562    _browser_downloads (driver , pages )
5663
@@ -65,5 +72,5 @@ def _browser_downloads(driver, pages):
6572    # TODO: why is Chrome downloading files as .html??? 
6673    # WebDriverWait(driver, 5).until(lambda d: "file_2.jpg" in d.get_downloadable_files()) 
6774    WebDriverWait (driver , 5 ).until (
68-         lambda  d : any (f  in  d .get_downloadable_files () for  f  in  ("file_2.jpg" , "file_2.html" ))
75+         lambda  d : any (f  in  d .get_downloadable_files () for  f  in  ("file_2.jpg" , "file_2.htm"  ,  "file_2. html" ))
6976    )
0 commit comments