@@ -39,35 +39,28 @@ def _download_and_verify_report_headers(self, expected_headers: str) -> None:
3939 getattr (browser , "browser_type" , None ), "name" , None
4040 )
4141
42- # Playwright's webkit browser may open CSVs in the browser
43- # unlike Chromium and Firefox, but behavior varies by environment
44- if browser_type_name == "webkit" :
45- # WebKit behavior varies: may download file, open in new page,
46- # or open in current page. Try download first (macOS CI behavior)
47- try :
48- with self .page .expect_download (timeout = 5000 ) as download_info :
49- self .click_download_report ()
50- download = download_info .value
51- download .save_as (_file_path )
52- _actual_df = pd .read_csv (_file_path )
53- except PlaywrightTimeoutError :
54- # No download - CSV opened in browser (new page or current page)
55- new_page = self .page .context .pages [- 1 ]
56- if new_page != self .page :
57- new_page .wait_for_load_state ("load" , timeout = 10000 )
58- csv_content = new_page .locator ("pre" ).inner_text (timeout = 5000 )
59- new_page .close ()
60- else :
61- self .page .wait_for_load_state ("load" , timeout = 10000 )
62- csv_content = self .page .locator ("pre" ).inner_text (timeout = 10000 )
63- self .page .go_back ()
64- _actual_df = pd .read_csv (StringIO (csv_content ))
65- else :
66- with self .page .expect_download () as download_info :
42+ # Try to download the file (set shorter timeout for WebKit)
43+ download_timeout = 5000 if browser_type_name == "webkit" else None
44+ page_load_timeout = 10000 if browser_type_name == "webkit" else None
45+ try :
46+ with self .page .expect_download (timeout = download_timeout ) as download_info :
6747 self .click_download_report ()
6848 download = download_info .value
6949 download .save_as (_file_path )
7050 _actual_df = pd .read_csv (_file_path )
51+ except PlaywrightTimeoutError :
52+ # WebKit may open CSV in browser - read from <pre> element
53+ pages = self .page .context .pages
54+ page_to_read = pages [- 1 ] if len (pages ) > 1 else self .page
55+ page_to_read .wait_for_load_state ("load" , timeout = page_load_timeout )
56+ csv_content = page_to_read .locator ("pre" ).inner_text ()
57+ _actual_df = pd .read_csv (StringIO (csv_content ))
58+
59+ # Clean up: close new page or go back on current page
60+ if page_to_read != self .page :
61+ page_to_read .close ()
62+ else :
63+ self .page .go_back ()
7164
7265 expected_set = set (expected_headers .split ("," ))
7366 actual_set = set (_actual_df .columns )
0 commit comments