Skip to content

Commit 326c996

Browse files
committed
refactoring
1 parent fbc63bd commit 326c996

File tree

4 files changed

+82
-89
lines changed

4 files changed

+82
-89
lines changed

tests/regression/communications_production/test_basic_active_batch_list_functionality.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,28 @@
1111
)
1212

1313

14-
@pytest.fixture
15-
def select_user(page: Page):
16-
def _login_as(user_role: str):
17-
# Log in with the specified user
18-
UserTools.user_login(page, user_role)
19-
# Navigate to Active Batch List
20-
BasePage(page).go_to_communications_production_page()
21-
CommunicationsProductionPage(page).go_to_active_batch_list_page()
22-
return page
14+
@pytest.fixture(scope="function", autouse=True)
15+
def before_each(page: Page):
16+
"""
17+
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the active batch list page
18+
"""
19+
# Log in to BCSS
20+
UserTools.user_login(page, "Hub Manager at BCS01")
2321

24-
return _login_as
22+
# Go to active batch list page
23+
BasePage(page).go_to_communications_production_page()
24+
CommunicationsProductionPage(page).go_to_active_batch_list_page()
2525

2626

2727
@pytest.mark.letters_tests
2828
@pytest.mark.regression
29-
def test_headings_on_active_batch_list_screen(select_user) -> None:
29+
def test_headings_on_active_batch_list_screen(page: Page) -> None:
3030
"""
3131
Scenario: Check headings on Active Batch List Screen
3232
Given I log in to BCSS "England" as user role "HubManager"
3333
When I view the active batch list
3434
Then the table contains a sortable and filterable column for "<Column Name>"
3535
"""
36-
page = select_user("Hub Manager at BCS01")
3736
batch_list_page = ActiveBatchListPage(page)
3837

3938
expected_columns = [
@@ -49,37 +48,36 @@ def test_headings_on_active_batch_list_screen(select_user) -> None:
4948
"Deadline",
5049
"Count",
5150
]
52-
51+
# The table contains a sortable and filterable column for each expected header
5352
for column in expected_columns:
54-
# Step 1: Ensure the column is present
53+
# Ensure the column is present
5554
batch_list_page.assert_column_present(column)
5655

57-
# Step 2: Assert sortable UI attribute is present
56+
# Assert sortable UI attribute is present
5857
batch_list_page.assert_column_sortable(column)
5958

60-
# Step 3: Assert filterable control is rendered
59+
# Assert filterable control is rendered
6160
batch_list_page.assert_column_filterable(column)
6261

6362

6463
@pytest.mark.letters_tests
6564
@pytest.mark.regression
66-
def test_navigation_to_manage_active_batch_screen(select_user) -> None:
65+
def test_navigation_to_manage_active_batch_screen(page: Page) -> None:
6766
"""
6867
Scenario: Check navigation from Active Batch List Screen to Manage Active Batch Screen
6968
Given I log in to BCSS "England" as user role "HubManager"
7069
When I view the active batch list
7170
And I select an active batch
7271
Then I view the details of an active batch
7372
"""
74-
page = select_user("Hub Manager at BCS01")
7573
batch_list_page = ActiveBatchListPage(page)
7674

77-
# Step 1: Ensure the batch list table is visible
75+
# Ensure the batch list table is visible
7876
batch_list_page.assert_batch_table_visible()
7977

80-
# Step 2: Click into the first available batch link (usually ID column)
78+
# Click into the first available batch link
8179
batch_list_page.select_first_active_batch()
8280

83-
# Step 3: Assert navigation to the Manage Active Batch page
81+
# Assert navigation to the Manage Active Batch page
8482
manage_batch_page = ManageActiveBatchPage(page)
8583
manage_batch_page.assert_active_batch_details_visible()

tests/regression/communications_production/test_basic_archived_batch_list_functionality.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,28 @@
1313
)
1414

1515

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_archived_batch_list_page()
24-
return page
16+
@pytest.fixture(scope="function", autouse=True)
17+
def before_each(page: Page):
18+
"""
19+
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the archived batch list page
20+
"""
21+
# Log in to BCSS
22+
UserTools.user_login(page, "Hub Manager at BCS01")
2523

26-
return _login_as
24+
# Go to active batch list page
25+
BasePage(page).go_to_communications_production_page()
26+
CommunicationsProductionPage(page).go_to_archived_batch_list_page()
2727

2828

2929
@pytest.mark.letters_tests
3030
@pytest.mark.regression
31-
def test_headings_on_archived_batch_list_screen(select_user) -> None:
31+
def test_headings_on_archived_batch_list_screen(page: Page) -> None:
3232
"""
3333
Scenario: Check headings on Archived Batch List Screen
3434
Given I log in to BCSS "England" as user role "HubManager"
3535
When I view the archived batch list
3636
Then the table contains a sortable and filterable column for each expected header
3737
"""
38-
page = select_user("Hub Manager at BCS01")
3938

4039
archived_batch_list_page = ArchivedBatchListPage(page)
4140

@@ -54,37 +53,36 @@ def test_headings_on_archived_batch_list_screen(select_user) -> None:
5453
"Date Archived",
5554
"Count",
5655
]
57-
56+
# The table contains a sortable and filterable column for each expected header
5857
for column in expected_columns:
59-
# Step 1: Ensure the column is present
58+
# Ensure the column is present
6059
archived_batch_list_page.assert_column_present(column)
6160

62-
# Step 2: Assert sortable UI attribute is present
61+
# Assert sortable UI attribute is present
6362
archived_batch_list_page.assert_column_sortable(column)
6463

65-
# Step 3: Assert filterable control is rendered
64+
# Assert filterable control is rendered
6665
archived_batch_list_page.assert_column_filterable(column)
6766

6867

6968
@pytest.mark.letters_tests
7069
@pytest.mark.regression
71-
def test_navigation_to_manage_archived_batch_screen(select_user) -> None:
70+
def test_navigation_to_manage_archived_batch_screen(page: Page) -> None:
7271
"""
7372
Scenario: Check navigation from Archived Batch List Screen to Manage Archived Batch Screen
7473
Given I log in to BCSS "England" as user role "HubManager"
7574
When I view the archived batch list
7675
And I select an archived batch
7776
Then I view the details of an archived batch
7877
"""
79-
page = select_user("Hub Manager at BCS01")
8078
archived_batch_list_page = ArchivedBatchListPage(page)
8179

82-
# Step 1: Ensure the archived batch table is visible
80+
# Ensure the archived batch table is visible
8381
archived_batch_list_page.assert_batch_table_visible()
8482

85-
# Step 2: Click into the first available archived batch
83+
# Click into the first available archived batch
8684
archived_batch_list_page.select_first_archived_batch()
8785

88-
# Step 3: Assert navigation to the Manage Archived Batch page
86+
# Assert navigation to the Manage Archived Batch page
8987
manage_batch_page = ManageArchivedBatchPage(page)
9088
manage_batch_page.assert_archived_batch_details_visible()

tests/regression/communications_production/test_basic_manage_active_batch_functionality.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
from utils.batch_processing import prepare_and_print_batch
1313

1414

15-
@pytest.fixture
16-
def select_user(page: Page):
17-
def _login_as(user_role: str):
18-
# Log in with the specified user
19-
UserTools.user_login(page, user_role)
20-
# Navigate to Active Batch List
21-
BasePage(page).go_to_communications_production_page()
22-
CommunicationsProductionPage(page).go_to_active_batch_list_page()
23-
return page
15+
@pytest.fixture(scope="function", autouse=True)
16+
def before_each(page: Page):
17+
"""
18+
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the active batch list page
19+
"""
20+
# Log in to BCSS
21+
UserTools.user_login(page, "Hub Manager at BCS01")
2422

25-
return _login_as
23+
# Go to active batch list page
24+
BasePage(page).go_to_communications_production_page()
25+
CommunicationsProductionPage(page).go_to_active_batch_list_page()
2626

2727

2828
@pytest.mark.letters_tests
2929
@pytest.mark.regression
30-
def test_prepare_retrieve_and_confirm_active_letter_batch(select_user) -> None:
30+
def test_prepare_retrieve_and_confirm_active_letter_batch(page: Page) -> None:
3131
"""
3232
Scenario: I can prepare, retrieve and confirm a letter batch of any number of files
3333
Given I log in to BCSS "England" as user role "HubManagerStateRegistered"
@@ -37,25 +37,24 @@ def test_prepare_retrieve_and_confirm_active_letter_batch(select_user) -> None:
3737
And I prepare the letter batch
3838
And I retrieve and confirm the letters
3939
"""
40-
# Step 1: Log in as Hub Manager (State Registered) and access Active Batch List
41-
page = select_user("Hub Manager State Registered at BCS01")
40+
# Access Active Batch List
4241
batch_list_page = ActiveBatchListPage(page)
4342

44-
# Step 2: Ensure the active batch list table is visible
43+
# Ensure the active batch list table is visible
4544
batch_list_page.assert_batch_table_visible()
4645

47-
# Step 3: Locate the first batch with type "Original" and status "Open"
46+
# Locate the first batch with type "Original" and status "Open"
4847
row = batch_list_page.get_open_original_batch_row()
4948
if not row:
5049
pytest.skip("No open 'Original' batches found in the active batch list.")
5150

52-
# Step 4: Capture the batch ID from the selected row and click to open
51+
# Capture the batch ID from the selected row and click to open
5352
batch_id = row.locator("a").first.inner_text()
5453
row.locator("a").first.click()
5554

56-
# Step 5: Assert that Manage Active Batch page has loaded
55+
# Assert that Manage Active Batch page has loaded
5756
manage_page = ManageActiveBatchPage(page)
5857
manage_page.assert_active_batch_details_visible()
5958

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

tests/regression/communications_production/test_basic_manage_archived_batch_functionality.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
from utils.batch_processing import prepare_and_print_batch
1919

2020

21-
@pytest.fixture
22-
def select_user(page: Page):
23-
def _login_as(user_role: str):
24-
# Log in with the specified user
25-
UserTools.user_login(page, user_role)
26-
# Navigate to communications production page
27-
BasePage(page).go_to_communications_production_page()
28-
return page
21+
@pytest.fixture(scope="function", autouse=True)
22+
def before_each(page: Page):
23+
"""
24+
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the communications production page
25+
"""
26+
# Log in to BCSS
27+
UserTools.user_login(page, "Hub Manager at BCS01")
2928

30-
return _login_as
29+
# Go to communications production page
30+
BasePage(page).go_to_communications_production_page()
3131

3232

3333
@pytest.mark.letters_tests
3434
@pytest.mark.regression
35-
def test_reprint_and_archive_letter_batch(select_user) -> None:
35+
def test_reprint_and_archive_letter_batch(page: Page) -> None:
3636
"""
3737
Scenario: I can take an archived batch, reprint it, then archive that new batch
3838
Given I log in to BCSS "England" as user role "HubManagerStateRegistered"
@@ -43,13 +43,12 @@ def test_reprint_and_archive_letter_batch(select_user) -> None:
4343
And I retrieve and confirm the letters
4444
And my batch is now archived
4545
"""
46-
# Step 1: Log in as user and navigate to Archived Batch List
47-
page = select_user("Hub Manager State Registered at BCS01")
46+
# Navigate to Archived Batch List
4847
CommunicationsProductionPage(page).go_to_archived_batch_list_page()
49-
batch_list_page = ArchivedBatchListPage(page)
48+
archived_batch_list_page = ArchivedBatchListPage(page)
5049

51-
# Step 2: Ensure the archived batch list table is visible
52-
batch_list_page.assert_batch_table_visible()
50+
# Ensure the archived batch list table is visible
51+
archived_batch_list_page.assert_batch_table_visible()
5352
# Wait for at least one row to appear
5453
page.wait_for_function(
5554
"document.querySelectorAll('table#batchList tbody tr').length > 1", timeout=8000
@@ -60,9 +59,9 @@ def test_reprint_and_archive_letter_batch(select_user) -> None:
6059
for i in range(row_count):
6160
row = rows.nth(i)
6261

63-
# Step 3: Find and open archived batch with Type "Original", Event Code "S1", and Description "Pre"
62+
# Find and open archived batch with Type "Original", Event Code "S1", and Description "Pre"
6463
# You might want to use filters like:
65-
row = batch_list_page.get_archived_batch_row(
64+
row = archived_batch_list_page.get_archived_batch_row(
6665
"Original", "S1", "Pre-invitation (FIT)"
6766
)
6867
if not row:
@@ -71,27 +70,26 @@ def test_reprint_and_archive_letter_batch(select_user) -> None:
7170
batch_id = row.locator("a").first.inner_text()
7271
row.locator("a").first.click()
7372

74-
# Step 4: Perform reprint from Archived Batch detail screen
73+
# Perform reprint from Archived Batch detail screen
7574
manage_archived_page = ManageArchivedBatchPage(page) # Assuming reuse
7675
manage_archived_page.assert_archived_batch_details_visible()
7776
manage_archived_page.click_reprint_button()
7877
BasePage(page).safe_accept_dialog(page.get_by_role("button", name="Reprint Batch"))
7978

80-
# Step 5: Wait for navigation to new Active Batch screen
81-
# You’ll likely land back in Active Batch context
79+
# Wait for navigation to new Active Batch screen
8280
manage_active_page = ManageActiveBatchPage(page)
8381
manage_active_page.assert_active_batch_details_visible()
8482

85-
# Step 6: Prepare, retrieve and confirm new batch
83+
# Prepare, retrieve and confirm new batch
8684
prepare_and_print_batch(page, link_text=batch_id)
8785

88-
# Step 7: Assert batch archived successfully
86+
# Assert batch archived successfully
8987
manage_archived_page.confirm_archived_message_visible()
9088

9189

9290
@pytest.mark.letters_tests
9391
@pytest.mark.regression
94-
def test_check_that_s1_has_supplementary_batches(select_user) -> None:
92+
def test_check_that_s1_has_supplementary_batches(page: Page) -> None:
9593
"""
9694
Scenario: I can create a supplementary batch for S1 and archive it
9795
Given I log in to BCSS "England" as user role "HubManagerStateRegistered"
@@ -101,14 +99,14 @@ def test_check_that_s1_has_supplementary_batches(select_user) -> None:
10199
And I Go to letter library index and filter by Supplementary Letters
102100
And I Open a supplementary letter
103101
"""
104-
# Step 1: Log in as user and navigate to Letter Library Index
105-
page = select_user("Hub Manager State Registered at BCS01")
102+
103+
# Navigate to Letter Library Index
106104
CommunicationsProductionPage(page).go_to_letter_library_index_page()
107105

108-
# Step 2: Filter for "Invitation Letters" group
106+
# Filter for "Invitation Letters" group
109107
LetterLibraryIndexPage(page).filter_by_letters_group("Invitation Letters")
110108

111-
# Step 3: Ensure S1 supplementary batches can be created
109+
# Ensure S1 supplementary batches can be created
112110
LetterLibraryIndexPage(page).filter_by_event_code("S1")
113111
LetterLibraryIndexPage(page).click_first_letter_code_link_in_table()
114112
LetterLibraryIndexPage(page).click_define_supplementary_letter_button()
@@ -122,11 +120,11 @@ def test_check_that_s1_has_supplementary_batches(select_user) -> None:
122120
)
123121
expect(page.locator("#ntshPageTitle")).to_contain_text("Version History")
124122

125-
# Step 4: Go to letter library index and filter by Supplementary Letters
123+
# Go to letter library index and filter by Supplementary Letters
126124
BasePage(page).click_main_menu_link()
127125
BasePage(page).go_to_communications_production_page()
128126
CommunicationsProductionPage(page).go_to_letter_library_index_page()
129127
LetterLibraryIndexPage(page).filter_by_letters_group("Supplementary Letters")
130128

131-
# Step 5: Open a supplementary letter
129+
# Open a supplementary letter
132130
LetterLibraryIndexPage(page).click_first_letter_code_link_in_table()

0 commit comments

Comments
 (0)