|
9 | 9 | import json |
10 | 10 | import logging |
11 | 11 | import re |
| 12 | +import time |
12 | 13 | from collections.abc import Callable |
13 | 14 | from dataclasses import dataclass |
14 | 15 | from pathlib import Path |
@@ -224,21 +225,26 @@ def test_classic_ti_plan( # noqa: PLR0915 |
224 | 225 | assert not ws_info.value.is_closed() |
225 | 226 | restartable_jlab_websocket = RobustWebSocket(page, ws_info.value) |
226 | 227 |
|
227 | | - with ( |
228 | | - log_context(logging.INFO, "Run optimization"), |
229 | | - restartable_jlab_websocket.expect_event( |
230 | | - "framereceived", |
231 | | - _JLabWebSocketWaiter( |
232 | | - expected_header_msg_type="stream", |
233 | | - expected_message_contents="All results evaluated", |
234 | | - ), |
235 | | - timeout=_JLAB_RUN_OPTIMIZATION_MAX_TIME |
236 | | - + _JLAB_RUN_OPTIMIZATION_APPEARANCE_TIME, |
237 | | - ), |
238 | | - ): |
239 | | - ti_iframe.get_by_role("button", name="Run Optimization").click( |
240 | | - timeout=_JLAB_RUN_OPTIMIZATION_APPEARANCE_TIME |
241 | | - ) |
| 228 | + with log_context(logging.INFO, "Run optimization") as ctx: |
| 229 | + run_button = ti_iframe.get_by_role("button", name="Run Optimization") |
| 230 | + run_button.click(timeout=_JLAB_RUN_OPTIMIZATION_APPEARANCE_TIME) |
| 231 | + |
| 232 | + start = time.time() |
| 233 | + success = False |
| 234 | + while ( |
| 235 | + time.time() - start < _JLAB_RUN_OPTIMIZATION_MAX_TIME / 1000 |
| 236 | + ): # Convert ms to seconds |
| 237 | + bg_color = run_button.evaluate( |
| 238 | + "el => getComputedStyle(el).backgroundColor" |
| 239 | + ) |
| 240 | + if bg_color == "rgb(0, 128, 0)": |
| 241 | + ctx.logger.info("Optimization finished!") |
| 242 | + success = True |
| 243 | + break |
| 244 | + time.sleep(2) |
| 245 | + |
| 246 | + if not success: |
| 247 | + ctx.logger.info("Optimization did not finish in time.") |
242 | 248 |
|
243 | 249 | with log_context(logging.INFO, "Create report"): |
244 | 250 | with log_context( |
|
0 commit comments