Skip to content

Commit 93c1da2

Browse files
committed
Added test_prepare_retrieve_and_confirm_active_letter_batch
1 parent 6e1bdc2 commit 93c1da2

File tree

3 files changed

+136
-31
lines changed

3 files changed

+136
-31
lines changed

pages/communication_production/batch_list_page.py

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from playwright.sync_api import Page, expect
1+
from playwright.sync_api import Page, expect, Locator
22
from pages.base_page import BasePage
33
from datetime import datetime
44
from utils.calendar_picker import CalendarPicker
@@ -130,29 +130,36 @@ def verify_deadline_date_filter_input(self, expected_text: str) -> None:
130130
expect(self.deadline_date_filter_with_input).to_have_value(expected_text)
131131

132132
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 = "",
134138
) -> None:
135139
"""
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.
142141
"""
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
156163
expect(view_link).to_be_visible()
157164
view_link.click()
158165

@@ -189,6 +196,28 @@ def prepare_batch(self, batch_type: str) -> None:
189196
prepare_button.click()
190197
expect(row).not_to_be_visible(timeout=5000)
191198

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+
192221

193222
class ArchivedBatchListPage(BatchListPage):
194223
"""Archived Batch List Page-specific setup."""

pages/communication_production/manage_active_batch_page.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from playwright.sync_api import Page
22
from pages.base_page import BasePage
33
from playwright.sync_api import expect
4+
import re
45

56

67
class ManageActiveBatchPage(BasePage):
@@ -35,3 +36,29 @@ def assert_batch_details_visible(self) -> None:
3536
"""Asserts that the Manage Active Batch screen has loaded by checking the page title."""
3637
page_title = self.page.locator("#page-title")
3738
expect(page_title).to_have_text("Manage Active Batch")
39+
40+
def prepare_and_print(self) -> None:
41+
"""Clicks the Prepare and Print button."""
42+
button = self.page.get_by_role("button", name="Prepare and Print")
43+
expect(button).to_be_enabled()
44+
button.click()
45+
46+
def retrieve_and_confirm_letters(self) -> None:
47+
"""Clicks the Retrieve and Confirm Letters button."""
48+
button = self.page.get_by_role("button", name="Retrieve and Confirm Letters")
49+
expect(button).to_be_enabled()
50+
button.click()
51+
52+
def assert_confirmation_success_message(self) -> None:
53+
"""Verifies the confirmation message is shown after printing."""
54+
message = self.page.locator('text="Batch Successfully Archived and Printed"')
55+
expect(message).to_be_visible()
56+
57+
def get_batch_id(self) -> str:
58+
"""Extracts the batch ID from the page title."""
59+
title_text = self.page.locator("#page-title").inner_text()
60+
print(f"[DEBUG] Page title text: '{title_text}'")
61+
match = re.search(r"\d+", title_text)
62+
if match:
63+
return match.group()
64+
raise ValueError("Batch ID not found in page title.")
Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,62 @@
1-
# @LettersTests
2-
# Feature: Basic Manage Active 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 ActiveBatchListPage
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.batch_list_page import ActiveBatchListPage
13+
from utils.batch_processing import prepare_and_print_batch
314

415

5-
# Scenario: I can prepare, retrieve and confirm a letter batch of any number of files
6-
# The first open batch will be picked up for processing, regardless of letter type
16+
@pytest.fixture
17+
def select_user(page: Page):
18+
def _login_as(user_role: str):
19+
# Log in with the specified user
20+
UserTools.user_login(page, user_role)
21+
# Navigate to Active Batch List
22+
BasePage(page).go_to_communications_production_page()
23+
CommunicationsProductionPage(page).go_to_active_batch_list_page()
24+
return page
725

8-
# Given I log in to BCSS "England" as user role "HubManagerStateRegistered"
9-
# When I view the active batch list
10-
# And There are open letter batches to process in the active batch list
11-
# Then I view the "Original" type "Open" status active letter batch for "" ""
12-
# And I prepare the letter batch
13-
# And I retrieve and confirm the letters
26+
return _login_as
27+
28+
29+
@pytest.mark.letters_tests
30+
@pytest.mark.regression
31+
def test_prepare_retrieve_and_confirm_active_letter_batch(select_user) -> None:
32+
"""
33+
Scenario: I can prepare, retrieve and confirm a letter batch of any number of files
34+
Given I log in to BCSS "England" as user role "HubManagerStateRegistered"
35+
When I view the active batch list
36+
And there are open letter batches to process in the active batch list
37+
Then I view the "Original" type "Open" status active letter batch
38+
And I prepare the letter batch
39+
And I retrieve and confirm the letters
40+
"""
41+
# Step 1: Log in as Hub Manager (State Registered) and access Active Batch List
42+
page = select_user("Hub Manager State Registered at BCS01")
43+
batch_list_page = ActiveBatchListPage(page)
44+
45+
# Step 2: Ensure the active batch list table is visible
46+
batch_list_page.assert_batch_table_visible()
47+
48+
# Step 3: Locate the first batch with type "Original" and status "Open"
49+
row = batch_list_page.get_open_original_batch_row()
50+
if not row:
51+
pytest.skip("No open 'Original' batches found in the active batch list.")
52+
53+
# Step 4: Capture the batch ID from the selected row and click to open
54+
batch_id = row.locator("a").first.inner_text()
55+
row.locator("a").first.click()
56+
57+
# Step 5: Assert that Manage Active Batch page has loaded
58+
manage_page = ManageActiveBatchPage(page)
59+
manage_page.assert_batch_details_visible()
60+
61+
# Step 6: Prepare, retrieve and confirm the batch using utility method
62+
prepare_and_print_batch(page, link_text=batch_id)

0 commit comments

Comments
 (0)