|
| 1 | +"""Module for interactions within the Heater-Shaker Step configuration form.""" |
| 2 | + |
| 3 | +from enum import Enum |
| 4 | + |
| 5 | +from playwright.sync_api import Page |
| 6 | + |
| 7 | +from .base_page import BasePage |
| 8 | + |
| 9 | + |
| 10 | +class LidPosition(Enum): |
| 11 | + """Defines the allowed positions for the Heater-Shaker lid.""" |
| 12 | + |
| 13 | + OPEN = "open" |
| 14 | + CLOSED = "closed" |
| 15 | + |
| 16 | + |
| 17 | +class HeaterShakerStepPage(BasePage): |
| 18 | + """Page object for configuring a Heater-Shaker step.""" |
| 19 | + |
| 20 | + def __init__(self, page: Page) -> None: |
| 21 | + """Initialize the HeaterShakerStepPage.""" |
| 22 | + super().__init__(page) |
| 23 | + self._save_button = self.page.get_by_role("button", name="Save", exact=True) |
| 24 | + self._target_speed_toggle = self.page.get_by_text("Target Speed").locator("..").locator(".ToggleButton_Off") |
| 25 | + self._latch_closed_toggle = self.page.get_by_text("Labware latchClosed") |
| 26 | + self._latch_open_toggle = self.page.get_by_text("Labware latchOpen") |
| 27 | + |
| 28 | + def wait_for_form_load(self) -> None: |
| 29 | + """Wait for the Heater-Shaker step form to be visible.""" |
| 30 | + self.wait_for_visible(self.page.get_by_text("Heater-Shaker Module", exact=False)) |
| 31 | + |
| 32 | + def set_target_temperature(self, temp: str) -> None: |
| 33 | + """Enable and set the target heating temperature. |
| 34 | +
|
| 35 | + Args: |
| 36 | + temp: The target temperature string (e.g., "60"). |
| 37 | + """ |
| 38 | + self.page.get_by_text("HeaterOff").click() |
| 39 | + try: |
| 40 | + self.page.locator('input[name="targetTemperature"]').fill(temp) |
| 41 | + except Exception: # noqa: BLE001 |
| 42 | + self.page.get_by_role("textbox").fill(temp) |
| 43 | + |
| 44 | + def set_target_speed(self, speed: str) -> None: |
| 45 | + """Enable and set the target shaking speed. |
| 46 | +
|
| 47 | + Args: |
| 48 | + speed: The target speed string (e.g., "700"). |
| 49 | + """ |
| 50 | + self.page.get_by_text("ShakerOff").click() |
| 51 | + self.page.locator('input[name="targetSpeed"]').fill(speed) |
| 52 | + |
| 53 | + def set_lid_position(self, position: LidPosition) -> None: |
| 54 | + """Set the position of the Heater-Shaker lid. |
| 55 | +
|
| 56 | + Args: |
| 57 | + position: LidPosition.OPEN or LidPosition.CLOSED. |
| 58 | + """ |
| 59 | + if position == LidPosition.CLOSED: |
| 60 | + self._latch_closed_toggle.click() |
| 61 | + elif position == LidPosition.OPEN: |
| 62 | + self._latch_open_toggle.click() |
| 63 | + |
| 64 | + def save_step(self) -> None: |
| 65 | + """Click the Save button to confirm and close the step editor.""" |
| 66 | + self.wait_for_visible(self._save_button) |
| 67 | + self._save_button.click() |
| 68 | + |
| 69 | + def pause_confirm(self) -> None: |
| 70 | + """Confirm the pause in the step editor.""" |
| 71 | + self.page.get_by_role("button", name="Add pause step").click() |
| 72 | + |
| 73 | + ## Composite step |
| 74 | + |
| 75 | + |
| 76 | +def _add_heater_shaker_step(page: Page, temp: str, speed: str, timer: str) -> None: |
| 77 | + """Add a Heater-Shaker step configured with temperature, speed, and timer. |
| 78 | +
|
| 79 | + Args: |
| 80 | + editor: The initialized ProtocolEditorPage object for adding steps. |
| 81 | + page: The Playwright Page object for raw interactions. |
| 82 | + temp: The target temperature for the module (e.g., "50"). |
| 83 | + speed: The target RPM speed for the shaker (e.g., "300"). |
| 84 | + timer: The optional timer duration in HH:MM format (e.g., "00:30"). |
| 85 | + """ |
| 86 | + hs_page = HeaterShakerStepPage(page) |
| 87 | + hs_page.wait_for_form_load() |
| 88 | + |
| 89 | + hs_page.set_target_temperature(temp) |
| 90 | + hs_page.set_target_speed(speed) |
| 91 | + |
| 92 | + try: |
| 93 | + timer_input = page.locator('input[name="heaterShakerTimer"]') |
| 94 | + timer_input.click() |
| 95 | + timer_input.fill(timer) |
| 96 | + print(f"✓ Heater-Shaker timer set to {timer}") |
| 97 | + except Exception as e: # noqa: BLE001 |
| 98 | + print(f"Warning: Could not set Heater-Shaker timer. Error: {e}") |
| 99 | + |
| 100 | + hs_page.save_step() |
| 101 | + hs_page.pause_confirm() |
| 102 | + |
| 103 | + print(f"✓ Heater-Shaker step added (T:{temp}°C, S:{speed}rpm).") |
0 commit comments