Skip to content

Commit 731f484

Browse files
AC - got basic login test working
1 parent 0072e06 commit 731f484

File tree

10 files changed

+124
-8
lines changed

10 files changed

+124
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
__pycache__/
1616
.pytest_cache/
1717
test-results/
18+
.env
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ RUN mkdir -p /tests/
1212
COPY ./tests/ ./tests/
1313
RUN mkdir -p /utils/
1414
COPY ./utils/ ./utils/
15+
RUN mkdir -p /pages/
16+
COPY ./pages ./pages
1517
COPY ./pytest.ini ./pytest.ini
1618
COPY ./run_tests.sh ./run_tests.sh
19+
COPY ./.env ./.env
1720

1821
RUN chmod +x ./run_tests.sh
22+
CMD bash run_tests.sh

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ include scripts/init.mk
77

88
# Example CI/CD targets are: dependencies, build, publish, deploy, clean, etc.
99

10+
test: # run tests in a local podman container
11+
if podman inspect -f '{{.Name}}' playwright > /dev/null; then
12+
podman rm playwright --force
13+
fi
14+
podman build -t bcss-playwright:latest .
15+
podman run --name playwright bcss-playwright:latest
16+
podman logs -f playwright
17+
1018
dependencies: # Install dependencies needed to build and test the project @Pipeline
1119
# TODO: Implement installation of your project dependencies
1220

1321
build: # Build the project artefact @Pipeline
14-
# TODO: Implement the artefact build step
22+
podman build -t bcss-playwright:latest .
1523

1624
publish: # Publish the project artefact @Pipeline
1725
# TODO: Implement the artefact publishing step

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This project is designed to provide a blueprint to allow for development teams t
66

77
NOTE: This project is currently under initial development so isn't finalised, but should work if you want to experiment with Playwright Python.
88

9-
> **NOTE: When considering this project, please be advised that currently Playwright is a "proposed" tool within the [NHS England Tech Radar](https://radar.engineering.england.nhs.uk/). Whilst we are taking steps to get Playwright moved to the "mainstream" section of the radar, as it has not yet been formally adopted it is possible that Playwright may not be fully endorsed by NHS England as a standard tool going forward, and using this framework for an NHS England project is currently at your own risk.**
9+
> **NOTE: When considering this project, please be advised that currently Playwright is a "proposed" tool within the [NHS England Tech Radar](https://radar.engineering.england.nhs.uk/). Whilst we are taking steps to get Playwright moved to the "mainstream" section of the radar, as it has not yet been formally adopted it is possible that Playwright may not be fully endorsed by NHS England as a standard tool going forward, and using this framework for an NHS England project is currently at your own risk.**
1010
1111
## Table of Contents
1212

@@ -34,18 +34,26 @@ To utilise the blueprint code, you will need to have the following installed:
3434
- [Python](https://www.python.org/downloads/) 3.12 or greater
3535

3636
Whilst not required to get started, you may also want to [configure a Python virtual environment for your project](https://docs.python.org/3/library/venv.html) before proceeding with
37-
the configuration. If you are using an IDE such as Visual Studio Code or PyCharm, you will normally be prompted to do this automatically.
37+
the configuration. If you are using an IDE such as Visual Studio Code or PyCharm, you will normally be prompted to do this automatically.
3838

3939
### Configuration
4040

41-
To get started using Playwright and with the examples provided, use the following commands:
41+
There is a makefile which has common commands to interface with the repository, to check if the tests are working you can run the command `make test`
4242

43-
```shell
43+
The first time you run this it will create a container using buildah and podman, it will then install the prerequisites onto it and copy over the code before executing `pytest` to run all the tests. This is the reccomended way to run the tests
44+
45+
If you prefer to run the tests locally you can do so by first assuming the python virtual environment, vscode should pick it up automatically in the `venv` directory but if you are using the terminal on linux or mac you can run `source venv/bin/activate` If you are using windows it may work the same for you or you may need to lookup how to assume a python virtual environment.
46+
47+
Once that is done you can run the following commands to install the prerequisites:
48+
49+
```bash
4450
pip install -r requirements.txt
4551
playwright install --with-deps
4652
```
4753

48-
This will install all the necessary packages for executing Playwright tests, and install Playwright ready for use by the framework. You can test the configuration
54+
> **Note** I found that trying to run this on fedora let to some errors, only Ubuntu seems to be supported which is why I have setup a container using ubuntu to support other environments
55+
56+
This will install all the necessary packages for executing Playwright tests, and install Playwright ready for use by the framework. You can test the configuration
4957
has worked by running our example tests, which can be done using the following command (this will run all tests with tracing reports turned on, and in headed mode
5058
so you can see the browser execution):
5159

pages/bcss_home_page.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from playwright.sync_api import Page
2+
3+
4+
class BcssHomePage:
5+
6+
def __init__(self, page: Page):
7+
self.page = page
8+
self.sub_menu_link = self.page.get_by_role("link", name="Show Sub-menu")
9+
self.hide_sub_menu_link = self.page.get_by_role("link", name="Hide Sub-menu")
10+
self.select_org_link = self.page.get_by_role("link", name="Select Org")
11+
self.back_button = self.page.get_by_role("link", name="Back")
12+
self.release_notes_link = self.page.get_by_role("link", name="- Release Notes")
13+
self.refresh_alerts_link = self.page.get_by_role("link", name="Refresh alerts")
14+
self.user_guide_link = self.page.get_by_role("link", name="User guide")
15+
self.help_link = self.page.get_by_role("link", name="Help")
16+
17+
18+
def click_sub_menu_link(self):
19+
self.sub_menu_link.click()
20+
21+
def click_hide_sub_menu_link(self):
22+
self.hide_sub_menu_link.click()
23+
24+
def click_select_org_link(self):
25+
self.select_org_link.click()
26+
27+
def click_back_button(self):
28+
self.back_button.click()
29+
30+
def click_release_notes_link(self):
31+
self.release_notes_link.click()
32+
33+
def click_refresh_alerts_link(self):
34+
self.refresh_alerts_link.click()
35+
36+
def click_user_guide_link(self):
37+
self.user_guide_link.click()
38+
39+
def click_help_link(self):
40+
self.help_link.click()

pages/login.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from playwright.sync_api import Page, expect
2+
class BcssLoginPage:
3+
4+
def __init__(self, page: Page):
5+
self.page = page
6+
self.page.goto("/")
7+
self.username = page.get_by_role("textbox", name="Username")
8+
self.password = page.get_by_role("textbox", name="Password")
9+
self.submit_button = page.get_by_role("button", name="submit")
10+
11+
12+
def login(self, username, password):
13+
self.username.fill(username)
14+
self.password.fill(password)
15+
self.submit_button.click()

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ markers =
1313
branch: tests designed to run at a branch level
1414
main: tests designed to run against the main branch
1515
release: tests designed to run specifically against a release branch
16+
pythonpath = .

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytest-playwright>=0.5.1
22
pytest-html>=4.1.1
33
pytest-json-report>=1.5.0
4+
python-dotenv>=1.0.1

run_tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

3-
pytest
3+
pytest

tests/test_login_to_bcss.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from os import environ
2+
from playwright.sync_api import Page, expect
3+
from pages.login import BcssLoginPage
4+
from dotenv import load_dotenv
5+
6+
load_dotenv()
7+
8+
def test_successful_login_to_bcss(page: Page) -> None:
9+
username = environ.get("BCSS_USERNAME")
10+
password = environ.get("BCSS_PASSWORD")
11+
login_page = BcssLoginPage(page)
12+
login_page.login(username, password)
13+
expect(page.locator("#ntshAppTitle")).to_contain_text("Bowel Cancer Screening System")
14+
15+
16+
def test_login_to_bcss_with_invalid_username(page: Page) -> None:
17+
username = "zzzzzz"
18+
password = environ.get("BCSS_PASSWORD")
19+
login_page = BcssLoginPage(page)
20+
login_page.login(username, password)
21+
expect(page.locator("body")).to_contain_text("Incorrect username or password.")
22+
23+
24+
def test_login_to_bcss_with_invalid_password(page: Page) -> None:
25+
username = environ.get("BCSS_USERNAME")
26+
password = "zzzzzz"
27+
login_page = BcssLoginPage(page)
28+
login_page.login(username, password)
29+
expect(page.locator("body")).to_contain_text("Incorrect username or password.")
30+
31+
32+
def test_login_to_bcss_with_no_username_or_password(page: Page) -> None:
33+
username = ""
34+
password = ""
35+
login_page = BcssLoginPage(page)
36+
login_page.login(username, password)
37+
# Login should fail - verify that sign in button is still visible
38+
expect(page.get_by_role("button", name="submit")).to_be_visible()

0 commit comments

Comments
 (0)