diff --git a/conftest.py b/conftest.py index aa6b2209d..7ce2e55fb 100644 --- a/conftest.py +++ b/conftest.py @@ -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() diff --git a/features/reports.feature b/features/reports.feature index 8a8e40834..ffd567d19 100644 --- a/features/reports.feature +++ b/features/reports.feature @@ -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 + 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 | + | neelima.guntupalli1+no_location_sites@nhs.net | diff --git a/pages/reports_date_range_selection_page.py b/pages/reports_date_range_selection_page.py index 45724bf16..bf0337d58 100644 --- a/pages/reports_date_range_selection_page.py +++ b/pages/reports_date_range_selection_page.py @@ -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)") @@ -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") diff --git a/pages/site_vaccine_batches_page.py b/pages/site_vaccine_batches_page.py index fcfad82f1..621762344 100644 --- a/pages/site_vaccine_batches_page.py +++ b/pages/site_vaccine_batches_page.py @@ -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) diff --git a/pages/site_vaccines_add_batch_page.py b/pages/site_vaccines_add_batch_page.py index 570d3dabc..ab1c67b6d 100644 --- a/pages/site_vaccines_add_batch_page.py +++ b/pages/site_vaccines_add_batch_page.py @@ -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") @@ -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) @@ -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'.") diff --git a/pages/vaccines_page.py b/pages/vaccines_page.py index 0f429de59..05089d926 100644 --- a/pages/vaccines_page.py +++ b/pages/vaccines_page.py @@ -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") diff --git a/tests/test_add_vaccine_batches_steps.py b/tests/test_add_vaccine_batches_steps.py index fffcbe3c8..8bb6061fe 100644 --- a/tests/test_add_vaccine_batches_steps.py +++ b/tests/test_add_vaccine_batches_steps.py @@ -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") diff --git a/tests/test_reports_steps.py b/tests/test_reports_steps.py index 706f7ae1a..b24990ef2 100644 --- a/tests/test_reports_steps.py +++ b/tests/test_reports_steps.py @@ -2,7 +2,7 @@ import secrets import string from pytest_bdd import given, when, then, scenarios, scenario -from pytest_bdd.parsers import parse, cfparse +from pytest_bdd.parsers import parse from pages.login_page import * from pages.home_page import * from pages.nhs_signin_page import * @@ -24,11 +24,11 @@ def shared_data(): @pytest.mark.reports @given("I am logged into the RAVS app") -def logged_into_ravs_app(): +def logged_into_ravs_app(navigate_and_login): pass @when("I click the reports navigation link") -def I_click_reports_nav_link(navigate_and_login): +def I_click_reports_nav_link(): click_reports_nav_link() attach_screenshot("reports_navigation_link_clicked") logging.info("logged_in_and_reports_navigation_link_clicked") @@ -38,3 +38,32 @@ def the_reports_page_should_be_displayed(): assert check_create_report_button_exists() == True attach_screenshot("reports_page_loads_and_create_report_button_is_visible") logging.info("reports_page_loads_and_create_report_button_is_visible") + +@when("I click the create report button") +def I_click_create_report_button(): + click_create_report_button() + attach_screenshot("create_report_button_is_clicked") + logging.info("logged_in_and_reports_navigation_link_clicked") + +@then("the choose dates page should be displayed") +def the_choose_dates_page_should_be_displayed(): + assert check_today_radio_button_exists() == True + attach_screenshot("choose_dates_range_page_should_be_displayed") + logging.info("choose_dates_range_page_should_be_displayed") + + +@given(parse('I am logged into the RAVS app with the {username}')) +def logged_into_ravs_app_with_username(username): + navigate_and_login_with_username(username) + +@then("the `No vaccination data to report on` message should be displayed") +def the_choose_dates_page_should_be_displayed(): + assert check_no_vaccination_data_to_report_message_exists() == True + attach_screenshot("no_vaccination_data_to_report_message_exists") + logging.info("no_vaccination_data_to_report_message should be visible") + +@then("the Create report button should be disabled") +def the_choose_dates_page_should_be_displayed(): + assert check_create_report_button_enabled() == False + attach_screenshot("Create report button should be disabled") + logging.info("Create report button should be disabled")