Skip to content

Commit 9439b8f

Browse files
Fixing the calendar util to select the correct day. (#61)
Incresing the performance of the select_day method. Making selecting today's date a lot quicker. <!-- markdownlint-disable-next-line first-line-heading --> ## Description <!-- Describe your changes in detail. --> Fixing the calendar util to select the correct day. Incresing the performance of the select_day method. Making selecting today's date a lot quicker. ## Context <!-- Why is this change required? What problem does it solve? --> Increases reliability and performance of the util. ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [x] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md) - [x] I have followed the code style of the project - [x] I have added tests to cover my changes (where appropriate) - [ ] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.
1 parent b11ecfa commit 9439b8f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

tests/test_calendar_picker_methods.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def test_calender_picker_v1(page: Page) -> None:
2828
SubjectScreeningPage(page).select_dob_using_calendar_picker(datetime(2020, 3, 30))
2929
SubjectScreeningPage(page).verify_date_of_birth_filter_input("30/03/2020")
3030
SubjectScreeningPage(page).click_clear_filters_button()
31-
SubjectScreeningPage(page).select_dob_using_calendar_picker(datetime(2020, 6, 15))
32-
SubjectScreeningPage(page).verify_date_of_birth_filter_input("15/06/2020")
31+
SubjectScreeningPage(page).select_dob_using_calendar_picker(datetime(2019, 11, 27))
32+
SubjectScreeningPage(page).verify_date_of_birth_filter_input("27/11/2019")
3333
SubjectScreeningPage(page).click_clear_filters_button()
3434
SubjectScreeningPage(page).select_dob_using_calendar_picker(datetime.today())
3535
SubjectScreeningPage(page).verify_date_of_birth_filter_input(

utils/calendar_picker.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, page: Page):
1818
self.v1_calendar_current_date = self.page.locator(
1919
'td.title[colspan="5"][style="cursor: move;"]'
2020
)
21+
self.v1_today_button = self.page.get_by_text("Today", exact=True)
2122
# V2 Calendar picker locators
2223
self.v2date_picker_switch = self.page.locator(
2324
'th.datepicker-switch[colspan="5"]:visible'
@@ -127,18 +128,20 @@ def select_day(self, date: datetime) -> None:
127128
"cell", name=day_to_select
128129
).count()
129130

130-
all_days = self.page.locator(".day").all()
131+
all_matching_days = self.page.get_by_role(
132+
"cell", name=day_to_select, exact=True
133+
).all()
131134

132135
matching_days = [
133136
day
134-
for day in all_days
137+
for day in all_matching_days
135138
if day.evaluate("el => el.textContent.trim()") == day_to_select
136139
]
137140

138141
if int(day_to_select) < 15 and number_of_cells_with_day > 1:
139142
self.click(matching_days[0].first)
140143
elif int(day_to_select) > 15 and number_of_cells_with_day > 1:
141-
self.click(matching_days[0].last)
144+
self.click(matching_days[-1].last)
142145
else:
143146
self.click(matching_days[0])
144147

@@ -150,6 +153,13 @@ def v1_calender_picker(self, date: datetime) -> None:
150153
Args:
151154
date (datetime): The date we want to select
152155
"""
156+
157+
if DateTimeUtils.format_date(date, "%d/%m/%Y") == DateTimeUtils.format_date(
158+
datetime.today(), "%d/%m/%Y"
159+
):
160+
self.click(self.v1_today_button)
161+
return
162+
153163
current_date = datetime.strptime(
154164
self.v1_calendar_current_date.inner_text(), "%B, %Y"
155165
)

0 commit comments

Comments
 (0)