|
1 | 1 | import pytest
|
| 2 | +from pytest_bdd import given, when, then, scenarios, scenario |
| 3 | +from pytest_bdd.parsers import parse |
2 | 4 | # from pages.add_vaccines_page import *
|
| 5 | +from pages.check_and_confirm_vaccinated_record_page import * |
| 6 | +from pages.delete_vaccination_page import * |
3 | 7 | from pages.settings_page import *
|
4 | 8 | from pages.site_vaccine_batches_page import *
|
5 | 9 | from pages.vaccines_page import *
|
|
24 | 28 | from datetime import datetime, timedelta
|
25 | 29 | from allure_commons.types import LabelType
|
26 | 30 | import logging
|
| 31 | +from test_data.get_values_from_models import * |
27 | 32 |
|
28 | 33 | # Define marks
|
29 | 34 | pytest.mark.login = pytest.mark.mark(login=True)
|
@@ -52,20 +57,6 @@ def format_nhs_number(nhs_number):
|
52 | 57 | formatted_number = re.sub(r"(\d{3})(\d{3})(\d{4})", r"\1 \2 \3", nhs_number)
|
53 | 58 | return formatted_number
|
54 | 59 |
|
55 |
| - |
56 |
| -# @pytest.fixture(scope='function') |
57 |
| -# def playwright_helper(request): |
58 |
| -# helper = PlaywrightHelper(get_working_directory(), config) |
59 |
| -# def teardown(): |
60 |
| -# try: |
61 |
| -# helper.quit_browser() |
62 |
| -# except Exception as e: |
63 |
| -# print(f"An error occurred during teardown: {e}") |
64 |
| -# raise |
65 |
| - |
66 |
| -# request.addfinalizer(teardown) |
67 |
| -# return helper |
68 |
| - |
69 | 60 | # Fixture for site parameter
|
70 | 61 | @pytest.fixture(params=["NEELIMA HOUSE", "ALBERT HOUSE", "ST JOHN'S HOUSE"])
|
71 | 62 | def site(request):
|
@@ -430,3 +421,162 @@ def navigate_and_login_with_username(username):
|
430 | 421 | attach_screenshot("entered_password")
|
431 | 422 | click_nhs_signin_button()
|
432 | 423 | attach_screenshot("clicked_nhs_signin_button")
|
| 424 | + |
| 425 | +@given(parse("I login to RAVS and set vaccinator details with {site} and {care_model} and get patient details for {nhs_number} with option {index} and choose to vaccinate with vaccine details as {chosen_vaccine}, {batch_number} with {batch_expiry_date}")) |
| 426 | +def step_login_to_ravs(site, care_model, nhs_number, index, chosen_vaccine, batch_number, batch_expiry_date, shared_data): |
| 427 | + shared_data["nhs_number"] = nhs_number |
| 428 | + shared_data["index"] = index |
| 429 | + shared_data["chosen_vaccine"] = chosen_vaccine |
| 430 | + shared_data["chosen_vaccine_type"] = get_vaccination_type(index, chosen_vaccine) |
| 431 | + shared_data["batch_number"] = batch_number |
| 432 | + shared_data["site"] = site |
| 433 | + shared_data["care_model"] = get_care_model(index) |
| 434 | + |
| 435 | + today_str = datetime.today().strftime('%d/%m/%Y') |
| 436 | + today = datetime.strptime(today_str, '%d/%m/%Y') |
| 437 | + if datetime.strptime(batch_expiry_date, '%d/%m/%Y') <= today: |
| 438 | + batch_expiry_date = today + timedelta(days=7) |
| 439 | + batch_expiry_date = standardize_date_format(batch_expiry_date) |
| 440 | + shared_data["batch_expiry_date"] = batch_expiry_date |
| 441 | + check_vaccine_and_batch_exists_in_site(site, chosen_vaccine, shared_data["chosen_vaccine_type"], batch_number, batch_expiry_date) |
| 442 | + return shared_data |
| 443 | + |
| 444 | +@given("I search for a patient with the NHS number in the find a patient screen") |
| 445 | +@then("I search for a patient with the NHS number in the find a patient screen") |
| 446 | +def step_search_for_patient(shared_data): |
| 447 | + nhs_number = shared_data["nhs_number"] |
| 448 | + click_find_a_patient_and_search_with_nhs_number(nhs_number) |
| 449 | + |
| 450 | +@given(parse("I open the patient record by clicking on patient {name}")) |
| 451 | +@then(parse("I open the patient record by clicking on patient {name}")) |
| 452 | +def step_search_for_patient(shared_data, name): |
| 453 | + attach_screenshot("before_clicking_patient_name") |
| 454 | + click_on_patient_name(name) |
| 455 | + attach_screenshot("before_clicking_patient_name") |
| 456 | + shared_data["patient_name"] = name |
| 457 | + |
| 458 | +@when(parse("I click choose vaccine button and choose the {chosen_vaccine}, {batch_number} with {batch_expiry_date} and click continue")) |
| 459 | +def step_choose_vaccine_and_vaccine_type(shared_data, chosen_vaccine, batch_number, batch_expiry_date): |
| 460 | + time.sleep(3) |
| 461 | + immunisation_history_records_count_before_vaccination = click_on_patient_search_result_and_click_choose_vaccine(shared_data['patient_name'], chosen_vaccine) |
| 462 | + shared_data["immunisation_history_records_count_before_vaccination"] = immunisation_history_records_count_before_vaccination |
| 463 | + choose_vaccine_and_vaccine_type_for_patient(shared_data['site'], chosen_vaccine, shared_data['chosen_vaccine_type']) |
| 464 | + |
| 465 | +@when(parse("I assess the patient's {eligibility} with the details and date as {assess_date} and click continue to record consent screen button")) |
| 466 | +def step_assess_eligibility_and_click_continue_record_consent_screen(shared_data, eligibility, assess_date): |
| 467 | + shared_data['eligible_decision'] = eligibility |
| 468 | + shared_data['legal_mechanism'] = get_legal_mechanism(shared_data["index"]) |
| 469 | + shared_data['eligibility_type'] = get_eligibility_type(shared_data["index"], shared_data["chosen_vaccine"]) |
| 470 | + shared_data["healthcare_worker"] = get_staff_role(shared_data["index"]) |
| 471 | + shared_data['eligibility_assessing_clinician'] = get_random_assessing_clinician() |
| 472 | + assess_date = format_date(str(get_date_value(assess_date)), config["browser"]) |
| 473 | + shared_data['eligibility_assessment_date'] = assess_date |
| 474 | + shared_data['eligibility_assessment_outcome'] = get_assessment_outcome(0) |
| 475 | + shared_data['eligibility_assessment_no_vaccine_given_reason'] = get_assess_vaccine_not_given_reason(shared_data["index"]) |
| 476 | + shared_data['assessment_comments'] = "Assessment comments " + assess_date + shared_data["patient_name"] |
| 477 | + assess_patient_with_details_and_click_continue_to_consent(eligibility, shared_data['eligibility_type'], shared_data["healthcare_worker"], shared_data['eligibility_assessing_clinician'], None, assess_date, shared_data['legal_mechanism'], shared_data['eligibility_assessment_outcome'], shared_data['assessment_comments'],shared_data['eligibility_assessment_no_vaccine_given_reason']) |
| 478 | + |
| 479 | +@when(parse("I assess the pregnant patient's {eligibility} with the details of due date as {due_date} and assessment date as {assess_date} and click continue to record consent screen button")) |
| 480 | +def step_assess_eligibility_and_click_continue_record_consent_screen(shared_data, eligibility, due_date, assess_date): |
| 481 | + shared_data['eligible_decision'] = eligibility |
| 482 | + shared_data['legal_mechanism'] = get_legal_mechanism(shared_data["index"]) |
| 483 | + shared_data['eligibility_type'] = "Pregnancy" |
| 484 | + shared_data["healthcare_worker"] = get_staff_role(shared_data["index"]) |
| 485 | + shared_data['eligibility_assessing_clinician'] = get_random_assessing_clinician() |
| 486 | + due_date = format_date(str(get_date_value(due_date)), config["browser"]) |
| 487 | + shared_data['eligibility_due_date'] = due_date |
| 488 | + assess_date = format_date(str(get_date_value(assess_date)), config["browser"]) |
| 489 | + shared_data['eligibility_assessment_date'] = assess_date |
| 490 | + shared_data['eligibility_assessment_outcome'] = get_assessment_outcome(0) |
| 491 | + shared_data['eligibility_assessment_no_vaccine_given_reason'] = get_assess_vaccine_not_given_reason(shared_data["index"]) |
| 492 | + shared_data['assessment_comments'] = "Assessment comments " + assess_date + shared_data["patient_name"] |
| 493 | + assess_patient_with_details_and_click_continue_to_consent(eligibility, shared_data['eligibility_type'], shared_data["healthcare_worker"], shared_data['eligibility_assessing_clinician'], due_date, assess_date, shared_data['legal_mechanism'], shared_data['eligibility_assessment_outcome'], shared_data['assessment_comments'],shared_data['eligibility_assessment_no_vaccine_given_reason']) |
| 494 | + |
| 495 | +@when(parse("I record {consent} with the details and click continue to vaccinate button")) |
| 496 | +def step_record_consent_and_click_continue_to_vaccinate_screen(shared_data, consent): |
| 497 | + shared_data['consent_decision'] = consent |
| 498 | + if shared_data["eligibility_assessment_outcome"].lower() == "give vaccine": |
| 499 | + shared_data['consent_given_by'] = get_consent_given_by(shared_data["index"]) |
| 500 | + name_of_person_consenting = "Automation tester" |
| 501 | + relationship_to_patient = "RAVS tester" |
| 502 | + if shared_data['legal_mechanism'] == "Patient Group Direction (PGD)": |
| 503 | + shared_data['consent_clinician_details'] = shared_data['eligibility_assessing_clinician'] |
| 504 | + else: |
| 505 | + shared_data['consent_clinician_details'] = get_consenting_clinician(shared_data["index"]) |
| 506 | + shared_data["no_consent_reason"] = get_no_consent_reason(shared_data["index"]) |
| 507 | + record_consent_details_and_click_continue_to_vaccinate(shared_data['consent_decision'],shared_data['consent_given_by'], name_of_person_consenting, relationship_to_patient, shared_data['consent_clinician_details'], shared_data['legal_mechanism'], shared_data["no_consent_reason"]) |
| 508 | + |
| 509 | +@when(parse("I record {vaccination} details and date as {vaccination_date} and click Continue to Check and confirm screen")) |
| 510 | +def step_enter_vaccination_details_and_continue_to_check_and_confirm_screen(shared_data, vaccination, vaccination_date): |
| 511 | + shared_data["vaccinated_decision"] = vaccination |
| 512 | + if shared_data["consent_decision"].lower() == "yes": |
| 513 | + if shared_data["eligibility_assessment_outcome"].lower() == "give vaccine": |
| 514 | + shared_data["vaccination_date"] = format_date(str(get_date_value(vaccination_date)), config["browser"]) |
| 515 | + chosen_vaccine = shared_data["chosen_vaccine"] |
| 516 | + shared_data["vaccination_site"] = get_vaccination_site(shared_data["index"]) |
| 517 | + shared_data["dose_amount"] = str(get_vaccine_dose_amount(shared_data["chosen_vaccine_type"])) |
| 518 | + if shared_data['legal_mechanism'] == "Patient Group Direction (PGD)": |
| 519 | + shared_data['vaccinator'] = shared_data['eligibility_assessing_clinician'] |
| 520 | + else: |
| 521 | + shared_data["vaccinator"] = get_vaccinator(shared_data["index"]) |
| 522 | + shared_data["vaccination_comments"] = shared_data["chosen_vaccine_type"] + "vaccination given on " + shared_data["vaccination_date"] + " for " + shared_data["patient_name"] |
| 523 | + shared_data["no_vaccination_reason"] = get_vaccination_not_given_reason(shared_data["index"]) |
| 524 | + enter_vaccine_details_and_click_continue_to_check_and_confirm(shared_data["vaccinated_decision"], shared_data["care_model"], shared_data["vaccination_date"], chosen_vaccine, shared_data["chosen_vaccine_type"], shared_data["vaccination_site"], shared_data["batch_number"], shared_data["batch_expiry_date"], shared_data["dose_amount"], shared_data["vaccinator"], shared_data["vaccination_comments"], shared_data["legal_mechanism"], shared_data["no_vaccination_reason"]) |
| 525 | + attach_screenshot("entered_vaccination_details") |
| 526 | + logging.info(shared_data) |
| 527 | + |
| 528 | +@then(parse("I need to be able to see the patient {name}, {dob}, {address} and vaccination details on the check and confirm screen")) |
| 529 | +def step_see_patient_details_on_check_and_confirm_screen(shared_data, name, dob, address): |
| 530 | + if shared_data["vaccinated_decision"].lower() == "Yes".lower() and shared_data["consent_decision"].lower() == "Yes".lower() and shared_data["eligibility_assessment_outcome"].lower() == "Give vaccine".lower(): |
| 531 | + attach_screenshot("check_and_confirm_screen_before_assertion") |
| 532 | + assert get_patient_name_value() == shared_data["patient_name"] |
| 533 | + assert get_patient_address_value() == address |
| 534 | + assert get_patient_vaccination_dose_amount_value() == shared_data["dose_amount"] |
| 535 | + assert get_patient_vaccinated_chosen_vaccine_value() == shared_data["chosen_vaccine"] |
| 536 | + assert get_patient_vaccinated_chosen_vaccine_product_value() == shared_data["chosen_vaccine_type"] |
| 537 | + assert get_patient_eligibility_assessment_date_value() == date_format_with_day_of_week(shared_data['eligibility_assessment_date']) |
| 538 | + assert get_patient_vaccinated_date_value() == date_format_with_day_of_week(shared_data['vaccination_date']) |
| 539 | + assert get_patient_dob_value() == date_format_with_age(dob) |
| 540 | + assert get_patient_vaccination_batch_expiry_date_value() == date_format_with_name_of_month(shared_data['batch_expiry_date']) |
| 541 | + assert get_patient_eligibility_assessing_clinician_vaccine_value() == shared_data['eligibility_assessing_clinician'] |
| 542 | + assert get_patient_consent_recorded_by_clinician_value() == shared_data['consent_clinician_details'] |
| 543 | + assert get_patient_vaccination_vaccinator_value() == shared_data['vaccinator'] |
| 544 | + attach_screenshot("check_and_confirm_screen_after_assertion") |
| 545 | + |
| 546 | +@then("when I click confirm and save button, I should see a record saved dialogue") |
| 547 | +def click_confirm_and_save_button_record_saved(shared_data): |
| 548 | + attach_screenshot("patient_details_screen_with_immunisation_history") |
| 549 | + click_confirm_details_and_save_button() |
| 550 | + attach_screenshot("before_assert_record_saved") |
| 551 | + assert check_record_saved_element_exists(False) |
| 552 | + |
| 553 | +@then("the immunisation history of the patient should be updated in the patient details page") |
| 554 | +def immunisation_history_should_be_updated(shared_data): |
| 555 | + attach_screenshot("immunisation_history_records_count_after_vaccination") |
| 556 | + immunisation_history_records_count_after_vaccination = get_count_of_immunisation_history_records(shared_data["chosen_vaccine"]) |
| 557 | + assert int(immunisation_history_records_count_after_vaccination) >= int(shared_data["immunisation_history_records_count_before_vaccination"]) + 1 |
| 558 | + click_delete_history_link(shared_data["chosen_vaccine"]) |
| 559 | + attach_screenshot("click_delete_history_link") |
| 560 | + click_delete_vaccination_button() |
| 561 | + attach_screenshot("click_delete_vaccination_button") |
| 562 | + shared_data.clear() |
| 563 | + |
| 564 | +@then("the immunisation history of the patient should be updated in the patient details page and not be deleted") |
| 565 | +def immunisation_history_should_be_updated(shared_data): |
| 566 | + attach_screenshot("immunisation_history_records_count_after_vaccination") |
| 567 | + immunisation_history_records_count_after_vaccination = get_count_of_immunisation_history_records(shared_data["chosen_vaccine"]) |
| 568 | + assert int(immunisation_history_records_count_after_vaccination) >= int(shared_data["immunisation_history_records_count_before_vaccination"]) + 1 |
| 569 | + |
| 570 | +@then("when I click confirm and save button, the immunisation history of the patient should be updated in the patient details page") |
| 571 | +def click_confirm_and_save_button_immunisation_history_should_be_updated(shared_data): |
| 572 | + attach_screenshot("patient_details_screen_with_immunisation_history") |
| 573 | + if shared_data["vaccinated_decision"].lower() == "yes" and shared_data["consent_decision"].lower() == "yes" and shared_data["eligibility_assessment_outcome"].lower() == "give vaccine": |
| 574 | + click_confirm_details_and_save_button() |
| 575 | + immunisation_history_records_count_after_vaccination = get_count_of_immunisation_history_records(shared_data["chosen_vaccine"]) |
| 576 | + assert int(immunisation_history_records_count_after_vaccination) >= int(shared_data["immunisation_history_records_count_before_vaccination"]) + 1 |
| 577 | + shared_data.clear() |
| 578 | + else: |
| 579 | + immunisation_history_records_count_after_vaccination = get_count_of_immunisation_history_records(shared_data["chosen_vaccine"]) |
| 580 | + assert int(immunisation_history_records_count_after_vaccination) == int(shared_data["immunisation_history_records_count_before_vaccination"]) |
| 581 | + shared_data.clear() |
| 582 | + attach_screenshot("patient_details_screen_with_immunisation_history") |
0 commit comments