2828def test_get_downloadable_files (driver , pages ):
2929 _browser_downloads (driver , pages )
3030 file_names = driver .get_downloadable_files ()
31- # TODO: why is Chrome downloading files as .html???
32- # assert "file_1.txt" in file_names
33- # assert "file_2.jpg" in file_names
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" ))
31+
32+ assert "file_1.txt" in file_names
33+ assert "file_2.jpg" in file_names
3634 assert type (file_names ) is list
3735
3836
@@ -42,12 +40,8 @@ def test_download_file(driver, pages):
4240
4341 # Get a list of downloadable files and find the txt file
4442 downloadable_files = driver .get_downloadable_files ()
45- # TODO: why is Chrome downloading files as .html???
46- # text_file_name = next((file for file in downloadable_files if file.endswith(".txt")), 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- )
50- assert text_file_name is not None , "Could not find file in downloadable files"
43+ text_file_name = next ((file for file in downloadable_files if file .endswith (".txt" )), None )
44+ assert text_file_name is not None , "Could not find a .txt file in downloadable files"
5145
5246 with tempfile .TemporaryDirectory () as target_directory :
5347 driver .download_file (text_file_name , target_directory )
@@ -69,8 +63,4 @@ def _browser_downloads(driver, pages):
6963 pages .load ("downloads/download.html" )
7064 driver .find_element (By .ID , "file-1" ).click ()
7165 driver .find_element (By .ID , "file-2" ).click ()
72- # TODO: why is Chrome downloading files as .html???
73- # WebDriverWait(driver, 5).until(lambda d: "file_2.jpg" in d.get_downloadable_files())
74- WebDriverWait (driver , 5 ).until (
75- lambda d : any (f in d .get_downloadable_files () for f in ("file_2.jpg" , "file_2.htm" , "file_2.html" ))
76- )
66+ WebDriverWait (driver , 3 ).until (lambda d : "file_2.jpg" in d .get_downloadable_files ())
0 commit comments