Skip to content

Commit 69acdeb

Browse files
authored
Merge branch 'main' into feature/BCSS-21307-fobt-regression-tests-scenario-5
Signed-off-by: AndyG <[email protected]>
2 parents 26e772c + c333f93 commit 69acdeb

31 files changed

+6994
-14
lines changed

.gitleaksignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,4 @@ cae84544e2852202f5d0abb9ad18f9d83a0c6d80:subject_criteria_builder/criteria.json:
225225
203cd8811be75d33859eb7c7cc8a48beb5a2b8b2:subject_criteria_builder/criteria.json:generic-api-key:4210
226226
60468a7d6f3ff3259616757be85d6f07e62d00b6:subject_criteria_builder/criteria.json:generic-api-key:4210
227227
145171b9e9d169acb136fc527708c997c9ad9f61:subject_criteria_builder/criteria.json:generic-api-key:4210
228+
2ccb5e91033934d4818c1efa2eb1696b5511ebc9:subject_criteria_builder/criteria.json:generic-api-key:4210

Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,22 @@ include scripts/init.mk
55

66
# ==============================================================================
77

8-
# NOTE: This project currently only uses this Makefile as part of CI/CD checks.
8+
# This allows the setup of Playwright by using a single command ready to use, and checks
9+
# if the user is in a virtual environment before running the setup.
10+
11+
.PHONY: check-venv
12+
check-venv: # Checks if in a Python venv / VIRTUALENV before installing a bunch of dependencies
13+
@python -c "import sys, os; \
14+
venv = (hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix) or 'VIRTUAL_ENV' in os.environ); \
15+
import sys; sys.exit(0 if venv else 1)"
16+
17+
setup-playwright: # Install Playwright and associated packages, and create local.env
18+
@echo "Checking for virtual environment..."
19+
$(MAKE) check-venv || (echo "ERROR: Not in a virtual environment, please create before running this command!"; exit 1)
20+
21+
@echo "Install Playwright"
22+
pip install -r requirements.txt
23+
playwright install
24+
25+
@echo "Setup local.env file"
26+
python setup_env_file.py

README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BCSS Playwright Test Suite
22

3-
[![CI/CD Pull Request](https://github.com/nhs-england-tools/repository-template/actions/workflows/cicd-1-pull-request.yaml/badge.svg)](https://github.com/nhs-england-tools/playwright-python-blueprint/actions/workflows/cicd-1-pull-request.yaml)
3+
[![CI/CD Pull Request](https://github.com/nhs-england-tools/playwright-python-blueprint/actions/workflows/cicd-1-pull-request.yaml/badge.svg)](https://github.com/nhs-england-tools/playwright-python-blueprint/actions/workflows/cicd-1-pull-request.yaml)
44

55
This repository contains the automated UI test suite for the BCSS application, built using [Playwright Python](https://playwright.dev/python/). It provides a structured framework and reusable utilities to support consistent, maintainable test development across the project.
66

@@ -48,7 +48,8 @@ Note: This project is actively maintained and evolving.
4848
- [3. Best Practices](#3-best-practices)
4949
- [4. Blueprint Utilities](#4-blueprint-utilities)
5050
- [5. BCSS Project Specific Utilities](#5-bcss-project-specific-utilities)
51-
- [Contributing](#contributing)
51+
- [Using the Jira Upload Script](#using-the-jira-upload-script)
52+
- [Contributing](#contributing)
5253
- [Contacts](#contacts)
5354
- [Licence](#licence)
5455

@@ -379,7 +380,57 @@ These utilities have been created specifically for the bcss playwright project:
379380
| [Table Utility](.docs/utility-guides/TableUtil.md) | Provides helper methods for interacting with HTML tables, including row selection, column indexing, and data extraction. |
380381
| [User Tools](.docs/utility-guides/UserTools.md) | Manages test user credentials via `users.json`, supports login automation, and retrieves user metadata for role-based testing. |
381382

382-
### Contributing
383+
## Using the Jira Upload Script
384+
385+
Included with this code is a Jira Upload utility that will allow for the uploading of artifacts from test runs to
386+
a Jira ticket directly. The script itself ([`jira_upload.py`](jira_upload.py)) can be invoked using the following
387+
command:
388+
389+
```shell
390+
python jira_upload.py
391+
```
392+
393+
For this to work, you need to set the follow environment variables (which you can do via local.env):
394+
395+
| Key | Required | Description |
396+
| --------------------- | -------- | ------------------------------------------------------------------------------------------------------ |
397+
| `JIRA_URL` | Yes | The Jira instance url to connect to |
398+
| `JIRA_PROJECT_KEY` | Yes | The project key for the Jira project to upload to |
399+
| `JIRA_API_KEY` | Yes | The Jira API key for your user, which can be generated in Jira via Profile > Personal Access Tokens |
400+
| `JIRA_TICKET_REFERENCE` | No | The Jira ticket you want to default to, if required. Can be left blank to use branch-based referencing |
401+
402+
This command will do the following actions:
403+
404+
1. Work out the Jira ticket to upload to and confirm it is a valid reference, by using the following logic:
405+
1. If a `--jira-ref` value has been provided, use that value.
406+
2. If a `JIRA_TICKET_REFERENCE` environment variable exists, use that value.
407+
3. If none of the above, check if you are in a feature branch and if so, compiles the Jira ticket reference by combining the project key and the end of the feature branch (when in the format `feature/<shortcode>-<jira_ticket_number>`).
408+
2. Check the `test-results/` directory (or custom directory if specified) for appropriate files under 10MB (Jira's file limit), specifically:
409+
1. HTML files (e.g. `report.html` generated by `pytest`).
410+
2. Trace Files (e.g. `test_name/trace.zip` generated by Playwright).
411+
3. Screenshots (e.g. `test_screenshot.png` generated by Playwright).
412+
4. CSV Files (e.g. `results.csv` generated during test execution from the UI).
413+
3. Prompt the user to confirm that they are updating the correct ticket and the correct files are being uploaded. If files already exist on the ticket with a matching name, a unique name will be provided unless `--overwrite-files` is provided.
414+
4. If `y` is selected, upload the files and add a comment (unless `--no-comment` is provided) to Jira outlining the files uploaded and if possible, the environment information from the test run (unless `--no-env-data` is provided).
415+
416+
You can also pass in the following arguments which will have the noted effects:
417+
418+
| Argument | Description |
419+
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
420+
| `--jira-ref <Jira Reference>` | The Jira ticket to upload to. Will take precedence over auto-deriving from branch name and the set environment variable. |
421+
| `--results-dir <Directory>` | The directory to point to. If not set, points to `test-results/` (the default directory for test results in this repository). |
422+
| `--no-html` | Don't include HTML files in the upload. |
423+
| `--no-trace` | Don't include Trace files (.zip) in the upload. |
424+
| `--no-csv` | Don't include CSV files in the upload. |
425+
| `--no-screenshots` | Don't include screenshots (.png) in the upload. |
426+
| `--no-comment` | Don't add a Jira comment highlighting the results. |
427+
| `--no-env-data` | Don't include environment data in the Jira comment (if getting environment data has been configured). |
428+
| `--overwrite-files` | If a filename exists on the ticket that matches those in the results directory, overwrite them. |
429+
| `--auto-confirm` | Will not ask if you want to proceed if provided, and will assume that yes has been pressed. |
430+
431+
Further information on the available actions for this logic can be found in the [Jira Confluence Utility utility guide](./docs/utility-guides/JiraConfluenceUtil.md).
432+
433+
## Contributing
383434

384435
Further guidance on contributing to this project can be found in our [contribution](./CONTRIBUTING.md) page.
385436

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
# Subject Criteria Builder Application
2+
3+
This application is a Streamlit-based tool for interactively building subject selection criteria for the NHS BCSS system. It allows users to search, select, and configure criteria keys, view descriptions, choose from allowed values, and copy the resulting criteria as JSON. It also generates the corresponding SQL query and, if required, allows you to select a user or enter a subject's NHS number to populate the query context.
4+
5+
---
6+
7+
## Table of Contents
8+
9+
- [Subject Criteria Builder Application](#subject-criteria-builder-application)
10+
- [Table of Contents](#table-of-contents)
11+
- [How to Use the Application](#how-to-use-the-application)
12+
- [Pre-requisites](#pre-requisites)
13+
- [Launching the App](#launching-the-app)
14+
- [Searching for Criteria](#searching-for-criteria)
15+
- [Selecting and Configuring a Criterion](#selecting-and-configuring-a-criterion)
16+
- [User and Subject Dependencies](#user-and-subject-dependencies)
17+
- [Copying the Criteria](#copying-the-criteria)
18+
- [Resetting the Builder and Hiding Criteria](#resetting-the-builder-and-hiding-criteria)
19+
- [Maintaining the Application](#maintaining-the-application)
20+
- [Updating `criteria.json`](#updating-criteriajson)
21+
- [To add a new criterion](#to-add-a-new-criterion)
22+
- [To edit a criterion](#to-edit-a-criterion)
23+
- [To remove a criterion](#to-remove-a-criterion)
24+
- [About the `dependencies` field](#about-the-dependencies-field)
25+
- [Adding New Criteria Keys](#adding-new-criteria-keys)
26+
- [Editing Allowed Values or Descriptions](#editing-allowed-values-or-descriptions)
27+
- [Troubleshooting](#troubleshooting)
28+
- [Example Entry in `criteria.json`](#example-entry-in-criteriajson)
29+
- [Summary](#summary)
30+
31+
---
32+
33+
## How to Use the Application
34+
35+
### Pre-requisites
36+
37+
Before running the application, you must create a `local.env` file containing your Oracle database credentials.<br>
38+
You can generate a template for this file by running:
39+
40+
```bash
41+
python setup_env_file.py
42+
```
43+
44+
After running the script, open the generated `local.env` file and populate the following fields with your Oracle credentials:
45+
46+
```env
47+
ORACLE_USERNAME=your_oracle_username
48+
ORACLE_DB=your_oracle_db
49+
ORACLE_PASS=your_oracle_password
50+
```
51+
52+
These credentials are required for the application to connect to the Oracle database and populate user and subject objects.
53+
54+
---
55+
56+
### Launching the App
57+
58+
1. **Open a terminal** in the project root directory.
59+
2. Run the following command: `streamlit run subject_criteria_builder.py`
60+
3. The app will open in your default web browser.
61+
4. You can also copy and paste the `Local URL` into a browser to access the app.
62+
63+
---
64+
65+
### Searching for Criteria
66+
67+
- Use the **search bar** at the top to filter criteria keys by name or description.
68+
- The list updates as you type, showing only matching criteria.
69+
- You can hide or show the search bar and criteria list using the "Hide Criteria/Search" and "Show Criteria/Search" buttons at the top.
70+
71+
---
72+
73+
### Selecting and Configuring a Criterion
74+
75+
1. **Expand a criterion** by clicking the ➕ button next to its name.
76+
2. The expanded section shows:
77+
- **Description:** An explanation of what the key is and what input is expected.
78+
- **Dropdown:** If the key has a set of allowed values (from `criteria.json`), a dropdown will appear for you to select from.
79+
- **Text Input:** You can always enter a custom value, even if a dropdown is present.
80+
3. **Collapse** the criterion by clicking the ✖ button.
81+
82+
---
83+
84+
### User and Subject Dependencies
85+
86+
Some criteria require additional context, such as a User or Subject object.<br>
87+
If you select a criterion that has a dependency on "User" or "Subject" (as defined in `criteria.json`):
88+
89+
- **User Dependency:**
90+
- A section will appear allowing you to select a user from the list defined in `users.json`.
91+
- Once selected, the user's name and username are displayed, and a populated user object is created for use in the SQL query.
92+
93+
- **Subject Dependency:**
94+
- A section will appear allowing you to enter a subject's NHS number.
95+
- Once entered, the application will attempt to populate a subject object using this NHS number for use in the SQL query.
96+
97+
These sections will remain visible as long as any selected criteria require them.
98+
99+
---
100+
101+
### Copying the Criteria
102+
103+
- As you configure criteria, the **Final Criteria Dictionary** at the bottom updates in real time.
104+
- To copy the criteria you can either select the whole code block manually or click on the copy button that is at the top right of this code block.
105+
106+
---
107+
108+
### Resetting the Builder and Hiding Criteria
109+
110+
- Click the **🔄 Reset Criteria Builder** button at the top to clear all selections and start over.
111+
- Use the **🙈 Hide Criteria/Search** and **👁️ Show Criteria/Search** buttons to hide or show the search bar and criteria list.
112+
113+
---
114+
115+
## Maintaining the Application
116+
117+
### Updating `criteria.json`
118+
119+
The file `subject_criteria_builder/criteria.json` defines all available criteria keys, their descriptions, allowed values, and dependencies.
120+
121+
Each entry in the file looks like this:
122+
123+
```json
124+
{
125+
"key": "NHS_NUMBER",
126+
"value_source": "",
127+
"notes": "Enter the 10-digit NHS Number of the subject you want to search for."
128+
}
129+
```
130+
131+
Or, with allowed values and dependencies:
132+
133+
```json
134+
{
135+
"key": "SUBJECT_HUB_CODE",
136+
"value_source": "SubjectHubCode.by_description",
137+
"notes": "Select the hub or organisation for the subject.",
138+
"allowed_values": [
139+
"user's hub",
140+
"user's organisation"
141+
],
142+
"dependencies": [
143+
"User"
144+
]
145+
}
146+
```
147+
148+
- **`key`:** The unique identifier for the criterion (must match the code).
149+
- **`value_source`:** (Optional) The source of the value, can be left blank. This refers to the class + method used in the subject selection query builder. This is not used by the code but is there to allow easier tracking/mapping.
150+
- **`notes`:** A clear, user-focused description of what the key is and what the user should input.
151+
- **`allowed_values`:** (Optional) An array of allowed values for the dropdown selection.
152+
- **`dependencies`:** (Optional) An array that can include `"User"` and/or `"Subject"`. If present, the app will prompt for a user selection or subject NHS number as needed.
153+
154+
#### To add a new criterion
155+
156+
1. Add a new object to the JSON array with the following fields:
157+
- `"key"`: The `Enum` member name (must match the code).
158+
- `"value_source"`: (Optional) The value source, can be left blank.
159+
- `"notes"`: A clear, user-focused description of what the key is and what the user should input.
160+
- `"allowed_values"`: (Optional) An array of allowed values for the dropdown selection.
161+
- `"dependencies"`: (Optional) An array containing `"User"` and/or `"Subject"` if the criterion requires additional context.
162+
163+
2. Save the file. The app will automatically pick up the new key on reload.
164+
165+
#### To edit a criterion
166+
167+
- Find the object with the matching `"key"` and update the `"notes"`, `"allowed_values"`, or `"dependencies"` as needed.
168+
- Save the file and reload the app.
169+
170+
#### To remove a criterion
171+
172+
- Delete the object from the JSON array.
173+
- Save the file and reload the app.
174+
175+
#### About the `dependencies` field
176+
177+
- If a criterion requires a User or Subject context, add a `"dependencies"` array to its entry, e.g.:
178+
179+
```json
180+
"dependencies": ["User"]
181+
```
182+
183+
or
184+
185+
```json
186+
"dependencies": ["Subject"]
187+
```
188+
189+
or both:
190+
191+
```json
192+
"dependencies": ["User", "Subject"]
193+
```
194+
195+
- The application will automatically show the relevant input sections when any selected criteria require these dependencies.
196+
197+
---
198+
199+
### Adding New Criteria Keys
200+
201+
If you add new keys to the `SubjectSelectionCriteriaKey` `Enum` in your code, you should also add a corresponding entry in `criteria.json` with a description (`notes`), and (optionally) allowed values and dependencies.
202+
203+
---
204+
205+
### Editing Allowed Values or Descriptions
206+
207+
- **Allowed Values:** Update the `"allowed_values"` array for any key to change the dropdown options shown to users.
208+
- **Descriptions:** Update the `"notes"` field to clarify what the key is for or what input is expected.
209+
- **Dependencies:** Update the `"dependencies"` array to control when the app prompts for user or subject context.
210+
211+
---
212+
213+
### Troubleshooting
214+
215+
- **A key does not appear in the UI:**
216+
Ensure it exists in both the `SubjectSelectionCriteriaKey` `Enum` and in `criteria.json`.
217+
218+
- **Dropdown is missing for a key:**
219+
Add or update the `"allowed_values"` array for that key in `criteria.json`.
220+
221+
- **Descriptions are unclear or missing:**
222+
Update the `"notes"` field for the relevant key in `criteria.json`.
223+
224+
- **App does not reload changes:**
225+
Save your changes and refresh the `Streamlit` app in your browser.
226+
227+
- **Copy to clipboard does not work:**
228+
Some browsers may not support auto-copy. Manually select and copy the JSON from the code block.
229+
230+
- **Oracle DB errors:**
231+
Ensure your `local.env` file is present and contains valid values for `ORACLE_USERNAME`, `ORACLE_DB`, and `ORACLE_PASS`.
232+
233+
---
234+
235+
## Example Entry in `criteria.json`
236+
237+
```json
238+
{
239+
"key": "SCREENING_STATUS",
240+
"value_source": "ScreeningStatusType.by_description_case_insensitive",
241+
"notes": "Select the current screening status for the subject.",
242+
"allowed_values": [
243+
"Call",
244+
"Inactive",
245+
"Opt-in",
246+
"Recall",
247+
"Self-referral",
248+
"Surveillance",
249+
"Ceased"
250+
],
251+
"dependencies": ["Subject"]
252+
}
253+
```
254+
255+
---
256+
257+
## Summary
258+
259+
- **All configuration is driven by `criteria.json`.**
260+
- **Descriptions, allowed values, and dependencies are fully customizable.**
261+
- **No code changes are needed for most updates—just edit the JSON file.**
262+
- **For new `Enum` keys, add them to both the `SubjectSelectionCriteriaKey` `Enum` and the JSON.**
263+
- **For criteria that require user or subject context, use the `dependencies` field.**

0 commit comments

Comments
 (0)