Skip to content

Commit fe90a9e

Browse files
Transfer of prototype code (#1)
This transfers the prototype code that is generic into this project ready to be built upon.
1 parent 458a188 commit fe90a9e

File tree

11 files changed

+100
-11
lines changed

11 files changed

+100
-11
lines changed

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
# Repository Template
1+
# Playwright Python Blueprint
22

33
[![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/repository-template/actions/workflows/cicd-1-pull-request.yaml)
44
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=repository-template&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=repository-template)
55

6-
Start with an overview or a brief description of what the project is about and what it does. For example -
6+
This project is designed to provide a blueprint to allow for development teams to start quickly developing UI tests using [Playwright Python](https://playwright.dev/python/), providing the base framework and utilities to allow for initial focus on writing tests, rather than configuration of the framework itself.
77

8-
Welcome to our repository template designed to streamline your project setup! This robust template provides a reliable starting point for your new projects, covering an essential tech stack and encouraging best practices in documenting.
9-
10-
This repository template aims to foster a user-friendly development environment by ensuring that every included file is concise and adequately self-documented. By adhering to this standard, we can promote increased clarity and maintainability throughout your project's lifecycle. Bundled within this template are resources that pave the way for seamless repository creation. Currently supported technologies are:
11-
12-
- Terraform
13-
- Docker
14-
15-
Make use of this repository template to expedite your project setup and enhance your productivity right from the get-go. Enjoy the advantage of having a well-structured, self-documented project that reduces overhead and increases focus on what truly matters - coding!
8+
NOTE: This project is currently under initial development.
169

1710
## Table of Contents
1811

19-
- [Repository Template](#repository-template)
12+
- [Playwright Python Blueprint](#playwright-python-blueprint)
2013
- [Table of Contents](#table-of-contents)
2114
- [Setup](#setup)
2215
- [Prerequisites](#prerequisites)

blueprint/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__pycache__/
2+
.pytest_cache/
3+
test-results/

blueprint/buildBase.dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /test
4+
5+
# Install dependencies
6+
COPY ./requirements.txt ./requirements.txt
7+
RUN pip install --no-cache-dir -r requirements.txt
8+
RUN playwright install --with-deps
9+
RUN playwright install chrome
10+
11+
RUN mkdir -p /tests/
12+
COPY ./tests/ ./tests/
13+
RUN mkdir -p /utils/
14+
COPY ./utils/ ./utils/
15+
COPY ./pytest.ini ./pytest.ini
16+
COPY ./run_tests.sh ./run_tests.sh

blueprint/pytest.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[pytest]
2+
log_cli = True
3+
log_cli_level = INFO
4+
addopts =
5+
--html=test-results/report.html
6+
--self-contained-html
7+
--json-report
8+
--json-report-file=test-results/results.json
9+
--json-report-omit=collectors
10+
markers =
11+
subjects: tests for subject-based scenarios
12+
branch: tests designed to run at a branch level
13+
main: tests designed to run against the main branch
14+
release: tests designed to run specifically against a release branch

blueprint/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest-playwright>=0.5.1
2+
pytest-html>=4.1.1
3+
pytest-json-report>=1.5.0

blueprint/run_tests.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
BASE_URL=${1:-${BASE_URL}}
4+
5+
pytest --tracing retain-on-failure --base-url $1

blueprint/tests/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Add tests here
2+
3+
Your projects test files should be added to this directory.

blueprint/tests/test_example.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file provides a very basic test to confirm the configuration is working
2+
3+
from playwright.sync_api import Page, expect
4+
5+
6+
def test_basic_example(page: Page):
7+
# Navigate to page
8+
page.goto("https://github.com/nhs-england-tools/playwright-python-blueprint")
9+
10+
# Assert repo text is present
11+
expect(page.get_by_role("article")).to_contain_text("Playwright Python Blueprint")
12+
13+
# Click license link
14+
page.get_by_role("link", name="MIT license").click()
15+
16+
# Assert license text
17+
expect(page.get_by_role("article")).to_contain_text("MIT Licence")

blueprint/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from nhs_number_tools import NHSNumberTools
2+
__all__ = [NHSNumberTools]

blueprint/utils/nhs_number_tools.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import logging
2+
logger = logging.getLogger(__name__)
3+
4+
class NHSNumberTools:
5+
"""
6+
A utility class providing functionality around NHS numbers.
7+
"""
8+
def _nhs_number_checks(self, nhs_number: str) -> None:
9+
"""
10+
This does basic checks on NHS number values provided and outputs information or exceptions if applicable.
11+
12+
Args:
13+
nhs_number (str): The NHS number to check.
14+
"""
15+
if not nhs_number.isnumeric():
16+
raise Exception("The NHS number provided ({}) is not numeric.".format(nhs_number))
17+
18+
19+
def spaced_nhs_number(self, nhs_number: int | str) -> str:
20+
"""
21+
This will space out a provided NHS number in the format nnn nnn nnnn.
22+
23+
Args:
24+
nhs_number (int | str): The NHS number to space out.
25+
26+
Returns:
27+
str: The NHS number in "nnn nnn nnnn" format.
28+
"""
29+
self._nhs_number_checks(str(nhs_number))
30+
return "{} {} {}".format(str(nhs_number)[:3], str(nhs_number)[3:6], str(nhs_number)[6:])

0 commit comments

Comments
 (0)