|
1 | 1 | import pandas as pd |
2 | 2 | from playwright.sync_api import Page, expect |
| 3 | +from io import StringIO |
3 | 4 |
|
4 | 5 | from ..data import TestData |
5 | 6 | from ..models import ReportFormat, Programme |
@@ -129,12 +130,24 @@ def verify_report_format(self, programme: Programme, report_format: ReportFormat |
129 | 130 | def _download_and_verify_report_headers(self, expected_headers: str): |
130 | 131 | _file_path = f"working/rpt_{get_current_datetime()}.csv" |
131 | 132 |
|
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) |
136 | 150 |
|
137 | | - _actual_df = pd.read_csv(_file_path) |
138 | 151 | actual_headers = ",".join(_actual_df.columns.tolist()) |
139 | 152 | _e_not_a = [ |
140 | 153 | h for h in expected_headers.split(",") if h not in actual_headers.split(",") |
|
0 commit comments