Skip to content

Commit 8e0e69b

Browse files
Merge branch 'main' into feature/BCSS-20608-new-regression-tests-subject-spine-retrieval
2 parents f50defc + ab514ab commit 8e0e69b

File tree

14 files changed

+5037
-44
lines changed

14 files changed

+5037
-44
lines changed

docs/utility-guides/ManualCease.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Utility Guide: Manual Cease Workflow
2+
3+
This utility facilitates creation, UI automation, and database verification for manual cease workflows in the BCSS Playwright test suite.<br> It includes:
4+
5+
1. Generating a subject eligible for manual cease via database creation and timeline event execution.
6+
2. Performing the cease workflow through the browser UI, supporting both 'immediate' and 'with disclaimer' flows.
7+
3. Validating dynamic database fields after cease is completed.
8+
9+
## Table of Contents
10+
11+
- [Utility Guide: Manual Cease Workflow](#utility-guide-manual-cease-workflow)
12+
- [Table of Contents](#table-of-contents)
13+
- [Creating Subjects for Cease](#creating-subjects-for-cease)
14+
- [Arguments](#arguments)
15+
- [How to use this method](#how-to-use-this-method)
16+
- [UI Workflow Methods](#ui-workflow-methods)
17+
- [Standard Flow (with Disclaimer)](#standard-flow-with-disclaimer)
18+
- [Immediate Flow](#immediate-flow)
19+
- [DB Verification](#db-verification)
20+
- [Arguments](#arguments-1)
21+
- [How to use this method](#how-to-use-this-method-1)
22+
- [Enums and Constants](#enums-and-constants)
23+
- [EXPECT markers](#expect-markers)
24+
- [Status \& Reason Enums](#status--reason-enums)
25+
26+
## Creating Subjects for Cease
27+
28+
The `create_manual_cease_ready_subject` method creates a subject with Inactive screening status and executes timed events, preparing it for the cease flow.
29+
30+
### Arguments
31+
32+
`screening_centre`:
33+
Type: str
34+
Screening centre to associate with the subject. Defaults to "BCS002".
35+
36+
`base_age`:
37+
Type: int
38+
Age threshold used during subject creation. Defaults to 75.
39+
40+
### How to use this method
41+
42+
```python
43+
from utils.manual_cease_util import create_manual_cease_ready_subject
44+
nhs_number = create_manual_cease_ready_subject(screening_centre="BCS002", base_age=75)
45+
```
46+
47+
## UI Workflow Methods
48+
49+
### Standard Flow (with Disclaimer)
50+
51+
`process_manual_cease_with_disclaimer(page: Page, reason: str = "Informed Dissent")` automates the full cease workflow including disclaimer steps.
52+
53+
```python
54+
from utils.manual_cease_util import process_manual_cease_with_disclaimer
55+
process_manual_cease_with_disclaimer(page, reason="Moved Away")
56+
```
57+
58+
### Immediate Flow
59+
60+
`process_manual_cease_immediate(page: Page, reason: str = "Informed Dissent")` performs the cease workflow without recording disclaimer letters.
61+
62+
```python
63+
from utils.manual_cease_util import process_manual_cease_immediate
64+
process_manual_cease_immediate(page, reason="Deceased")
65+
```
66+
67+
## DB Verification
68+
69+
The method `verify_manual_cease_db_fields_dynamic(nhs_number: str, expected: dict[str, object])` dynamically validates updated DB fields based on supplied expectations.
70+
71+
### Arguments
72+
73+
nhs_number:
74+
Type: str
75+
NHS number of the subject to validate.
76+
77+
expected:
78+
Type: dict[str, object]
79+
A dictionary mapping human-readable field labels to expected values. Supports assertions like TODAY, NULL, UNCHANGED, or direct values.
80+
81+
### How to use this method
82+
83+
```python
84+
from utils.manual_cease_util import verify_manual_cease_db_fields_dynamic, EXPECT
85+
86+
verify_manual_cease_db_fields_dynamic(nhs_number, {
87+
"Screening Status": 4008,
88+
"Screening Status Reason": 43,
89+
"Ceased Confirmation Date": EXPECT.TODAY,
90+
"Ceased Confirmation Details": "AUTO TEST: notes"
91+
})
92+
```
93+
94+
## Enums and Constants
95+
96+
### EXPECT markers
97+
98+
Used in DB assertions to express flexible expectations.
99+
EXPECT.TODAY: Field must match today's date.
100+
EXPECT.NULL: Field must be null.
101+
EXPECT.UNCHANGED: Field must exist but is not asserted.
102+
EXPECT.MATCH_USER_ID: Field must be a valid user ID.
103+
104+
### Status & Reason Enums
105+
106+
The utility includes enums for easier mapping in test code:
107+
108+
```python
109+
from utils.manual_cease_util import ScreeningStatus, ScreeningStatusReason
110+
111+
ScreeningStatus.CEASED # → 4008
112+
ScreeningStatusReason.DECEASED # → 45
113+
```
114+
115+
Refer to the source code in `utils/manual_cease_util.py` for additional mappings and helper logic.

pages/base_page.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,15 @@ def handle_dialog(dialog: Dialog, accept: bool = False):
276276
except AssertionError as e:
277277
self._dialog_assertion_error = e
278278
if accept:
279-
dialog.accept()
279+
try:
280+
dialog.accept()
281+
except Exception:
282+
logging.warning("Dialog already accepted or handled")
280283
else:
281-
dialog.dismiss() # Dismiss dialog
284+
try:
285+
dialog.dismiss() # Dismiss dialog
286+
except Exception:
287+
logging.warning("Dialog already dismissed or handled")
282288

283289
self.page.once("dialog", lambda dialog: handle_dialog(dialog, accept))
284290

0 commit comments

Comments
 (0)