Skip to content

Commit 9fd9aba

Browse files
Addressing feedback comments from reviews (#90)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description <!-- Describe your changes in detail. --> Changing the markdown comment to address feedback given during reviews. ## Context <!-- Why is this change required? What problem does it solve? --> Makes it easier to understand when and how to use the utility. ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [x] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md) - [x] I have followed the code style of the project - [ ] I have added tests to cover my changes (where appropriate) - [x] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.
1 parent 3da25d0 commit 9fd9aba

File tree

1 file changed

+65
-31
lines changed

1 file changed

+65
-31
lines changed

docs/utility-guides/UserTools.md

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Utility Guide: User Tools
22

3-
The User Tools utility provided by this blueprint allows for the easy management of test users via a json file included
3+
The User Tools utility provided by this blueprint allows for the easy management of test users via a `users.json` file included
44
at the base of the repository.
55

66
## Table of Contents
@@ -10,56 +10,85 @@ at the base of the repository.
1010
- [Using the User Tools class](#using-the-user-tools-class)
1111
- [Managing Users](#managing-users)
1212
- [Considering Security](#considering-security)
13-
- [`retrieve_user()`: Retrieve User Details](#retrieve_user-retrieve-user-details)
13+
- [`user_login()`: Log In as a User](#user_login-log-in-as-a-user)
1414
- [Required Arguments](#required-arguments)
15-
- [Returns](#returns)
1615
- [Example Usage](#example-usage)
16+
- [`retrieve_user()`: Retrieve User Details](#retrieve_user-retrieve-user-details)
17+
- [Required Arguments](#required-arguments-1)
18+
- [Returns](#returns)
19+
- [Example Usage](#example-usage-1)
1720

1821
## Using the User Tools class
1922

20-
You can initialise the User Tools class by using the following code in your test file:
23+
You can use the User Tools class by importing it in your test file:
2124

22-
from utils.user_tools import UserTools
25+
```python
26+
from utils.user_tools import UserTools
27+
```
2328

2429
This module has been designed as a static class, so you do not need to instantiate it when you want to retrieve any user information.
2530

2631
## Managing Users
2732

28-
For this class, users are managed via the [users.json](../../users.json) file provided with this repository. For any new users you need to
29-
add, the idea is to just add a new record, with any appropriate metadata you need for the user whilst they interact with your application.
33+
For this class, users are managed via the [`users.json`](../../users.json) file provided with this repository. For any new users you need to add, simply add a new record with any appropriate metadata you need for the user whilst they interact with your application.
3034

3135
For example, adding a record like so (this example shows the entire `users.json` file):
3236

33-
{
34-
"Documentation User": {
35-
"username": "DOC_USER",
36-
"roles": ["Example Role A"],
37-
"unique_id": 42
38-
}
39-
}
40-
41-
The data you require for these users can be completely customised for what information you need, so whilst the example shows `username`, `roles`
42-
and `unique_id` as possible values we may want to use, this is not an exhaustive list. The key that is used (so in this example, `"Documentation User"`)
43-
is also customisable and should be how you want to easily reference retrieving this user in your tests.
37+
```json
38+
{
39+
"Hub Manager State Registered at BCS01": {
40+
"username": "BCSS401",
41+
"roles": [
42+
"Hub Manager State Registered, Midlands and North West"
43+
]
44+
}
45+
}
46+
```
4447

4548
### Considering Security
4649

47-
An important note on managing users in this way is that passwords or security credentials should **never** be stored in the `users.json` file. These
48-
are considered secrets, and whilst it may be convenient to store them in this file, it goes against the
50+
An important note on managing users in this way is that passwords or security credentials should **never** be stored in the `users.json` file. These are considered secrets, and whilst it may be convenient to store them in this file, it goes against the
4951
[security principles outlined in the Software Engineering Quality Framework](https://github.com/NHSDigital/software-engineering-quality-framework/blob/main/practices/security.md#application-level-security).
5052

5153
With this in mind, it's recommended to do the following when it comes to managing these types of credentials:
5254

53-
- When running locally, store any secret values in a local configuration file and set this file in `.gitignore` so it is not committed to the codebase.
55+
- When running locally, store any secret values in a local configuration file such as `local.env`. This file is created by running the script [`setup_env_file.py`](../../setup_env_file.py) and is included in `.gitignore` so it is not committed to the codebase.
5456
- When running via a CI/CD process, store any secret values in an appropriate secret store and pass the values into pytest at runtime.
5557

58+
## `user_login()`: Log In as a User
59+
60+
The `user_login()` method allows you to log in to the BCSS application as a specified user. It retrieves the username from the `users.json` file and the password from the `local.env` file (using the `BCSS_PASS` environment variable).
61+
62+
### Required Arguments
63+
64+
| Argument | Format | Description |
65+
|-----------|--------|--------------------------------------------------------------------|
66+
| page | `Page` | The Playwright page object to interact with. |
67+
| username | `str` | The key from `users.json` for the user you want to log in as. |
68+
69+
### Example Usage
70+
71+
```python
72+
from utils.user_tools import UserTools
73+
74+
def test_login_as_user(page):
75+
UserTools.user_login(page, "Hub Manager State Registered at BCS01")
76+
```
77+
78+
> **Note:**
79+
> Ensure you have set the `BCSS_PASS` environment variable in your `local.env` file (created by running `setup_env_file.py`) before using this method.
80+
81+
---
82+
5683
## `retrieve_user()`: Retrieve User Details
5784

5885
The `retrieve_user()` method is designed to easily retrieve the data for a specific user entry from the `users.json` file. This is a static method,
5986
so can be called using the following logic:
6087

61-
# Retrieving documentation user details from example
62-
user_details = UserTools.retrieve_user("Documentation User")
88+
```python
89+
# Retrieving documentation user details from example
90+
user_details = UserTools.retrieve_user("Hub Manager State Registered at BCS01")
91+
```
6392

6493
### Required Arguments
6594

@@ -77,13 +106,18 @@ A Python `dict` object that contains the values associated with the provided use
77106

78107
When using a `users.json` file as set up in the example above:
79108

80-
from utils.user_tools import UserTools
81-
from playwright.sync_api import Page
109+
```python
110+
from utils.user_tools import UserTools
111+
from playwright.sync_api import Page
112+
113+
def test_login(page: Page) -> None:
114+
# Retrieving documentation user details from example
115+
user_details = UserTools.retrieve_user("Hub Manager State Registered at BCS01")
116+
117+
# Use values to populate a form
118+
page.get_by_role("textbox", name="Username").fill(user_details["username"])
119+
```
82120

83-
def test_login(page: Page) -> None:
84-
# Retrieving documentation user details from example
85-
user_details = UserTools.retrieve_user("Documentation User")
121+
---
86122

87-
# Use values to populate a form
88-
page.get_by_role("textbox", name="Username").fill(user_details["username"])
89-
page.get_by_role("textbox", name="ID").fill(user_details["unique_id"])
123+
For more details on each function's implementation, refer to the source code in `utils/user_tools.py`.

0 commit comments

Comments
 (0)