From fe90a9ee7cac1436d3292b35aba6ef4b08d93e33 Mon Sep 17 00:00:00 2001 From: davethepunkyone <35965578+davethepunkyone@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:52:18 +0100 Subject: [PATCH] Transfer of prototype code (#1) This transfers the prototype code that is generic into this project ready to be built upon. --- README.md | 15 ++++----------- blueprint/.gitignore | 3 +++ blueprint/buildBase.dockerfile | 16 +++++++++++++++ blueprint/pytest.ini | 14 ++++++++++++++ blueprint/requirements.txt | 3 +++ blueprint/run_tests.sh | 5 +++++ blueprint/tests/README.md | 3 +++ blueprint/tests/test_example.py | 17 ++++++++++++++++ blueprint/utils/__init__.py | 2 ++ blueprint/utils/nhs_number_tools.py | 30 +++++++++++++++++++++++++++++ docs/CONTRIBUTING.md | 3 +++ 11 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 blueprint/.gitignore create mode 100644 blueprint/buildBase.dockerfile create mode 100644 blueprint/pytest.ini create mode 100644 blueprint/requirements.txt create mode 100644 blueprint/run_tests.sh create mode 100644 blueprint/tests/README.md create mode 100644 blueprint/tests/test_example.py create mode 100644 blueprint/utils/__init__.py create mode 100644 blueprint/utils/nhs_number_tools.py create mode 100644 docs/CONTRIBUTING.md diff --git a/README.md b/README.md index 7008e9c..1cf76ac 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/blueprint/.gitignore b/blueprint/.gitignore new file mode 100644 index 0000000..888cb74 --- /dev/null +++ b/blueprint/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +.pytest_cache/ +test-results/ diff --git a/blueprint/buildBase.dockerfile b/blueprint/buildBase.dockerfile new file mode 100644 index 0000000..46981cd --- /dev/null +++ b/blueprint/buildBase.dockerfile @@ -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 diff --git a/blueprint/pytest.ini b/blueprint/pytest.ini new file mode 100644 index 0000000..8fdba90 --- /dev/null +++ b/blueprint/pytest.ini @@ -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 diff --git a/blueprint/requirements.txt b/blueprint/requirements.txt new file mode 100644 index 0000000..c4ebc37 --- /dev/null +++ b/blueprint/requirements.txt @@ -0,0 +1,3 @@ +pytest-playwright>=0.5.1 +pytest-html>=4.1.1 +pytest-json-report>=1.5.0 diff --git a/blueprint/run_tests.sh b/blueprint/run_tests.sh new file mode 100644 index 0000000..e545a3f --- /dev/null +++ b/blueprint/run_tests.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +BASE_URL=${1:-${BASE_URL}} + +pytest --tracing retain-on-failure --base-url $1 diff --git a/blueprint/tests/README.md b/blueprint/tests/README.md new file mode 100644 index 0000000..d5e88ee --- /dev/null +++ b/blueprint/tests/README.md @@ -0,0 +1,3 @@ +# Add tests here + +Your projects test files should be added to this directory. diff --git a/blueprint/tests/test_example.py b/blueprint/tests/test_example.py new file mode 100644 index 0000000..b75df01 --- /dev/null +++ b/blueprint/tests/test_example.py @@ -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") diff --git a/blueprint/utils/__init__.py b/blueprint/utils/__init__.py new file mode 100644 index 0000000..e172960 --- /dev/null +++ b/blueprint/utils/__init__.py @@ -0,0 +1,2 @@ +from nhs_number_tools import NHSNumberTools +__all__ = [NHSNumberTools] diff --git a/blueprint/utils/nhs_number_tools.py b/blueprint/utils/nhs_number_tools.py new file mode 100644 index 0000000..2a4ed18 --- /dev/null +++ b/blueprint/utils/nhs_number_tools.py @@ -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:]) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md new file mode 100644 index 0000000..83618d4 --- /dev/null +++ b/docs/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# Contributing to this project + +This page will be populated in the near future to outline the contribution process.