|
1 | | -from playwright.sync_api import Page, expect |
| 1 | +from playwright.sync_api import Page, expect, Locator |
2 | 2 | from pages.base_page import BasePage |
3 | 3 | from datetime import datetime |
4 | 4 | from utils.calendar_picker import CalendarPicker |
@@ -130,29 +130,36 @@ def verify_deadline_date_filter_input(self, expected_text: str) -> None: |
130 | 130 | expect(self.deadline_date_filter_with_input).to_have_value(expected_text) |
131 | 131 |
|
132 | 132 | def open_letter_batch( |
133 | | - self, batch_type: str, status: str, level: str, description: str |
| 133 | + self, |
| 134 | + batch_type: str = "", |
| 135 | + status: str = "", |
| 136 | + level: str = "", |
| 137 | + description: str = "", |
134 | 138 | ) -> None: |
135 | 139 | """ |
136 | | - Finds and opens the batch row based on type, status, level, and description. |
137 | | - Args: |
138 | | - batch_type (str): The type of the batch (e.g., "Original"). |
139 | | - status (str): The status of the batch (e.g., "Open"). |
140 | | - level (str): The level of the batch (e.g., "S1"). |
141 | | - description (str): The description of the batch (e.g., "Pre-invitation (FIT)"). |
| 140 | + Finds and opens the batch row based on non-empty filters. |
142 | 141 | """ |
143 | | - # Step 1: Match the row using nested filters, one per column value |
144 | | - row = ( |
145 | | - self.page.locator("table tbody tr") |
146 | | - .filter(has=self.page.locator("td", has_text=batch_type)) |
147 | | - .filter(has=self.page.locator("td", has_text=status)) |
148 | | - .filter(has=self.page.locator("td", has_text=level)) |
149 | | - .filter(has=self.page.locator("td", has_text=description)) |
150 | | - ) |
151 | | - |
152 | | - # Step 2: Click the "View" link in the matched row |
153 | | - view_link = row.locator( |
154 | | - "a" |
155 | | - ) # Click the first link in the row identified in step 1 |
| 142 | + row_locator = self.page.locator(f"{self.table_selector} tbody tr") |
| 143 | + |
| 144 | + if batch_type: |
| 145 | + row_locator = row_locator.filter( |
| 146 | + has=self.page.locator("td", has_text=batch_type) |
| 147 | + ) |
| 148 | + if status: |
| 149 | + row_locator = row_locator.filter( |
| 150 | + has=self.page.locator("td", has_text=status) |
| 151 | + ) |
| 152 | + if level: |
| 153 | + row_locator = row_locator.filter( |
| 154 | + has=self.page.locator("td", has_text=level) |
| 155 | + ) |
| 156 | + if description: |
| 157 | + row_locator = row_locator.filter( |
| 158 | + has=self.page.locator("td", has_text=description) |
| 159 | + ) |
| 160 | + |
| 161 | + row = row_locator.first |
| 162 | + view_link = row.locator("a").first |
156 | 163 | expect(view_link).to_be_visible() |
157 | 164 | view_link.click() |
158 | 165 |
|
@@ -189,6 +196,28 @@ def prepare_batch(self, batch_type: str) -> None: |
189 | 196 | prepare_button.click() |
190 | 197 | expect(row).not_to_be_visible(timeout=5000) |
191 | 198 |
|
| 199 | + def get_open_original_batch_row(self) -> Locator | None: |
| 200 | + """ |
| 201 | + Returns the first table row where: |
| 202 | + - The 'Type' column contains 'Original' |
| 203 | + - The 'Status' column contains 'Open' |
| 204 | +
|
| 205 | + Returns: |
| 206 | + Locator of the matching <tr> element, or None if not found. |
| 207 | + """ |
| 208 | + rows = self.page.locator(f"{self.table_selector} tbody tr") |
| 209 | + for i in range(rows.count()): |
| 210 | + row = rows.nth(i) |
| 211 | + type_cell = row.locator("td").nth(1) # Assuming Type is 2nd column |
| 212 | + status_cell = row.locator("td").nth(8) # Assuming Status is 9th column |
| 213 | + |
| 214 | + if ( |
| 215 | + "Original" in type_cell.inner_text() |
| 216 | + and "Open" in status_cell.inner_text() |
| 217 | + ): |
| 218 | + return row |
| 219 | + return None |
| 220 | + |
192 | 221 |
|
193 | 222 | class ArchivedBatchListPage(BatchListPage): |
194 | 223 | """Archived Batch List Page-specific setup.""" |
|
0 commit comments