|
17 | 17 |
|
18 | 18 | Provides StreamlitRunner, a context manager that starts a Streamlit server |
19 | 19 | in a subprocess, waits for it to become healthy, and tears it down on exit. |
| 20 | +Also provides shared Playwright locator helpers used across E2E test modules. |
20 | 21 | """ |
21 | 22 |
|
22 | 23 | import contextlib |
|
29 | 30 | import time |
30 | 31 | import typing |
31 | 32 | from contextlib import closing |
| 33 | +from pathlib import Path |
32 | 34 | from tempfile import TemporaryFile |
33 | 35 |
|
34 | 36 | import requests |
| 37 | +from playwright.sync_api import Locator, Page, expect |
35 | 38 |
|
36 | 39 | LOGGER = logging.getLogger(__file__) |
37 | 40 |
|
| 41 | +SCRIPT = Path(__file__).parent / "pivot_table.py" |
| 42 | +TOOLBAR_SCRIPT = Path(__file__).parent / "pivot_table_toolbar_app.py" |
| 43 | +INTERACTIONS_SCRIPT = Path(__file__).parent / "pivot_table_interactions_app.py" |
| 44 | +DATA_SCRIPT = Path(__file__).parent / "pivot_table_data_app.py" |
| 45 | + |
| 46 | +PIVOT_KEYS = [ |
| 47 | + "test_pivot", |
| 48 | + "test_pivot_subtotals", |
| 49 | + "test_pivot_locked", |
| 50 | + "test_pivot_locked_groups", |
| 51 | + "test_pivot_cond_fmt", |
| 52 | + "test_pivot_readonly", |
| 53 | + "test_pivot_number_fmt", |
| 54 | + "test_pivot_drilldown", |
| 55 | + "test_pivot_empty", |
| 56 | + "test_pivot_single_row", |
| 57 | + "test_pivot_no_cols", |
| 58 | + "test_pivot_count_distinct", |
| 59 | + "test_pivot_median", |
| 60 | + "test_pivot_auto", |
| 61 | + "test_pivot_threshold", |
| 62 | + "test_pivot_col_groups", |
| 63 | + "test_pivot_alignment", |
| 64 | + "test_pivot_tall", |
| 65 | + "test_pivot_null_separate", |
| 66 | + "test_pivot_null_zero", |
| 67 | + "test_pivot_dim_toggle", |
| 68 | + "test_pivot_no_drilldown", |
| 69 | + "test_pivot_per_dim_subtotals", |
| 70 | + "test_pivot_per_measure_row_totals", |
| 71 | + "test_pivot_per_measure_col_totals", |
| 72 | + "test_pivot_sparse_drilldown", |
| 73 | + "test_pivot_synthetic", |
| 74 | + "test_pivot_scalar_roundtrip", |
| 75 | +] |
| 76 | + |
| 77 | +TOOLBAR_PIVOT_KEYS = [ |
| 78 | + "test_pivot", |
| 79 | + "test_pivot_subtotals", |
| 80 | + "test_pivot_cond_fmt", |
| 81 | + "test_pivot_scalar_roundtrip", |
| 82 | +] |
| 83 | + |
| 84 | +INTERACTIONS_PIVOT_KEYS = [ |
| 85 | + "test_pivot", |
| 86 | + "test_pivot_subtotals", |
| 87 | + "test_pivot_cond_fmt", |
| 88 | + "test_pivot_locked", |
| 89 | + "test_pivot_locked_groups", |
| 90 | + "test_pivot_readonly", |
| 91 | + "test_pivot_drilldown", |
| 92 | + "test_pivot_no_drilldown", |
| 93 | + "test_pivot_dim_toggle", |
| 94 | + "test_pivot_per_dim_subtotals", |
| 95 | + "test_pivot_per_measure_row_totals", |
| 96 | + "test_pivot_per_measure_col_totals", |
| 97 | + "test_pivot_col_groups", |
| 98 | +] |
| 99 | + |
| 100 | +DATA_PIVOT_KEYS = [ |
| 101 | + "test_pivot", |
| 102 | + "test_pivot_cond_fmt", |
| 103 | + "test_pivot_number_fmt", |
| 104 | + "test_pivot_empty", |
| 105 | + "test_pivot_single_row", |
| 106 | + "test_pivot_no_cols", |
| 107 | + "test_pivot_count_distinct", |
| 108 | + "test_pivot_median", |
| 109 | + "test_pivot_auto", |
| 110 | + "test_pivot_threshold", |
| 111 | + "test_pivot_tall", |
| 112 | + "test_pivot_alignment", |
| 113 | + "test_pivot_null_separate", |
| 114 | + "test_pivot_null_zero", |
| 115 | + "test_pivot_sparse_drilldown", |
| 116 | + "test_pivot_synthetic", |
| 117 | +] |
| 118 | + |
| 119 | +APP_CONFIGS = { |
| 120 | + "default": {"script": SCRIPT, "pivot_keys": PIVOT_KEYS}, |
| 121 | + "pivot_table_test.py": {"script": TOOLBAR_SCRIPT, "pivot_keys": TOOLBAR_PIVOT_KEYS}, |
| 122 | + "pivot_table_interactions_test.py": { |
| 123 | + "script": INTERACTIONS_SCRIPT, |
| 124 | + "pivot_keys": INTERACTIONS_PIVOT_KEYS, |
| 125 | + }, |
| 126 | + "pivot_table_data_test.py": {"script": DATA_SCRIPT, "pivot_keys": DATA_PIVOT_KEYS}, |
| 127 | +} |
| 128 | + |
| 129 | + |
| 130 | +def get_pivot(page: Page, key: str) -> Locator: |
| 131 | + """Return a Locator scoped to the pivot-container for *key*.""" |
| 132 | + pivot_keys = getattr(page, "_pivot_keys", PIVOT_KEYS) |
| 133 | + idx = pivot_keys.index(key) |
| 134 | + container = page.get_by_test_id("pivot-container").nth(idx) |
| 135 | + container.evaluate("el => el.scrollIntoView({ block: 'center' })") |
| 136 | + return container |
| 137 | + |
| 138 | + |
| 139 | +def open_settings_popover(page: Page, container: Locator) -> Locator: |
| 140 | + """Open the gear settings popover in the toolbar.""" |
| 141 | + panel = page.get_by_test_id("toolbar-settings-panel") |
| 142 | + if panel.count(): |
| 143 | + expect(panel).to_be_visible(timeout=5000) |
| 144 | + return panel |
| 145 | + |
| 146 | + button = container.get_by_test_id("toolbar-settings") |
| 147 | + button.scroll_into_view_if_needed() |
| 148 | + button.evaluate("el => el.click()") |
| 149 | + expect(panel).to_be_visible(timeout=5000) |
| 150 | + return panel |
| 151 | + |
38 | 152 |
|
39 | 153 | def _find_free_port() -> int: |
40 | 154 | """Find and return a free port on the local machine.""" |
|
0 commit comments