Skip to content

Commit b5d9f18

Browse files
committed
fix safari downloads
1 parent 0519c84 commit b5d9f18

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

mavis/test/pages/programmes.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pandas as pd
22
from playwright.sync_api import Page, expect
3+
from io import StringIO
34

45
from ..data import TestData
56
from ..models import ReportFormat, Programme
@@ -129,12 +130,24 @@ def verify_report_format(self, programme: Programme, report_format: ReportFormat
129130
def _download_and_verify_report_headers(self, expected_headers: str):
130131
_file_path = f"working/rpt_{get_current_datetime()}.csv"
131132

132-
with self.page.expect_download() as download_info:
133-
self.continue_button.click()
134-
download = download_info.value
135-
download.save_as(_file_path)
133+
browser = getattr(self.page.context, "browser", None)
134+
browser_type_name = getattr(
135+
getattr(browser, "browser_type", None), "name", None
136+
)
137+
138+
# In Safari, downloaded files are not saved to disk, but instead immediately displayed in the browser
139+
if browser_type_name == "webkit":
140+
self.click_continue()
141+
csv_content = self.page.locator("pre").inner_text()
142+
_actual_df = pd.read_csv(StringIO(csv_content))
143+
self.page.go_back()
144+
else:
145+
with self.page.expect_download() as download_info:
146+
self.click_continue()
147+
download = download_info.value
148+
download.save_as(_file_path)
149+
_actual_df = pd.read_csv(_file_path)
136150

137-
_actual_df = pd.read_csv(_file_path)
138151
actual_headers = ",".join(_actual_df.columns.tolist())
139152
_e_not_a = [
140153
h for h in expected_headers.split(",") if h not in actual_headers.split(",")

0 commit comments

Comments
 (0)