Skip to content

Commit 38bf420

Browse files
Fixing errors listed by pytest and adding utils to use the book appointments calendar
1 parent ac02ab7 commit 38bf420

File tree

8 files changed

+148
-27
lines changed

8 files changed

+148
-27
lines changed

pages/gfobt_test_kits/gfobt_test_kit_logging_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pages.base_page import BasePage
33

44

5-
class TestKitLogging(BasePage):
5+
class GFOBTTestKitLogging(BasePage):
66
def __init__(self, page: Page):
77
super().__init__(page)
88
self.page = page

pages/gfobt_test_kits/gfobt_test_kit_quality_control_reading_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pages.base_page import BasePage
33

44

5-
class TestKitQualityControlReading(BasePage):
5+
class GFOBTTestKitQualityControlReading(BasePage):
66
def __init__(self, page: Page):
77
super().__init__(page)
88
self.page = page

pages/screening_practitioner_appointments/book_appointment_page.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ def __init__(self, page: Page):
1212
self.site_dropdown = page.locator("#UI_NEW_SITE")
1313
self.day_with_available_slots = page.locator(
1414
'input.twoColumnCalendar[style*="background-color: rgb(102, 255, 153);"]'
15-
).last
15+
)
16+
self.day_with_some_available_slots = page.locator(
17+
'input.twoColumnCalendar[style*="background-color: rgb(255, 220, 144);"]'
18+
)
1619
self.appointment_time_radio_button = page.locator(
1720
page.get_by_role("radio", name="UI_NEW_SLOT_SELECTION_ID")
1821
)
1922
self.save_button = page.get_by_role("button", name="Save")
2023
self.appointments_table = TableUtils(self.page, "#displayRS")
24+
self.current_month_displayed = self.page.locator("#MONTH_AND_YEAR")
2125

2226
def select_screening_centre_dropdown_option(self, screening_centre: str) -> None:
2327
self.screening_center_dropdown.select_option(label=screening_centre)
@@ -37,3 +41,9 @@ def click_save_button(self) -> None:
3741

3842
def appointment_booked_confirmation_is_displayed(self, message: str) -> None:
3943
expect(self.page.get_by_text(message)).to_be_visible()
44+
45+
def accept_dialog(self) -> None:
46+
self.page.once("dialog", lambda dialog: dialog.accept())
47+
48+
def get_current_month_displayed(self) -> str:
49+
return self.current_month_displayed.text_content()

pages/screening_practitioner_appointments/colonoscopy_assessment_appointments_page.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def verify_page_header(self) -> None:
1616
)
1717

1818
def filter_by_nhs_number(self, nhs_number: str) -> None:
19+
self.click(self.nhs_number_filter_text_field)
1920
self.nhs_number_filter_text_field.fill(nhs_number)
2021
self.nhs_number_filter_text_field.press("Enter")
2122

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ markers =
3232
compartment1: only for compartment 1
3333
compartment2: only for compartment 2
3434
compartment3: only for compartment 3
35+
compartment4: only for compartment 4
36+
compartment1_plan_creation: to run the plan creation for compartment 1
3537
vpn_required: for tests that require a VPN connection

tests/smokescreen/test_compartment_4.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from datetime import datetime
3131
from utils.oracle.oracle_specific_functions import get_subjects_for_appointments
3232
from utils.nhs_number_tools import NHSNumberTools
33+
import logging
3334

3435

3536
@pytest.fixture
@@ -54,6 +55,7 @@ def test_compartment_4(page: Page, smokescreen_properties: dict) -> None:
5455
smokescreen_properties["c4_eng_number_of_appointments_to_book"]
5556
)
5657

58+
logging.info("Setting up appointments")
5759
UserTools.user_login(page, "Screening Centre Manager at BCS001")
5860
BasePage(page).go_to_screening_practitioner_appointments_page()
5961
ScreeningPractitionerAppointmentsPage(page).go_to_set_availability_page()
@@ -65,9 +67,7 @@ def test_compartment_4(page: Page, smokescreen_properties: dict) -> None:
6567
"Astonish, Ethanol"
6668
)
6769
PractitionerAvailabilityPage(page).click_calendar_button()
68-
CalendarPicker(page).select_day(
69-
datetime.today()
70-
) # This will make it so that we can only run this test once a day, or we need to restore the DB back to the snapshot
70+
CalendarPicker(page).select_day(datetime.today())
7171
PractitionerAvailabilityPage(page).click_show_button()
7272
PractitionerAvailabilityPage(page).enter_start_time("09:00")
7373
PractitionerAvailabilityPage(page).enter_end_time("17:15")
@@ -81,25 +81,43 @@ def test_compartment_4(page: Page, smokescreen_properties: dict) -> None:
8181

8282
ScreeningPractitionerAppointmentsPage(page).go_to_log_in_page()
8383
UserTools.user_login(page, "Hub Manager State Registered at BCS01")
84+
8485
BasePage(page).go_to_screening_practitioner_appointments_page()
8586
ScreeningPractitionerAppointmentsPage(page).go_to_patients_that_require_page()
86-
# Add for loop to loop x times (depends on how many we want to run it for) 70 - 79
87-
nhs_number = subjects_df["subject_nhs_number"].iloc[0]
88-
nhs_number_spaced = NHSNumberTools().spaced_nhs_number(nhs_number)
89-
ColonoscopyAssessmentAppointments(page).filter_by_nhs_number(nhs_number)
90-
ColonoscopyAssessmentAppointments(page).click_nhs_number_link(nhs_number_spaced)
91-
BookAppointmentPage(page).select_screening_centre_dropdown_option(
92-
"BCS001 - Wolverhampton Bowel Cancer Screening Centre"
93-
)
94-
BookAppointmentPage(page).select_site_dropdown_option("Holly Hall Clinic (? km)")
95-
BookAppointmentPage(page).choose_day_with_available_slots()
96-
BookAppointmentPage(page).appointments_table.click_first_input_in_column(
97-
"Appt/Slot Time"
98-
)
99-
BookAppointmentPage(page).click_save_button()
100-
BookAppointmentPage(page).appointment_booked_confirmation_is_displayed(
101-
"Appointment booked"
102-
)
87+
88+
for subject_num in range(
89+
int(smokescreen_properties["c4_eng_number_of_appointments_to_book"])
90+
):
91+
nhs_number = subjects_df["subject_nhs_number"].iloc[subject_num]
92+
logging.info(f"Booking appointment for: {nhs_number}")
93+
94+
nhs_number_spaced = NHSNumberTools().spaced_nhs_number(nhs_number)
95+
ColonoscopyAssessmentAppointments(page).filter_by_nhs_number(nhs_number)
96+
ColonoscopyAssessmentAppointments(page).click_nhs_number_link(nhs_number_spaced)
97+
BookAppointmentPage(page).select_screening_centre_dropdown_option(
98+
"BCS001 - Wolverhampton Bowel Cancer Screening Centre"
99+
)
100+
BookAppointmentPage(page).select_site_dropdown_option(
101+
"The Royal Hospital (Wolverhampton) (? km)"
102+
)
103+
current_month_displayed = BookAppointmentPage(
104+
page
105+
).get_current_month_displayed()
106+
CalendarPicker(page).select_first_eligble_appointment(
107+
current_month_displayed,
108+
BookAppointmentPage(page).day_with_available_slots,
109+
BookAppointmentPage(page).day_with_some_available_slots,
110+
)
111+
BookAppointmentPage(page).appointments_table.click_first_input_in_column(
112+
"Appt/Slot Time"
113+
)
114+
BookAppointmentPage(page).accept_dialog()
115+
BookAppointmentPage(page).click_save_button()
116+
BookAppointmentPage(page).appointment_booked_confirmation_is_displayed(
117+
"Appointment booked"
118+
)
119+
BasePage(page).click_back_button()
120+
BasePage(page).click_main_menu_link()
103121

104122
batch_processing(
105123
page,

tests/test_gfobt_test_kits_page.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
from pages.base_page import BasePage
55
from pages.gfobt_test_kits.gfobt_test_kits_page import GFOBTTestKits
6-
from pages.gfobt_test_kits.gfobt_test_kit_logging_page import TestKitLogging
6+
from pages.gfobt_test_kits.gfobt_test_kit_logging_page import GFOBTTestKitLogging
77
from pages.gfobt_test_kits.gfobt_test_kit_quality_control_reading_page import (
8-
TestKitQualityControlReading,
8+
GFOBTTestKitQualityControlReading,
99
)
1010
from pages.gfobt_test_kits.gfobt_view_test_kit_result import ViewTestKitResult
1111
from pages.gfobt_test_kits.gfobt_create_qc_kit_page import (
@@ -27,6 +27,7 @@ def before_each(page: Page):
2727
# Go to gFOBT test kits page
2828
BasePage(page).go_to_gfobt_test_kits_page()
2929

30+
3031
@pytest.mark.smoke
3132
def test_gfobt_test_kit_page_navigation(page: Page) -> None:
3233
"""
@@ -35,12 +36,12 @@ def test_gfobt_test_kit_page_navigation(page: Page) -> None:
3536
"""
3637
# Test kit logging page opens as expected
3738
GFOBTTestKits(page).go_to_test_kit_logging_page()
38-
TestKitLogging(page).verify_test_kit_logging_title()
39+
GFOBTTestKitLogging(page).verify_test_kit_logging_title()
3940
BasePage(page).click_back_button()
4041

4142
# Test kit reading page opens as expected
4243
GFOBTTestKits(page).go_to_test_kit_reading_page()
43-
TestKitQualityControlReading(page).verify_test_kit_logging_tile()
44+
GFOBTTestKitQualityControlReading(page).verify_test_kit_logging_tile()
4445
BasePage(page).click_back_button()
4546

4647
# View test kit result page opens as expected

utils/calendar_picker.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from playwright.sync_api import Page, Locator
44
from pages.base_page import BasePage
55
from sys import platform
6+
import logging
7+
import pytest
68

79

810
class CalendarPicker(BasePage):
@@ -14,6 +16,13 @@ def __init__(self, page: Page):
1416
self.v1_prev_month = self.page.get_by_role("cell", name="‹").locator("div")
1517
self.v1_next_month = self.page.get_by_role("cell", name="›").locator("div")
1618
self.v1_next_year = self.page.get_by_role("cell", name="»").locator("div")
19+
# Book Appointment picker locators
20+
self.appointments_prev_month = self.page.get_by_role(
21+
"link", name="<-", exact=True
22+
)
23+
self.appointments_next_month = self.page.get_by_role(
24+
"link", name="->", exact=True
25+
)
1726

1827
# Calendar Methods
1928
def calendar_picker_ddmmyyyy(self, date: datetime, locator: Locator) -> None:
@@ -276,3 +285,83 @@ def v2_calendar_picker(self, date: datetime) -> None:
276285
)
277286

278287
self.select_day(date)
288+
289+
def month_string_to_number(self, string: str) -> None:
290+
"""
291+
This is used to convert a month from a string to an integer.
292+
It accepts the full month or the short version and is not case sensitive
293+
"""
294+
months = {
295+
"jan": 1,
296+
"feb": 2,
297+
"mar": 3,
298+
"apr": 4,
299+
"may": 5,
300+
"jun": 6,
301+
"jul": 7,
302+
"aug": 8,
303+
"sep": 9,
304+
"oct": 10,
305+
"nov": 11,
306+
"dec": 12,
307+
}
308+
month_short = string.strip()[:3].lower()
309+
310+
try:
311+
out = months[month_short]
312+
return out
313+
except Exception:
314+
raise ValueError("Not a month")
315+
316+
def select_first_eligble_appointment(
317+
self,
318+
current_month_displayed: str,
319+
avialble_locator: Locator,
320+
some_available_locator: Locator,
321+
) -> None:
322+
"""
323+
This is used to select the first eligible appointment date
324+
It first gets all available dates, and then clicks on the first one starting from today's date
325+
"""
326+
current_month_displayed_int = self.month_string_to_number(
327+
current_month_displayed
328+
)
329+
if platform == "win32": # Windows
330+
current_month_int = int(datetime.now().strftime("%#d"))
331+
else: # Linux or Mac
332+
current_month_int = int(datetime.now().strftime("%-d"))
333+
334+
if current_month_displayed_int != current_month_int:
335+
self.click(self.appointments_prev_month)
336+
337+
months_looped = 0
338+
appointment_clicked = False
339+
while (
340+
months_looped < 3 and not appointment_clicked
341+
): # This loops through this month + next two months to find available appointments. If none found it has failed
342+
appointment_clicked = self.check_for_eligible_appointment_dates(
343+
avialble_locator
344+
)
345+
346+
if not appointment_clicked:
347+
appointment_clicked = self.check_for_eligible_appointment_dates(
348+
some_available_locator
349+
)
350+
351+
if not appointment_clicked:
352+
self.click(self.appointments_next_month)
353+
months_looped += 1
354+
355+
if not appointment_clicked:
356+
pytest.fail("No available appointments found for the current month")
357+
358+
def check_for_eligible_appointment_dates(self, locator: Locator) -> bool:
359+
360+
locator_count = locator.count()
361+
362+
for i in range(locator_count):
363+
locator_number = locator_count - i - 1
364+
value = locator.nth(locator_number).get_attribute("name")
365+
if len(value) < 5:
366+
self.click(locator.nth(locator_number))
367+
return True

0 commit comments

Comments
 (0)