|
1 | 1 | import requests |
| 2 | +from playwright.sync_api import TimeoutError as PlaywrightTimeoutError |
2 | 3 | from playwright.sync_api import expect, sync_playwright |
3 | 4 |
|
4 | 5 | from util import get_auth_headers |
@@ -62,22 +63,30 @@ def test_ui(): |
62 | 63 | # Navigate to Apache Superset. |
63 | 64 | page = browser.new_page() |
64 | 65 | page.goto(uri_home) |
65 | | - page.wait_for_url("**/login/") |
| 66 | + page.wait_for_url("**/login/**") |
66 | 67 |
|
67 | 68 | # Run the login procedure. |
68 | 69 | page.type("input#username", "admin") |
69 | 70 | page.type("input#password", "admin") |
70 | 71 | page.click("[type=submit]") |
71 | 72 | page.wait_for_load_state() |
72 | 73 |
|
73 | | - # Navigate to SQL Lab. |
| 74 | + # Navigate to SQL Lab. Older Superset versions open a query editor tab |
| 75 | + # automatically; newer ones (6.1+) start empty and require creating one. |
74 | 76 | page.goto(uri_sqllab) |
75 | 77 | page.wait_for_load_state() |
| 78 | + try: |
| 79 | + page.wait_for_selector(".ace_editor", timeout=5000) |
| 80 | + except PlaywrightTimeoutError: |
| 81 | + page.click('[data-test="add-tab-icon"]') |
76 | 82 |
|
77 | 83 | # Invoke query on SQL Lab. |
| 84 | + # The ace editor's DOM id is randomly generated per tab instance, so |
| 85 | + # look it up by its `ace_editor` class instead of a fixed element id. |
78 | 86 | sql = "SELECT region, mountain, height FROM sys.summits LIMIT 42;" |
79 | | - page.wait_for_selector("#ace-editor") |
80 | | - page.evaluate(f"ace.edit('ace-editor').setValue('{sql}')") |
| 87 | + page.wait_for_selector(".ace_editor") |
| 88 | + editor_id = page.eval_on_selector(".ace_editor", "el => el.id") |
| 89 | + page.evaluate(f"ace.edit('{editor_id}').setValue('{sql}')") |
81 | 90 | page.get_by_role("button", name="Run").click() |
82 | 91 | page.wait_for_load_state() |
83 | 92 |
|
|
0 commit comments