Skip to content

Commit 2a8a685

Browse files
committed
Added test_reprint_and_archive_letter_batch and added/updated relevant utils/functions
1 parent 93c1da2 commit 2a8a685

File tree

5 files changed

+143
-14
lines changed

5 files changed

+143
-14
lines changed

pages/communication_production/batch_list_page.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,45 @@ def select_first_archived_batch(self) -> None:
232232
).first
233233
assert first_batch_link.count() > 0, "No archived batch links found"
234234
first_batch_link.click()
235+
236+
def get_archived_batch_row(
237+
self, batch_type: str, event_code: str, description: str
238+
) -> Locator | None:
239+
"""
240+
Returns the first archived batch row matching the specified Type, Event Code, and Description.
241+
Assumes columns appear in the following order:
242+
1. Batch ID
243+
2. Type
244+
3. Event Code
245+
4. Description
246+
5+ ...
247+
248+
Args:
249+
batch_type (str): The target value in the 'Type' column (e.g., 'Original').
250+
event_code (str): The target value in the 'Event Code' column (e.g., 'S1').
251+
description (str): The target text in the 'Description' column (e.g., 'Pre-invitation (FIT)').
252+
253+
Returns:
254+
Locator: The first <tr> element matching all criteria, or None if not found.
255+
"""
256+
rows = self.page.locator(f"{self.table_selector} tbody tr")
257+
row_count = rows.count()
258+
if row_count == 0:
259+
return None
260+
261+
for i in range(row_count):
262+
row = rows.nth(i)
263+
264+
try:
265+
type_text = row.locator("td").nth(1).inner_text().strip()
266+
event_code_text = row.locator("td").nth(4).inner_text().strip()
267+
description_text = row.locator("td").nth(5).inner_text().strip()
268+
269+
if (
270+
batch_type.lower() in type_text.lower()
271+
and event_code.lower() in event_code_text.lower()
272+
and description.lower() in description_text.lower()
273+
):
274+
return row
275+
except IndexError:
276+
return None

pages/communication_production/manage_active_batch_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def click_confirm_button(self) -> None:
3232
"""Click the Confirm Printed button"""
3333
self.click(self.confirm_button)
3434

35-
def assert_batch_details_visible(self) -> None:
35+
def assert_active_batch_details_visible(self) -> None:
3636
"""Asserts that the Manage Active Batch screen has loaded by checking the page title."""
3737
page_title = self.page.locator("#page-title")
3838
expect(page_title).to_have_text("Manage Active Batch")

pages/communication_production/manage_archived_batch_page.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ class ManageArchivedBatchPage(BasePage):
99
def __init__(self, page: Page):
1010
super().__init__(page)
1111

12-
def assert_batch_details_visible(self) -> None:
12+
def assert_archived_batch_details_visible(self) -> None:
1313
"""Verifies the Manage Archived Batch page has loaded."""
1414
header = self.page.locator("#page-title")
1515
expect(header).to_have_text("Manage Archived Batch")
16+
17+
def click_reprint_button(self) -> None:
18+
"""Clicks the 'Reprint' button on the Archived Batch details page."""
19+
reprint_button = self.page.locator("input.ReprintButton[value='Reprint Batch']")
20+
expect(reprint_button).to_be_visible()
21+
reprint_button.click()
22+
23+
def confirm_archived_message_visible(self) -> None:
24+
"""Verifies that the batch was successfully archived and confirmation message is shown."""
25+
confirmation_msg = self.page.locator(
26+
'text="Batch Successfully Archived and Printed"'
27+
)
28+
expect(confirmation_msg).to_be_visible()

tests/regression/communications_production/test_basic_manage_active_batch_functionality.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from pages.communication_production.manage_active_batch_page import (
1010
ManageActiveBatchPage,
1111
)
12-
from pages.communication_production.batch_list_page import ActiveBatchListPage
1312
from utils.batch_processing import prepare_and_print_batch
1413

1514

@@ -56,7 +55,7 @@ def test_prepare_retrieve_and_confirm_active_letter_batch(select_user) -> None:
5655

5756
# Step 5: Assert that Manage Active Batch page has loaded
5857
manage_page = ManageActiveBatchPage(page)
59-
manage_page.assert_batch_details_visible()
58+
manage_page.assert_active_batch_details_visible()
6059

6160
# Step 6: Prepare, retrieve and confirm the batch using utility method
6261
prepare_and_print_batch(page, link_text=batch_id)

tests/regression/communications_production/test_basic_manage_archived_batch_functionality.py

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,90 @@
1-
# @LettersTests
2-
# Feature: Basic Manage Archived Batch functionality
1+
import pytest
2+
from playwright.sync_api import Page
3+
from pages.base_page import BasePage
4+
from pages.communication_production.communications_production_page import (
5+
CommunicationsProductionPage,
6+
)
7+
from pages.communication_production.batch_list_page import ArchivedBatchListPage
8+
from utils.user_tools import UserTools
9+
from pages.communication_production.manage_active_batch_page import (
10+
ManageActiveBatchPage,
11+
)
12+
from pages.communication_production.manage_archived_batch_page import (
13+
ManageArchivedBatchPage,
14+
)
15+
from utils.batch_processing import prepare_and_print_batch
316

417

5-
# Scenario: I can take an archived batch, reprint it, then archive that new batch
6-
# Given I log in to BCSS "England" as user role "HubManagerStateRegistered"
7-
# When I view the archived batch list
8-
# And I view the "Original" type archived letter batch for "S1" "Pre"
9-
# And I reprint the archived letter batch
10-
# And I prepare the letter batch
11-
# And I retrieve and confirm the letters
12-
# And my batch is now archived
18+
@pytest.fixture
19+
def select_user(page: Page):
20+
def _login_as(user_role: str):
21+
# Log in with the specified user
22+
UserTools.user_login(page, user_role)
23+
# Navigate to Active Batch List
24+
BasePage(page).go_to_communications_production_page()
25+
CommunicationsProductionPage(page).go_to_archived_batch_list_page()
26+
return page
27+
28+
return _login_as
29+
30+
31+
@pytest.mark.wip
32+
@pytest.mark.letters_tests
33+
@pytest.mark.regression
34+
def test_reprint_and_archive_letter_batch(select_user) -> None:
35+
"""
36+
Scenario: I can take an archived batch, reprint it, then archive that new batch
37+
Given I log in to BCSS "England" as user role "HubManagerStateRegistered"
38+
When I view the archived batch list
39+
And I view the "Original" type archived letter batch for "S1" "Pre"
40+
And I reprint the archived letter batch
41+
And I prepare the letter batch
42+
And I retrieve and confirm the letters
43+
And my batch is now archived
44+
"""
45+
# Step 1: Log in as user and navigate to Archived Batch List
46+
page = select_user("Hub Manager State Registered at BCS01")
47+
batch_list_page = ArchivedBatchListPage(page)
48+
49+
# Step 2: Ensure the archived batch list table is visible
50+
batch_list_page.assert_batch_table_visible()
51+
# Wait for at least one row to appear
52+
page.wait_for_function(
53+
"document.querySelectorAll('table#batchList tbody tr').length > 1", timeout=8000
54+
)
55+
rows = page.locator("table#batchList tbody tr")
56+
row_count = rows.count()
57+
58+
for i in range(row_count):
59+
row = rows.nth(i)
60+
61+
# Step 3: Find and open archived batch with Type "Original", Event Code "S1", and Description "Pre"
62+
# You might want to use filters like:
63+
row = batch_list_page.get_archived_batch_row(
64+
"Original", "S1", "Pre-invitation (FIT)"
65+
)
66+
if not row:
67+
pytest.skip("No archived 'Original' S1 Pre batches found to reprint.")
68+
69+
batch_id = row.locator("a").first.inner_text()
70+
row.locator("a").first.click()
71+
72+
# Step 4: Perform reprint from Archived Batch detail screen
73+
manage_archived_page = ManageArchivedBatchPage(page) # Assuming reuse
74+
manage_archived_page.assert_archived_batch_details_visible()
75+
manage_archived_page.click_reprint_button()
76+
BasePage(page).safe_accept_dialog(page.get_by_role("button", name="Reprint Batch"))
77+
78+
# Step 5: Wait for navigation to new Active Batch screen
79+
# You’ll likely land back in Active Batch context
80+
manage_active_page = ManageActiveBatchPage(page)
81+
manage_active_page.assert_active_batch_details_visible()
82+
83+
# Step 6: Prepare, retrieve and confirm new batch
84+
prepare_and_print_batch(page, link_text=batch_id)
85+
86+
# Step 7: Assert batch archived successfully
87+
manage_archived_page.confirm_archived_message_visible()
1388

1489

1590
# Scenario: Check that S1 has supplementary batches

0 commit comments

Comments
 (0)