Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ravs 1094 automate reports feature #34

Merged
merged 19 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,18 @@ def enter_vaccine_details_and_click_continue_to_check_and_confirm(vaccinate_deci
attach_screenshot("patient_decided_to_not_vaccinate")
click_save_and_return_button_on_record_vaccinated_page()
attach_screenshot("patient_decided_to_not_vaccinate_saved_and_returned")

def navigate_and_login_with_username(username):
if config["browser"] == "mobile":
if check_navbar_toggle_exists_without_waiting():
click_navbar_toggler()
if check_logout_button_exists_without_waiting():
click_logout_button()
url = get_app_url(config["test_environment"])
navigate_to_ravs_login_page(url)
click_login_button()
emailAddress = username
enter_email_address(emailAddress)
password = config["credentials"]["ravs_password"]
enter_password(password)
click_nhs_signin_button()
18 changes: 17 additions & 1 deletion features/reports.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
Feature: Reports

@reports
Scenario: Create reports page should launch
Scenario: "Reports" page is displayed
Given I am logged into the RAVS app
When I click the reports navigation link
Then the reports page should be displayed

Scenario: "Choose dates" page is displayed
Given I am logged into the RAVS app
When I click the reports navigation link
And I click the create report button
Then the choose dates page should be displayed

Scenario Outline: Create report for an organization with no location sites
Given I am logged into the RAVS app with the <username>
When I click the reports navigation link
Then the `No vaccination data to report on` message should be displayed
And the Create report button should be disabled

Examples:
| username |
| [email protected] |
11 changes: 11 additions & 0 deletions pages/reports_date_range_selection_page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from init_helpers import *

CREATE_REPORT_BUTTON = ("role", "button", "Create report")
NO_VACCINATION_DATE_TO_REPORT = ("text", "No vaccination data to report")
TODAY_RADIO_BUTTON = ("label", "Today", None, True)
YESTERDAY_RADIO_BUTTON = ("label", "Yesterday")
LAST_7_DAYS_RADIO_BUTTON = ("label", "Last 7 days (includes today)")
Expand Down Expand Up @@ -30,6 +31,16 @@ def check_create_report_button_exists():
wait_for_element_to_appear(CREATE_REPORT_BUTTON)
return check_element_exists(CREATE_REPORT_BUTTON)

def check_no_vaccination_data_to_report_message_exists():
wait_for_element_to_disappear(PAGE_LOADING_ELEMENT)
wait_for_element_to_appear(NO_VACCINATION_DATE_TO_REPORT)
return check_element_exists(NO_VACCINATION_DATE_TO_REPORT)

def check_create_report_button_enabled():
wait_for_element_to_disappear(PAGE_LOADING_ELEMENT)
wait_for_element_to_appear(CREATE_REPORT_BUTTON)
return check_element_enabled(CREATE_REPORT_BUTTON)

def click_create_report_button():
wait_for_element_to_appear(CREATE_REPORT_BUTTON)
find_element_and_perform_action(CREATE_REPORT_BUTTON, "click")
Expand Down
216 changes: 103 additions & 113 deletions pages/site_vaccine_batches_page.py
Original file line number Diff line number Diff line change
@@ -1,114 +1,104 @@
from init_helpers import *
from test_data.get_values_from_models import get_flu_vaccine_add_batch_radio_button_xpath, get_covid_vaccine_add_batch_radio_button_xpath

ADD_BATCH_BUTTON = ("//button[text()='Add batch']")
SELECT_SITE_RADIOBUTTON = ("#SiteId")
BACK_BUTTON_ON_VACCINE_BATCHES_PAGE = ("//a[@href='/site-vaccines']")
COVID_VACCINE_RADIOBUTTON = ("//input[@class='nhsuk-radios__input' and @name='VaccineProgramId' and @value='1']")
FLU_VACCINE_RADIOBUTTON = ("//input[@class='nhsuk-radios__input' and @name='VaccineProgramId' and @value='2']")
CANCEL_ADDING_VACCINE_BATCHES_BUTTON = ("//button[text()='Cancel']")
CONFIRM_VACCINE_BATCHES_CHOICES_BUTTON = ("//button[text()='Confirm choices']")
SELECT_VACCINES_LABEL = ("//legend[text()='Select vaccines']")
FLU_BATCH_NUMBER_INPUT_FIELD = ("#FluBatchNumber")
COVID_BATCH_NUMBER_PREFIX_INPUT_FIELD = ("#CovidBatchNumberPrefix")
COVID_BATCH_NUMBER_SUFFIX_INPUT_FIELD = ("#CovidBatchNumberSuffix")
EXPIRY_DATE_DAY_INPUT_FIELD = ("#ExpiryDate_1")
EXPIRY_DATE_MONTH_INPUT_FIELD = ("#ExpiryDate_2")
EXPIRY_DATE_YEAR_INPUT_FIELD = ("#ExpiryDate_3")
COVID_BATCH_NUMBER_PREFIX_ERROR_LABEL = ("#CovidBatchNumberPrefixIdError")
COVID_BATCH_NUMBER_SUFFIX_ERROR_LABEL = ("#CovidBatchNumberSuffixIdError")
EXPIRY_DAY_INPUT_ERROR_LABEL = ("#ExpiryDate_1IdError")
EXPIRY_MONTH_INPUT_ERROR_LABEL = ("#ExpiryDate_2IdError")
EXPIRY_YEAR_INPUT_ERROR_LABEL = ("#ExpiryDate_3IdError")
REACTIVATE_BATCH_CONFIRMATION_BUTTON = ("//button[text()='Reactivate']")

def click_reactivate_batch_confirmation_button():
find_element_and_perform_action(REACTIVATE_BATCH_CONFIRMATION_BUTTON, "click")

def get_first_active_batch_number_value():
xpath = "(//tbody[@class='nhsuk-table__body']//tr[td[@role='cell'][3]//strong[text()='Active']][1]//td[@role='cell'])[1]"
wait_for_element_to_appear(("xpath", xpath))
full_text = find_element_and_perform_action(("xpath", xpath), "get_text")
batch_number = full_text.replace('Batch number', '').strip()
return batch_number

def check_required_field_error_appears_for_expiry_month(wait):
return check_element_exists(EXPIRY_MONTH_INPUT_ERROR_LABEL, wait)

def check_required_field_error_appears_for_covid_batch_prefix(wait):
return check_element_exists(COVID_BATCH_NUMBER_PREFIX_ERROR_LABEL, wait)

def check_required_field_error_appears_for_covid_batch_suffix(wait):
return check_element_exists(COVID_BATCH_NUMBER_SUFFIX_ERROR_LABEL, wait)

def check_required_field_error_appears_for_expiry_year(wait):
return check_element_exists(EXPIRY_YEAR_INPUT_ERROR_LABEL, wait)

def check_required_field_error_appears_for_expiry_DAY(wait):
return check_element_exists(EXPIRY_DAY_INPUT_ERROR_LABEL, wait)

def enter_expiry_date(date):
day, month, year = date.split('/')
find_element_and_perform_action(EXPIRY_DATE_DAY_INPUT_FIELD, "input_text",day)
find_element_and_perform_action(EXPIRY_DATE_MONTH_INPUT_FIELD,"input_text", month)
find_element_and_perform_action(EXPIRY_DATE_YEAR_INPUT_FIELD, "input_text",year)

def enter_flu_batch_number(batchnumber):
find_element_and_perform_action(FLU_BATCH_NUMBER_INPUT_FIELD, "input_text",batchnumber)

def enter_covid_batch_number_prefix(batchnumber):
find_element_and_perform_action(COVID_BATCH_NUMBER_PREFIX_INPUT_FIELD,"input_text", batchnumber)

def enter_covid_batch_number_suffix(batchnumber):
find_element_and_perform_action(COVID_BATCH_NUMBER_SUFFIX_INPUT_FIELD,"input_text", batchnumber)

def click_back_button_on_vaccine_batches_page():
find_element_and_perform_action(BACK_BUTTON_ON_VACCINE_BATCHES_PAGE,"click")

def click_select_vaccines_label():
release_mouse()
find_element_and_perform_action(SELECT_VACCINES_LABEL, "click")

def click_cancel_adding_vaccine_batches_button():
find_element_and_perform_action(CANCEL_ADDING_VACCINE_BATCHES_BUTTON,"click")

def click_confirm_vaccine_batch_choices_button():
find_element_and_perform_action(CONFIRM_VACCINE_BATCHES_CHOICES_BUTTON, "click")

def click_add_batch_button():
find_element_and_perform_action(ADD_BATCH_BUTTON, "click")

def check_add_batch_button_exists():
return check_element_exists(ADD_BATCH_BUTTON, True)

def check_add_batch_button_enabled():
return check_element_enabled(ADD_BATCH_BUTTON, True)

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

def click_covid_vaccine_radiobutton():
find_element_and_perform_action(COVID_VACCINE_RADIOBUTTON, "click")

def click_flu_vaccine_radiobutton():
find_element_and_perform_action(FLU_VACCINE_RADIOBUTTON, "click_checkbox")

def click_covid_vaccine_type_radiobutton_on_add_batches_page(vaccinetype):
element = get_covid_vaccine_add_batch_radio_button_xpath(vaccinetype.lower())
if element:
find_element_and_perform_action(element, "click")
else:
print("Invalid vaccine type")

def click_flu_vaccine_type_radiobutton_on_add_batches_page(vaccinetype):
element = get_flu_vaccine_add_batch_radio_button_xpath(vaccinetype.lower())
if element:
find_element_and_perform_action(element, "click")
else:
print("Invalid vaccine type")

def check_vaccine_already_added_warning_message_exists(site, vaccine):
element = (f"//span[text()='{site} already has {vaccine}']")
return check_element_exists(element, False)
# from init_helpers import *
# from test_data.get_values_from_models import get_flu_vaccine_add_batch_radio_button_xpath, get_covid_vaccine_add_batch_radio_button_xpath





# COVID_BATCH_NUMBER_PREFIX_ERROR_LABEL = ("#CovidBatchNumberPrefixIdError")
# COVID_BATCH_NUMBER_SUFFIX_ERROR_LABEL = ("#CovidBatchNumberSuffixIdError")
# EXPIRY_DAY_INPUT_ERROR_LABEL = ("#ExpiryDate_1IdError")
# EXPIRY_MONTH_INPUT_ERROR_LABEL = ("#ExpiryDate_2IdError")
# EXPIRY_YEAR_INPUT_ERROR_LABEL = ("#ExpiryDate_3IdError")
# REACTIVATE_BATCH_CONFIRMATION_BUTTON = ("//button[text()='Reactivate']")

# def click_reactivate_batch_confirmation_button():
# find_element_and_perform_action(REACTIVATE_BATCH_CONFIRMATION_BUTTON, "click")

# def get_first_active_batch_number_value():
# xpath = "(//tbody[@class='nhsuk-table__body']//tr[td[@role='cell'][3]//strong[text()='Active']][1]//td[@role='cell'])[1]"
# wait_for_element_to_appear(("xpath", xpath))
# full_text = find_element_and_perform_action(("xpath", xpath), "get_text")
# batch_number = full_text.replace('Batch number', '').strip()
# return batch_number

# def check_required_field_error_appears_for_expiry_month(wait):
# return check_element_exists(EXPIRY_MONTH_INPUT_ERROR_LABEL, wait)

# def check_required_field_error_appears_for_covid_batch_prefix(wait):
# return check_element_exists(COVID_BATCH_NUMBER_PREFIX_ERROR_LABEL, wait)

# def check_required_field_error_appears_for_covid_batch_suffix(wait):
# return check_element_exists(COVID_BATCH_NUMBER_SUFFIX_ERROR_LABEL, wait)

# def check_required_field_error_appears_for_expiry_year(wait):
# return check_element_exists(EXPIRY_YEAR_INPUT_ERROR_LABEL, wait)

# def check_required_field_error_appears_for_expiry_DAY(wait):
# return check_element_exists(EXPIRY_DAY_INPUT_ERROR_LABEL, wait)

# def enter_expiry_date(date):
# day, month, year = date.split('/')
# find_element_and_perform_action(EXPIRY_DATE_DAY_INPUT_FIELD, "input_text",day)
# find_element_and_perform_action(EXPIRY_DATE_MONTH_INPUT_FIELD,"input_text", month)
# find_element_and_perform_action(EXPIRY_DATE_YEAR_INPUT_FIELD, "input_text",year)

# def enter_flu_batch_number(batchnumber):
# find_element_and_perform_action(FLU_BATCH_NUMBER_INPUT_FIELD, "input_text",batchnumber)

# def enter_covid_batch_number_prefix(batchnumber):
# find_element_and_perform_action(COVID_BATCH_NUMBER_PREFIX_INPUT_FIELD,"input_text", batchnumber)

# def enter_covid_batch_number_suffix(batchnumber):
# find_element_and_perform_action(COVID_BATCH_NUMBER_SUFFIX_INPUT_FIELD,"input_text", batchnumber)

# def click_back_button_on_vaccine_batches_page():
# find_element_and_perform_action(BACK_BUTTON_ON_VACCINE_BATCHES_PAGE,"click")

# def click_select_vaccines_label():
# release_mouse()
# find_element_and_perform_action(SELECT_VACCINES_LABEL, "click")

# def click_cancel_adding_vaccine_batches_button():
# find_element_and_perform_action(CANCEL_ADDING_VACCINE_BATCHES_BUTTON,"click")

# def click_confirm_vaccine_batch_choices_button():
# find_element_and_perform_action(CONFIRM_VACCINE_BATCHES_CHOICES_BUTTON, "click")

# def click_add_batch_button():
# find_element_and_perform_action(ADD_BATCH_BUTTON, "click")

# def check_add_batch_button_exists():
# return check_element_exists(ADD_BATCH_BUTTON, True)

# def check_add_batch_button_enabled():
# return check_element_enabled(ADD_BATCH_BUTTON, True)

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

# def click_covid_vaccine_radiobutton():
# find_element_and_perform_action(COVID_VACCINE_RADIOBUTTON, "click")

# def click_flu_vaccine_radiobutton():
# find_element_and_perform_action(FLU_VACCINE_RADIOBUTTON, "click_checkbox")

# def click_covid_vaccine_type_radiobutton_on_add_batches_page(vaccinetype):
# element = get_covid_vaccine_add_batch_radio_button_xpath(vaccinetype.lower())
# if element:
# find_element_and_perform_action(element, "click")
# else:
# print("Invalid vaccine type")

# def click_flu_vaccine_type_radiobutton_on_add_batches_page(vaccinetype):
# element = get_flu_vaccine_add_batch_radio_button_xpath(vaccinetype.lower())
# if element:
# find_element_and_perform_action(element, "click")
# else:
# print("Invalid vaccine type")

# def check_vaccine_already_added_warning_message_exists(site, vaccine):
# element = (f"//span[text()='{site} already has {vaccine}']")
# return check_element_exists(element, False)

39 changes: 20 additions & 19 deletions pages/site_vaccines_add_batch_page.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from init_helpers import *

VACCINE_BATCH_NUMBER_INPUT = ("#OtherBatchNumber")
BATCH_NUMBER_PREFIX_INPUT = ("#CovidBatchNumberPrefix")
BATCH_NUMBER_SUFFIX_INPUT = ("#CovidBatchNumberSuffix")
EXPIRY_DAY_INPUT = ("#ExpiryDate_1")
EXPIRY_MONTH_INPUT = ("#ExpiryDate_2")
EXPIRY_YEAR_INPUT = ("#ExpiryDate_3")
ADD_BATCH_BUTTON = ("role", "link", "Add batch")
BACK_BUTTON_ON_VACCINE_BATCHES_PAGE = ("role", "link", "Back", True)
CONTINUE_TO_CHECK_AND_CONFIRM_VACCINE_BATCH_BUTTON = ("role", "button", "Continue")
BATCH_NUMBER_INPUT_FIELD = ("label", "Batch number")
EXPIRY_DATE_DAY_INPUT_FIELD = ("placeholder", "DD")
EXPIRY_DATE_MONTH_INPUT_FIELD = ("placeholder", "MM")
EXPIRY_DATE_YEAR_INPUT_FIELD = ("placeholder", "YYYY")
ADD_BATCH_TITLE = ("role", "heading", "Add batch")
CONTINUE_TO_CONFIRM_BATCH_BUTTON = ("role", "button", "Continue")
ERROR_MESSAGE_BATCH_ALREADY_EXISTS = ("text", "Error: There is already a batch with this number and expiry date")
Expand All @@ -15,6 +16,10 @@
ERROR_MESSAGE_LINK_ENTER_THE_BATCH_NUMBER = ("role", "button", "Enter the batch number")
ERROR_MESSAGE_LINK_ENTER_THE_BATCH_EXPIRY_DATE = ("role", "button", "Enter the expiry date")

def click_add_batch_button():
wait_for_element_to_appear(ADD_BATCH_BUTTON)
find_element_and_perform_action(ADD_BATCH_BUTTON, "click")

def check_batch_already_exists_error_message_is_displayed():
wait_for_element_to_appear(ERROR_MESSAGE_BATCH_ALREADY_EXISTS)
return check_element_exists(ERROR_MESSAGE_BATCH_ALREADY_EXISTS, False)
Expand Down Expand Up @@ -48,25 +53,21 @@ def check_add_batch_title_exists(wait):
return check_element_exists(ADD_BATCH_TITLE, wait)

def enter_batch_number(batch_number):
wait_for_element_to_appear(VACCINE_BATCH_NUMBER_INPUT)
if check_element_exists(VACCINE_BATCH_NUMBER_INPUT, False):
find_element_and_perform_action(VACCINE_BATCH_NUMBER_INPUT, "input_text", batch_number)
else:
prefix, suffix = batch_number.split('-')
find_element_and_perform_action(BATCH_NUMBER_PREFIX_INPUT, "input_text", prefix)
find_element_and_perform_action(BATCH_NUMBER_SUFFIX_INPUT, "input_text", suffix)
wait_for_element_to_appear(BATCH_NUMBER_INPUT_FIELD)
if check_element_exists(BATCH_NUMBER_INPUT_FIELD, False):
find_element_and_perform_action(BATCH_NUMBER_INPUT_FIELD, "input_text", batch_number)

def enter_vaccine_batch_number(batch_number):
wait_for_element_to_appear(VACCINE_BATCH_NUMBER_INPUT)
find_element_and_perform_action(VACCINE_BATCH_NUMBER_INPUT, "input_text", batch_number)
wait_for_element_to_appear(BATCH_NUMBER_INPUT_FIELD)
find_element_and_perform_action(BATCH_NUMBER_INPUT_FIELD, "input_text", batch_number)

def enter_expiry_date(expiry_date):
try:
day, month, year = expiry_date.split('/')
wait_for_element_to_appear(EXPIRY_DAY_INPUT)
find_element_and_perform_action(EXPIRY_DAY_INPUT, "input_text", day)
find_element_and_perform_action(EXPIRY_MONTH_INPUT, "input_text", month)
find_element_and_perform_action(EXPIRY_YEAR_INPUT, "input_text", year)
wait_for_element_to_appear(EXPIRY_DATE_DAY_INPUT_FIELD)
find_element_and_perform_action(EXPIRY_DATE_DAY_INPUT_FIELD, "input_text", day)
find_element_and_perform_action(EXPIRY_DATE_MONTH_INPUT_FIELD, "input_text", month)
find_element_and_perform_action(EXPIRY_DATE_YEAR_INPUT_FIELD, "input_text", year)
except ValueError:
raise ValueError("Invalid expiry date format. Please use the format 'dd/MM/yyyy'.")

Expand Down
3 changes: 3 additions & 0 deletions pages/vaccines_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
add_batch_link = "//a[text()='Add batch']"
filter_by_site_dropdown = ("label", "Select site")

def click_view_product_link(vaccine):
click_link_in_row(vaccine, 0)

def click_first_available_view_product_link():
xpath = "(//tr[@role='row']//a[contains(text(),'View product')])[1]"
find_element_and_perform_action(("xpath", xpath), "click")
Expand Down
6 changes: 2 additions & 4 deletions tests/test_add_vaccine_batches_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ def i_click_confirm_button():

@when("I view product for the existing vaccine in an existing site")
def view_product_for_site_and_vaccine_type(shared_data):
click_first_available_view_product_link()
shared_data["batch_number"] = get_first_active_batch_number_value()
click_view_product_link("Comirnaty 10 JN.1")

@when(parse("I enter {batch_number} that already exists and {expiry_date}"))
def i_enter_batchnumber_and_expirydate(shared_data, batch_number, expiry_date):
click_add_batch_link()
click_add_batch_button()
enter_batch_number(batch_number)
# expiry_date = format_date(str(get_date_value("today+365")), config["browser"])
enter_expiry_date(expiry_date)
attach_screenshot("entered_batch_number")

Expand Down
Loading
Loading