Skip to content

Commit 73170fe

Browse files
AC - added test to update phone number to test db update
1 parent 81bcac2 commit 73170fe

File tree

7 files changed

+147
-14
lines changed

7 files changed

+147
-14
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ This will take a while and will install playwright and its browsers which allow
5959

6060
### Configuration
6161

62+
To use these tests you will need to supply some environmental variables, the easiest way to do that is to create a file called `.env` in the root directory
63+
64+
inside that file you will need to provide the following information:
65+
66+
```bash
67+
PYTEST_BASE_URL="https://example.com/"
68+
69+
BCSS_USERNAME="MyUser"
70+
BCSS_PASSWORD="ChangeMe"
71+
```
72+
73+
Once those details have been filled in then
74+
6275
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`
6376

6477
There is also a dockerised version which will create a container using podman and run it there, if you dont have a compatible OS or you dont want to install the dependancies directly, however you will need to install podman and podman-build, you can run that with `podman-test`

pages/bcss_home_page.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, page: Page):
2626
self.screening_pracitioners_appointments = self.page.get_by_role(
2727
"link", name="Screening Practitioner Appointments"
2828
)
29+
self.contacts_list = self.page.get_by_role("link", name="Contacts List")
2930

3031
def click_sub_menu_link(self):
3132
self.sub_menu_link.click()
@@ -54,5 +55,8 @@ def click_help_link(self):
5455
def click_screening_pracitioners_appointments(self):
5556
self.screening_pracitioners_appointments.click()
5657

58+
def click_contacts_list(self):
59+
self.contacts_list.click()
60+
5761
def click_logout(self):
5862
self.log_out.click()

pages/contacts_list.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from playwright.sync_api import Page
2+
3+
4+
class ContactsList:
5+
6+
def __init__(self, page: Page):
7+
self.page = page
8+
9+
# Main Menu
10+
self.view_contacts = self.page.get_by_role("link", name="View Contacts")
11+
self.edit_my_contact_details = self.page.get_by_role(
12+
"link", name="Edit My Contact Details"
13+
)
14+
self.maintain_contacts = self.page.get_by_role("link", name="Maintain Contacts")
15+
self.my_preference_settings = self.page.get_by_role(
16+
"link", name="My Preference Settings"
17+
)
18+
self.extract_contact_details = self.page.get_by_role(
19+
"link", name="Extract Contact Details"
20+
)
21+
self.resect_and_discard_accredited_endoscopists = self.page.get_by_role(
22+
"link", name="Resect and Discard Accredited Endoscopists"
23+
)
24+
25+
def click_view_contacts(self):
26+
self.view_contacts.click()
27+
28+
def click_edit_my_contact_details(self):
29+
self.edit_my_contact_details.click()
30+
31+
def click_maintain_contacts(self):
32+
self.maintain_contacts.click()
33+
34+
def click_my_preference_settings(self):
35+
self.my_preference_settings.click()
36+
37+
def click_extract_contact_details(self):
38+
self.extract_contact_details.click()
39+
40+
def click_resect_and_discard_accredited_endoscopists(self):
41+
self.resect_and_discard_accredited_endoscopists.click()

pytest.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ pythonpath = .
2020

2121
# Seting for the retry plugin
2222
# timeout is in seconds and effects each individual test, not the entire run
23-
timeout = 60
23+
timeout = 120
2424
# How many times to retry a failed test before classifying it as failed
25-
retries = 3
25+
retries = 5
2626
# number of seconds between each retry
27-
retry_delay = 1
27+
retry_delay = 2
2828
# If you want to add together all of the time for the re-tried and successful
2929
# tests then set this to true.
3030
cumulative_timing = false

tests/test_contacts_list.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from gc import get_count
2+
from os import environ
3+
import random
4+
import re
5+
import pytest
6+
import logging
7+
from playwright.sync_api import Page, expect
8+
from pages.login import BcssLoginPage
9+
from pages.bcss_home_page import BcssHomePage
10+
from pages.contacts_list import ContactsList
11+
from dotenv import load_dotenv
12+
13+
load_dotenv()
14+
logger = logging.getLogger(__name__)
15+
expect.set_options(timeout=20_000)
16+
17+
18+
@pytest.fixture(scope="function", autouse=True)
19+
def before_each(page: Page):
20+
username = environ.get("BCSS_USERNAME")
21+
password = environ.get("BCSS_PASSWORD")
22+
login_page = BcssLoginPage(page)
23+
login_page.login(username, password)
24+
25+
26+
def get_to_screen(page: Page):
27+
homepage = BcssHomePage(page)
28+
expect(
29+
page.get_by_role("link", name="Screening Practitioner Appointments")
30+
).to_be_visible()
31+
homepage.click_contacts_list()
32+
page.screenshot(path="test-results/contacts_list/select_org_screen.png")
33+
expect(page.get_by_text("Contacts List")).to_be_visible()
34+
35+
36+
def test_view_contacts(page: Page):
37+
get_to_screen(page)
38+
contacts_list = ContactsList(page)
39+
contacts_list.click_view_contacts()
40+
page.screenshot(path="test-results/contacts_list/contacts_list.png")
41+
expect(page.get_by_text("View Contacts")).to_be_visible()
42+
43+
44+
def test_edit_my_contact_details(page: Page):
45+
get_to_screen(page)
46+
contacts_list = ContactsList(page)
47+
contacts_list.click_edit_my_contact_details()
48+
expect(page.get_by_text("Edit My Contact Details")).to_be_visible()
49+
expect(page.get_by_text("Telephone")).to_be_visible()
50+
test_number = generate_phone_number()
51+
page.locator("[name='A_C_TELEPHONE_NUMBER']").fill(test_number)
52+
page.get_by_text("Save").click()
53+
expect(page.get_by_text(test_number)).to_be_visible()
54+
page.screenshot(path="test-results/contacts_list/updated_number_save_clicked.png")
55+
expect(page.get_by_text("The action was performed successfully")).to_be_visible()
56+
57+
58+
def generate_phone_number():
59+
# Generate 2 digits for first part
60+
first_part = "".join(str(random.randint(0, 9)) for _ in range(2))
61+
# Generate 2 digits for second part
62+
second_part = "".join(str(random.randint(0, 9)) for _ in range(2))
63+
# Generate 4 digits for third part
64+
third_part = "".join(str(random.randint(0, 9)) for _ in range(4))
65+
66+
# Join them together to make the number and assert its correct and return it
67+
phone_number = f"{first_part} {second_part} {third_part}"
68+
assert re.fullmatch(
69+
r"\d{2}\s\d{2}\s\d{4}", phone_number
70+
), f"Phone number '{phone_number}' does not match expected format 'XX XX XXXX'"
71+
72+
return phone_number

tests/test_homepage_links.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def test_homepage_sub_menu(page: Page) -> None:
2323

2424
# Check the show and hide sub menu works
2525
homepage.click_sub_menu_link()
26-
page.screenshot(path="test-results/sub_menu_screen.png")
26+
page.screenshot(path="test-results/homepage/sub_menu_screen.png")
2727
expect(page.get_by_role("link", name="Organisation Parameters")).to_be_visible()
2828
homepage.click_hide_sub_menu_link()
29-
page.screenshot(path="test-results/menu_screen.png")
29+
page.screenshot(path="test-results/homepage/menu_screen.png")
3030
expect(page.get_by_role("cell", name="Alerts", exact=True)).to_be_visible()
3131

3232

@@ -35,7 +35,7 @@ def test_homepage_select_org(page: Page) -> None:
3535

3636
# check the select org link works
3737
homepage.click_select_org_link()
38-
page.screenshot(path="test-results/select_org_screen.png")
38+
page.screenshot(path="test-results/homepage/select_org_screen.png")
3939
expect(page.locator("form[action*='/changeorg']")).to_contain_text(
4040
"Choose an Organisation"
4141
)
@@ -53,7 +53,7 @@ def test_homepage_release_notes(page: Page) -> None:
5353

5454
# Click release notes link
5555
homepage.click_release_notes_link()
56-
page.screenshot(path="test-results/release_notes_screen.png")
56+
page.screenshot(path="test-results/homepage/release_notes_screen.png")
5757
expect(page.locator("#page-title")).to_contain_text("Release Notes")
5858

5959

@@ -64,7 +64,7 @@ def test_homepage_help(page: Page) -> None:
6464
with page.expect_popup() as popup_info:
6565
homepage.click_help_link()
6666
help_page = popup_info.value
67-
help_page.screenshot(path="test-results/help_screen.png")
67+
help_page.screenshot(path="test-results/homepage/help_screen.png")
6868
expect(
6969
help_page.get_by_text("Bowel Cancer Screening System Help")
7070
).to_be_visible
@@ -76,14 +76,12 @@ def test_homepage_user_guide(page: Page) -> None:
7676
# check the user guide works
7777
with page.expect_popup() as popup_info:
7878
homepage.click_user_guide_link()
79-
# homepage.screenshot(path="test-results/help_screen.png")
8079
user_guide = popup_info.value
81-
# user_guide.screenshot(path="test-results/help_screen.png")
8280
expect(user_guide.get_by_text("Bowel Cancer Screening System"))
8381

8482

8583
def test_logout(page: Page) -> None:
8684
homepage = BcssHomePage(page)
8785
homepage.click_logout()
88-
page.screenshot(path="test-results/logout_screen.png")
86+
page.screenshot(path="test-results/homepage/logout_screen.png")
8987
expect(page.get_by_role("link", name="Log in"))

tests/test_screening_practitioner_appointments.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def get_to_screen(page: Page):
2929
page.get_by_role("link", name="Screening Practitioner Appointments")
3030
).to_be_visible()
3131
homepage.click_screening_pracitioners_appointments()
32-
expect(page.get_by_role("link", name="View appointments")).to_be_visible()
32+
expect(page.get_by_text("Screening Practitioner Appointments")).to_be_visible()
33+
page.screenshot(path="test-results/screening/main_screen.png")
3334

3435

3536
def test_view_appointments(page: Page) -> None:
@@ -42,16 +43,20 @@ def test_view_appointments(page: Page) -> None:
4243
expect(page.get_by_text("Screening Practitioner Day View")).to_be_visible()
4344
table_locator = page.locator("table#displayRS tbody tr")
4445
row_count = table_locator.count()
46+
page.screenshot(path="test-results/screening/view_appointments.png")
4547
assert row_count > 0
4648

4749

4850
def test_patients_that_require_colonoscopy_assessment_appointments(page: Page) -> None:
4951
get_to_screen(page)
50-
screening_pracitioners_appointments = ScreeningPractitionerAppointments(page)
51-
screening_pracitioners_appointments.click_patients_that_require_colonoscopy_assessment_appointments()
52+
page.locator("#menuOp2").click()
53+
page.screenshot(path="test-results/screening/patients_requiring_appointments.png")
5254
expect(
5355
page.get_by_text("Patients that Require Colonoscopy Assessment Appointments")
5456
).to_be_visible()
57+
58+
page.screenshot(path="test-results/screening/patients_requiring_appointments.png")
5559
table_locator = page.locator("table#booking tbody tr")
5660
child_count = table_locator.count()
61+
5762
assert child_count > 0

0 commit comments

Comments
 (0)