Skip to content

Commit

Permalink
Merge pull request #12 from NHSDigital/RAVS-305-legal-mechanism-change
Browse files Browse the repository at this point in the history
Ravs 305 legal mechanism change
  • Loading branch information
neelimaguntupalli1-nhs authored Jul 23, 2024
2 parents fe4ab8c + a012099 commit c5a6f06
Show file tree
Hide file tree
Showing 27 changed files with 214 additions and 231 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests_dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
name: RAVS TESTS - DEV

on:
push:
branches:
- '**' # Triggers on push to any branch
pull_request:
branches:
- '**' # Triggers on PR to any branch
schedule:
- cron: "0 7 * * *"
workflow_dispatch:

jobs:
Expand Down
19 changes: 11 additions & 8 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ def choose_vaccine_and_vaccine_type_for_patient(vaccine, vaccine_type):
click_continue_to_assess_patient_button()
attach_screenshot("selected_vaccine_" + vaccine + "_and_" + vaccine_type + "_and_clicked_continue_button")

def check_vaccine_and_batch_exists_in_site_api_request(site, vaccine, vaccineType,batch_number, expirydate):
pass

def check_vaccine_and_batch_exists_in_site(site, vaccine, vaccineType,batch_number, expirydate):
if config["browser"] == "mobile":
if check_navlink_bar_toggle_exists():
Expand All @@ -246,10 +249,10 @@ def check_vaccine_and_batch_exists_in_site(site, vaccine, vaccineType,batch_numb
attach_screenshot("before_clicking_site_radio_button")
click_site_radio_button(site)
if "covid" in vaccine.lower():
attach_screenshot("before_clicking_covid_vaccine_checkbox")
click_covid_vaccine_checkbox()
attach_screenshot("before_clicking_covid_vaccinetype_checkbox")
click_covid_vaccine_type_checkbox(vaccineType)
attach_screenshot("before_clicking_covid_vaccine_checkbox")
click_covid_vaccine_checkbox()
attach_screenshot("before_clicking_covid_vaccinetype_checkbox")
click_covid_vaccine_type_checkbox(vaccineType)
elif "flu" in vaccine.lower():
attach_screenshot("before_clicking_flu_vaccine_checkbox")
click_flu_vaccine_checkbox()
Expand Down Expand Up @@ -301,7 +304,8 @@ def check_vaccine_and_batch_exists_in_site(site, vaccine, vaccineType,batch_numb
attach_screenshot("clicked_confirm_choices_button")
click_find_a_patient_nav_link()

def assess_patient_with_details_and_click_continue_to_consent(eligible_decision, eligibility_type, staff_role, assessing_clinician, assessment_date, assessment_outcome, assessment_comments, eligibility_assessment_no_vaccine_given_reason=None):
def assess_patient_with_details_and_click_continue_to_consent(eligible_decision, eligibility_type, staff_role, assessing_clinician, assessment_date, legal_mechanism, assessment_outcome, assessment_comments, eligibility_assessment_no_vaccine_given_reason=None):
click_legal_mechanism(legal_mechanism)
select_assessing_clinician_with_name_and_council(assessing_clinician)
enter_comments_for_assessing_patient(assessment_comments)
set_assessment_date(assessment_date)
Expand Down Expand Up @@ -346,7 +350,7 @@ def record_consent_details_and_click_continue_to_vaccinate(consent_decision, co
click_save_and_return_button_on_record_consent_page()
attach_screenshot("patient_decided_to_not_consent_saved_and_returned")

def enter_vaccine_details_and_click_continue_to_check_and_confirm(vaccinate_decision, vaccination_date, vaccine, vaccine_type2, vaccination_route, batch_number, batch_expiry_date, dose_amount, prescribing_method, vaccinator, vaccination_comments, no_vaccination_reason=None):
def enter_vaccine_details_and_click_continue_to_check_and_confirm(vaccinate_decision, vaccination_date, vaccine, vaccine_type2, vaccination_site, batch_number, batch_expiry_date, dose_amount, legal_mechanism, vaccinator, vaccination_comments, no_vaccination_reason=None):
select_vaccinator_name_and_council(vaccinator)
enter_vaccination_comments(vaccination_comments)
set_vaccination_date(vaccination_date)
Expand All @@ -356,12 +360,11 @@ def enter_vaccine_details_and_click_continue_to_check_and_confirm(vaccinate_deci
click_covid_vaccine_type_radiobutton_choose_vaccine_for_patient_on_vaccinated_page(vaccine_type2)
elif "flu" in (vaccine).lower():
click_flu_vaccine_type_radiobutton_choose_vaccine_for_patient_on_vaccinated_page(vaccine_type2)
select_vaccination_route(vaccination_route)
select_vaccination_site(vaccination_site)
batch_number_to_select = batch_number.upper() + " - " + batch_expiry_date
select_batch_number(batch_number_to_select)
time.sleep(3)
enter_dose_amount_value(dose_amount)
click_prescribing_method(prescribing_method)
if click_continue_to_check_and_confirm_screen_button() == True:
vaccination_date = format_date(vaccination_date, "safari")
set_vaccination_date(vaccination_date)
Expand Down
4 changes: 2 additions & 2 deletions features/find_a_patient.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ Feature: Find a patient
| nhsNumber | name | dateofbirth | address |
| 9693632109 | Bill GARTON | 23/6/1946 | 1 MOUNT AVENUE, BARTON-UPON-HUMBER, S HUMBERSIDE, DN18 5DW |
| 9449304424 | COMFORT Jones | 9/3/2018 | Ifyoucan113, GDA11 UCL6, KT17 1NA |
| 9449305552 | abxxyz Patel | 13/2/2020 | Caretakers Flat, Line2121, Line323, HYDERABAD, Country, EN2 6SN |
| 9449305552 | Prasad Patel | 14/2/2020 | Caretakers Flat, Line2121, Line323, HYDERABAD, Country, EN2 6SN |
| 9449306621 | Not found | 20110509 | KT21 1LJ |
| 9449306613 | Briar Anderton | 20/5/1990 | 123 Main Vyt, AB12 3CE |
| 9449306605 | Srinivasarao Patel | 03/03/2020 | 4 Calicut Lane2, Line 2, Line 3, SLOUGH, Berkshire, KT21 1EJ |
| 9449306494 | Reynolds Ryan | 27/3/2001 | 39 Barton Road, RG10 9DF |
| 9449306494 | Reynolds Ryan | 27/3/2001 | 40 Queen Street London, EC4R 1DD |
| 9469997956 | SOLOMON DAZLEY | 20160130 | 10 BROOK STREET, LANCASTER, LA1 1SL |
| 9469998626 | JONNY CONOPO | 20150305 | 1 DAISY BANK, LANCASTER, LA1 3JW |
| 9470004272 | JOJO LANE | 20150706 | 10 RAKESMOOR LANE, BARROW-IN-FURNESS, LA14 4LG |
Expand Down
71 changes: 68 additions & 3 deletions helpers/datetimeHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,82 @@ def standardize_date_format(date_str):
try:
# Try parsing the date as '%d/%m/%Y'
parsed_date = datetime.strptime(date_str, "%d/%m/%Y")
return parsed_date.strftime("%d/%m/%Y")
except ValueError:
try:
# If parsing fails, try parsing as '%m/%d/%Y'
parsed_date = datetime.strptime(date_str, "%m/%d/%Y")
# Format the parsed date to '%d/%m/%Y'
return parsed_date.strftime("%d/%m/%Y")
except ValueError:
# If parsing as both formats fails, return the original string
return date_str

# Manually format the date to ensure no leading zeros on the day
day = parsed_date.day
month = parsed_date.strftime('%m')
year = parsed_date.year

return f"{day}/{month}/{year}"

@staticmethod
def date_format_with_age(date_str):
try:
# Try parsing the date as '%d/%m/%Y'
parsed_date = datetime.strptime(date_str, "%d/%m/%Y")
except ValueError:
try:
# If parsing fails, try parsing as '%m/%d/%Y'
parsed_date = datetime.strptime(date_str, "%m/%d/%Y")
except ValueError:
# If parsing as both formats fails, return the original string
return date_str

today = datetime.today()
age = today.year - parsed_date.year - ((today.month, today.day) < (parsed_date.month, parsed_date.day))

day = parsed_date.day # Day without leading zero
month = parsed_date.strftime('%B') # Full month name
year = parsed_date.year # Full year

return f"{day} {month} {year} (aged {age})"

@staticmethod
def date_format_with_day_of_week(date_str):
try:
# Try parsing the date as '%d/%m/%Y'
parsed_date = datetime.strptime(date_str, "%d/%m/%Y")
except ValueError:
try:
# If parsing fails, try parsing as '%m/%d/%Y'
parsed_date = datetime.strptime(date_str, "%m/%d/%Y")
except ValueError:
# If parsing as both formats fails, return the original string
return date_str

# Manually format the date to include the day of the week without leading zero for the day
day_of_week = parsed_date.strftime('%A')
day = parsed_date.day
month = parsed_date.strftime('%B')
year = parsed_date.year

return f"{day_of_week} {day} {month} {year}"

@staticmethod
def date_format_with_name_of_month(date_str):
try:
# Try parsing the date as '%d/%m/%Y'
parsed_date = datetime.strptime(date_str, "%d/%m/%Y")
except ValueError:
try:
# If parsing fails, try parsing as '%m/%d/%Y'
parsed_date = datetime.strptime(date_str, "%m/%d/%Y")
except ValueError:
# If parsing as both formats fails, return the original string
return date_str.strftime("%d %B %Y")

day = parsed_date.day
month = parsed_date.strftime('%B')
year = parsed_date.year
return f"{day} {month} {year}"


class DatetimeHelper(BaseDatetimeHelper):
def __init__(self):
Expand Down
9 changes: 1 addition & 8 deletions helpers/playwrightHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,14 @@ def navigate_to_url(self,url):
self.page.goto(url)
self.page.wait_for_load_state()


def wait_for_page_to_load(self, timeout=1):
self.page.wait_for_selector('*', timeout=timeout * 100)
self.page.wait_for_load_state('domcontentloaded', timeout=timeout * 100)

def find_elements(self, selector):
return self.page.query_selector_all(selector)

def wait_for_element_to_appear(self, selector, timeout=50):
def wait_for_element_to_appear(self, selector, timeout=20):
try:
self.page.wait_for_selector(selector, timeout=timeout, state='visible')
print(f"Element {selector} appeared on the page.")
Expand All @@ -143,7 +142,6 @@ def wait_for_selector_to_disappear(self, selector, timeout=50):
print(f"Error waiting for element {selector} to disappear: {e}")

def check_element_exists(self, selector, wait=False):
self.wait_for_page_to_load()
try:
element = self.page.locator(selector)
if wait == True:
Expand All @@ -154,7 +152,6 @@ def check_element_exists(self, selector, wait=False):
return False

def check_element_enabled(self, selector, wait=False):
self.wait_for_page_to_load()
try:
element = self.page.locator(selector)
if wait == True:
Expand All @@ -169,7 +166,6 @@ def scroll_into_view(self, selector):
element.scroll_into_view_if_needed()

def clear_element(self, selector):
self.wait_for_page_to_load()
try:
element=self.page.locator(selector)
element.clear()
Expand All @@ -184,7 +180,6 @@ def release_mouse(self):
self.page.mouse.up()

def find_element_and_perform_action(self, selector, action, inputValue=None):
self.wait_for_page_to_load()
selector_filename = "".join(c if c.isalnum() else "_" for c in selector)
self.capture_screenshot(selector_filename)
try:
Expand Down Expand Up @@ -231,15 +226,13 @@ def find_element_and_perform_action(self, selector, action, inputValue=None):
self.capture_screenshot(selector_filename)

def get_current_url(self):
self.wait_for_page_to_load()
return self.page.url()

def get_accessibility_violations(self):
try:
current_url = self.get_current_url(self.page)

self.page.goto(current_url)
self.wait_for_page_to_load(self.page)

axe = self.page.accessibility
results = axe.check()
Expand Down
13 changes: 11 additions & 2 deletions init_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def load_config_from_env():
def attach_screenshot(filename):
logging.basicConfig(level=logging.DEBUG)
if config["browser"] == "mobile":
filename = config["browser"] + "_" + config["device"] + "_" + get_browser_version() + "_" + filename + ".png"
filename = config["test_environment"] + "_" + config["browser"] + "_" + config["device"] + "_" + get_browser_version() + "_" + filename + ".png"
else:
filename = config["browser"] + "_" + get_browser_version() + "_" + filename + ".png"
filename = config["test_environment"] + "_" + config["browser"] + "_" + get_browser_version() + "_" + filename + ".png"

directory = os.path.dirname(filename)
if directory:
Expand Down Expand Up @@ -164,6 +164,15 @@ def format_date(date, browser):
def standardize_date_format(date):
return datetime_helper_instance.standardize_date_format(date)

def date_format_with_day_of_week(date):
return datetime_helper_instance.date_format_with_day_of_week(date)

def date_format_with_age(date):
return datetime_helper_instance.date_format_with_age(date)

def date_format_with_name_of_month(date):
return datetime_helper_instance.date_format_with_name_of_month(date)

def get_date_value(date):
return datetime_helper_instance.get_date_value(date)

2 changes: 1 addition & 1 deletion pages/add_vaccines_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def check_confirm_choices_button_enabled():
return check_element_enabled(CONFIRM_VACCINE_CHOICES_BUTTON, True)

def click_site_radio_button(site):
element = (f"//label[text()='{site}']/preceding-sibling::input[@id='SiteId']")
element = (f"//label[text()='{site}']/preceding-sibling::input[@name='SiteId']")
find_element_and_perform_action(element, "click")

def click_covid_vaccine_checkbox():
Expand Down
12 changes: 12 additions & 0 deletions pages/assess_patient_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ def select_eligibility_type(type):
else:
click_eligible_yes_radiobutton()

def click_legal_mechanism(legal_mechanism):
xpath_map = {
"national protocol (np)": "//label[@for='LegalMechanismId-1']",
"patient group directions (pgd)": "//label[@for='LegalMechanismId-2']",
"patient specific directions (psd)": "//label[@for='LegalMechanismId-3']",
}
element = xpath_map.get(legal_mechanism.lower())
if element:
find_element_and_perform_action(element, "click")
else:
print("Invalid vaccine type")

def check_eligibility_type_is_visible():
return check_element_exists(ELIGIBILITY_TYPE_DROPDOWN_ELEMENT)

Expand Down
Loading

0 comments on commit c5a6f06

Please sign in to comment.