Skip to content

Commit

Permalink
Transfer of prototype code (#1)
Browse files Browse the repository at this point in the history
This transfers the prototype code that is generic into this project ready to be built upon.
  • Loading branch information
davethepunkyone authored Oct 3, 2024
1 parent 458a188 commit fe90a9e
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 11 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
# Repository Template
# Playwright Python Blueprint

[![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)
[![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)

Start with an overview or a brief description of what the project is about and what it does. For example -
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.

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.

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:

- Terraform
- Docker

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!
NOTE: This project is currently under initial development.

## Table of Contents

- [Repository Template](#repository-template)
- [Playwright Python Blueprint](#playwright-python-blueprint)
- [Table of Contents](#table-of-contents)
- [Setup](#setup)
- [Prerequisites](#prerequisites)
Expand Down
3 changes: 3 additions & 0 deletions blueprint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
.pytest_cache/
test-results/
16 changes: 16 additions & 0 deletions blueprint/buildBase.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.12-slim

WORKDIR /test

# Install dependencies
COPY ./requirements.txt ./requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
RUN playwright install --with-deps
RUN playwright install chrome

RUN mkdir -p /tests/
COPY ./tests/ ./tests/
RUN mkdir -p /utils/
COPY ./utils/ ./utils/
COPY ./pytest.ini ./pytest.ini
COPY ./run_tests.sh ./run_tests.sh
14 changes: 14 additions & 0 deletions blueprint/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[pytest]
log_cli = True
log_cli_level = INFO
addopts =
--html=test-results/report.html
--self-contained-html
--json-report
--json-report-file=test-results/results.json
--json-report-omit=collectors
markers =
subjects: tests for subject-based scenarios
branch: tests designed to run at a branch level
main: tests designed to run against the main branch
release: tests designed to run specifically against a release branch
3 changes: 3 additions & 0 deletions blueprint/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest-playwright>=0.5.1
pytest-html>=4.1.1
pytest-json-report>=1.5.0
5 changes: 5 additions & 0 deletions blueprint/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

BASE_URL=${1:-${BASE_URL}}

pytest --tracing retain-on-failure --base-url $1
3 changes: 3 additions & 0 deletions blueprint/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Add tests here

Your projects test files should be added to this directory.
17 changes: 17 additions & 0 deletions blueprint/tests/test_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file provides a very basic test to confirm the configuration is working

from playwright.sync_api import Page, expect


def test_basic_example(page: Page):
# Navigate to page
page.goto("https://github.com/nhs-england-tools/playwright-python-blueprint")

# Assert repo text is present
expect(page.get_by_role("article")).to_contain_text("Playwright Python Blueprint")

# Click license link
page.get_by_role("link", name="MIT license").click()

# Assert license text
expect(page.get_by_role("article")).to_contain_text("MIT Licence")
2 changes: 2 additions & 0 deletions blueprint/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from nhs_number_tools import NHSNumberTools
__all__ = [NHSNumberTools]
30 changes: 30 additions & 0 deletions blueprint/utils/nhs_number_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import logging
logger = logging.getLogger(__name__)

class NHSNumberTools:
"""
A utility class providing functionality around NHS numbers.
"""
def _nhs_number_checks(self, nhs_number: str) -> None:
"""
This does basic checks on NHS number values provided and outputs information or exceptions if applicable.
Args:
nhs_number (str): The NHS number to check.
"""
if not nhs_number.isnumeric():
raise Exception("The NHS number provided ({}) is not numeric.".format(nhs_number))


def spaced_nhs_number(self, nhs_number: int | str) -> str:
"""
This will space out a provided NHS number in the format nnn nnn nnnn.
Args:
nhs_number (int | str): The NHS number to space out.
Returns:
str: The NHS number in "nnn nnn nnnn" format.
"""
self._nhs_number_checks(str(nhs_number))
return "{} {} {}".format(str(nhs_number)[:3], str(nhs_number)[3:6], str(nhs_number)[6:])
3 changes: 3 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributing to this project

This page will be populated in the near future to outline the contribution process.

0 comments on commit fe90a9e

Please sign in to comment.