Skip to content
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
8 changes: 5 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from libs import CurrentExecution as ce
from libs import file_ops as fo
from libs.generic_constants import audit_log_paths, file_mode, fixture_scope
from libs.generic_constants import audit_log_paths, file_mode
from libs.mavis_constants import browsers_and_devices, playwright_constants
from libs.wrappers import *

Expand All @@ -14,7 +14,7 @@ def pytest_addoption(parser):
parser.addoption("--browser_or_device", action="store", default=browsers_and_devices.CHROMIUM)


@pytest.fixture(scope=fixture_scope.SESSION)
@pytest.fixture(scope="session")
def start_playwright_session(request):
ce.get_env_values()
ce.reset_environment()
Expand All @@ -26,7 +26,7 @@ def start_playwright_session(request):
# ce.reset_environment() # Clean up the environment after execution


@pytest.fixture(scope=fixture_scope.FUNCTION)
@pytest.fixture(scope="function")
def start_mavis(start_playwright_session):
_browser, _context = start_browser(pw=start_playwright_session, browser_or_device=ce.current_browser_name)
ce.browser = _browser
Expand All @@ -42,6 +42,8 @@ def create_session_screenshot_dir() -> str:
_session_name = f"{get_current_datetime()}-{ce.current_browser_name}"
fo.file_operations().create_dir(dir_path=f"screenshots/{_session_name}")
return f"screenshots/{_session_name}"
else:
return ""


def start_browser(pw, browser_or_device: str):
Expand Down
46 changes: 24 additions & 22 deletions libs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@
class CurrentExecution:
page = None
browser = None
service_url: str = ""
base_auth_username: str = ""
base_auth_password: str = ""
current_browser_name: str = ""
headless_mode: bool = False
session_screenshots_dir: str = ""
service_url: str | None = ""
base_auth_username: str | None = ""
base_auth_password: str | None = ""
current_browser_name: str | None = ""
headless_mode: bool | None = False
session_screenshots_dir: str | None = ""

capture_screenshot_flag: bool | None = False
nurse_username: str | None = ""
nurse_password: str | None = ""
superuser_username: str | None = ""
superuser_password: str | None = ""
admin_username: str | None = ""
admin_password: str | None = ""
reset_endpoint: str | None = ""
api_token: str | None = ""
reset_env_before_execution: bool | None = False
slow_motion: int | None = 0

screenshot_sequence: int = 0
capture_screenshot_flag: bool = False
nurse_username: str = ""
nurse_password: str = ""
superuser_username: str = ""
superuser_password: str = ""
admin_username: str = ""
admin_password: str = ""
reset_endpoint: str = ""
api_token: str = ""
reset_env_before_execution: bool = False
slow_motion: int = 0
child_list: list[str] = []
file_record_count: int = 0
session_id: str = ""
Expand All @@ -44,12 +46,12 @@ def get_env_values():
CurrentExecution.superuser_password = os.getenv("SUPERUSER_PASSWORD")
CurrentExecution.admin_username = os.getenv("ADMIN_USERNAME")
CurrentExecution.admin_password = os.getenv("ADMIN_PASSWORD")
CurrentExecution.headless_mode = os.getenv("HEADLESS").lower() == "true"
CurrentExecution.capture_screenshot_flag = os.getenv("CAPTURE_SCREENSHOTS").lower() == "true"
CurrentExecution.headless_mode = os.getenv("HEADLESS", "True").lower() == "true"
CurrentExecution.capture_screenshot_flag = os.getenv("CAPTURE_SCREENSHOTS", "True").lower() == "true"
CurrentExecution.reset_endpoint = f"{CurrentExecution.service_url}{os.getenv('RESET_ENDPOINT')}"
CurrentExecution.api_token = os.getenv("API_TOKEN")
CurrentExecution.reset_env_before_execution = os.getenv("RESET_ENV_BEFORE_EXECUTION").lower() == "true"
CurrentExecution.slow_motion = int(os.getenv("SLOW_MOTION"))
CurrentExecution.reset_env_before_execution = os.getenv("RESET_ENV_BEFORE_EXECUTION", "True").lower() == "true"
CurrentExecution.slow_motion = int(os.getenv("SLOW_MOTION", 0))

@staticmethod
def reset_environment():
Expand Down Expand Up @@ -80,5 +82,5 @@ def set_session_id(session_id: str):
CurrentExecution.session_id = session_id

@staticmethod
def get_session_id() -> int:
def get_session_id() -> str:
return CurrentExecution.session_id
8 changes: 6 additions & 2 deletions libs/file_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ def get_file_text(self, file_path: str) -> str:
str: Text content of the file.
"""
if self.check_if_path_exists(file_or_folder_path=file_path):
with open(file=file_path, mode=file_mode.READ) as f:
with open(file=file_path, mode=file_mode.READ, encoding="utf-8") as f:
return f.read()
else:
assert False, f"Cannot read file. File not found: {file_path}"

def read_csv_to_df(self, file_path: str) -> pd.DataFrame:
"""
Expand All @@ -64,6 +66,8 @@ def read_csv_to_df(self, file_path: str) -> pd.DataFrame:
"""
if self.check_if_path_exists(file_or_folder_path=file_path):
return pd.read_csv(filepath_or_buffer=file_path)
else:
assert False, f"Cannot read CSV file. File not found: {file_path}"

def read_excel_to_df(self, file_path: str, sheet_name: str) -> pd.DataFrame:
"""
Expand Down Expand Up @@ -93,6 +97,6 @@ def create_file(self, content: str, file_name_prefix: str = "") -> str:
str: Path to the created file.
"""
_file_name = f"working/{file_name_prefix}{get_current_datetime()}.csv"
with open(file=_file_name, mode=file_mode.WRITE) as f:
with open(file=_file_name, mode=file_mode.WRITE, encoding="utf-8") as f:
f.writelines(content)
return _file_name
60 changes: 28 additions & 32 deletions libs/generic_constants.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
from enum import Enum, auto
from typing import Final


class fixture_scope:
SESSION: Final[str] = "session"
FUNCTION: Final[str] = "function"


class element_properties:
TEXT: Final[str] = "text"
VISIBILITY: Final[str] = "visibility"
HREF: Final[str] = "href"
ELEMENT_EXISTS: Final[str] = "element_exists"
PAGE_URL: Final[str] = "page_url"
CHECKBOX_CHECKED: Final[str] = "checked"


class framework_actions:
CLICK_LINK: Final[str] = "click_link"
CLICK_BUTTON: Final[str] = "click_button"
CLICK_LABEL: Final[str] = "click_label"
CLICK_TEXT: Final[str] = "click_text"
FILL: Final[str] = "fill"
TYPE: Final[str] = "type"
RADIO_BUTTON_SELECT: Final[str] = "radio_select"
SELECT_FILE: Final[str] = "select_file"
SELECT_FROM_LIST: Final[str] = "select_from_list"
CHECKBOX_CHECK: Final[str] = "checkbox_check"
CHECKBOX_UNCHECK: Final[str] = "checkbox_uncheck"
CLICK_LINK_INDEX_FOR_ROW: Final[str] = "click_link_index_for_row"
CLICK_WILDCARD: Final[str] = "click_wildcard"
CHAIN_LOCATOR_ACTION: Final[str] = "chain_locator"
DOWNLOAD_FILE_USING_LINK: Final[str] = "download_file_using_link"
DOWNLOAD_FILE_USING_BUTTON: Final[str] = "download_file_using_button"
WAIT: Final[str] = "wait"
class element_properties(Enum):
TEXT = auto()
VISIBILITY = auto()
HREF = auto()
ELEMENT_EXISTS = auto()
PAGE_URL = auto()
CHECKBOX_CHECKED = auto()


class framework_actions(Enum):
CLICK_LINK = auto()
CLICK_BUTTON = auto()
CLICK_LABEL = auto()
CLICK_TEXT = auto()
FILL = auto()
TYPE = auto()
RADIO_BUTTON_SELECT = auto()
SELECT_FILE = auto()
SELECT_FROM_LIST = auto()
CHECKBOX_CHECK = auto()
CHECKBOX_UNCHECK = auto()
CLICK_LINK_INDEX_FOR_ROW = auto()
CLICK_WILDCARD = auto()
CHAIN_LOCATOR_ACTION = auto()
DOWNLOAD_FILE_USING_LINK = auto()
DOWNLOAD_FILE_USING_BUTTON = auto()
WAIT = auto()


class screenshot_actions:
Expand Down
28 changes: 16 additions & 12 deletions libs/mavis_constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum, auto
from typing import Final


Expand Down Expand Up @@ -34,11 +35,11 @@ class programmes:


class vaccines:
GARDASIL9: Final[str] = ("Gardasil9", 0) # HPV
MENQUADFI: Final[str] = ("MenQuadfi", 1) # MenACWY
MENVEO: Final[str] = ("Menveo", 2) # MenACWY
NIMENRIX: Final[str] = ("Nimenrix", 3) # MenACWY
REVAXIS: Final[str] = ("Revaxis", 4) # Td/IPV
GARDASIL9: Final[tuple[str, int]] = ("Gardasil9", 0) # HPV
MENQUADFI: Final[tuple[str, int]] = ("MenQuadfi", 1) # MenACWY
MENVEO: Final[tuple[str, int]] = ("Menveo", 2) # MenACWY
NIMENRIX: Final[tuple[str, int]] = ("Nimenrix", 3) # MenACWY
REVAXIS: Final[tuple[str, int]] = ("Revaxis", 4) # Td/IPV


class test_data_values:
Expand All @@ -49,12 +50,12 @@ class test_data_values:
EMPTY: Final[str] = "<empty>"


class mavis_file_types:
CHILD_LIST: Final[str] = "childlist"
COHORT: Final[str] = "cohort"
CLASS_LIST: Final[str] = "classlist"
VACCS_MAVIS: Final[str] = "vaccsmavis"
VACCS_SYSTMONE: Final[str] = "vaccssystmone"
class mavis_file_types(Enum):
CHILD_LIST = auto()
COHORT = auto()
CLASS_LIST = auto()
VACCS_MAVIS = auto()
VACCS_SYSTMONE = auto()


class record_limit:
Expand All @@ -80,6 +81,8 @@ class test_data_file_paths:
VACCS_SYSTMONE_POSITIVE: Final[str] = "VACCS_SYSTMONE_POSITIVE"
VACCS_SYSTMONE_NEGATIVE: Final[str] = "VACCS_SYSTMONE_NEGATIVE"
VACCS_SYSTMONE_HIST_NEGATIVE: Final[str] = "VACCS_SYSTMONE_HIST_NEGATIVE"
VACCS_MAV_1080: Final[str] = "VACCS_MAV_1080"
VACCS_SYSTMONE_MAV_1080: Final[str] = "VACCS_SYSTMONE_MAV_1080"
COHORTS_POSITIVE: Final[str] = "COHORTS_POSITIVE"
COHORTS_NEGATIVE: Final[str] = "COHORTS_NEGATIVE"
COHORTS_INVALID_STRUCTURE: Final[str] = "COHORTS_INVALID_STRUCTURE"
Expand All @@ -102,6 +105,7 @@ class test_data_file_paths:
CLASS_SINGLE_VACC: Final[str] = "CLASS_SINGLE_VACC"
CLASS_MAV_854: Final[str] = "CLASS_MAV_854"
CLASS_MAV_965: Final[str] = "CLASS_MAV_965"
CLASS_MAV_1080: Final[str] = "CLASS_MAV_1080"
COHORTS_NO_CONSENT: Final[str] = "COHORTS_NO_CONSENT"
COHORTS_CONFLICTING_CONSENT: Final[str] = "COHORTS_CONFLICTING_CONSENT"
COHORTS_E2E_1: Final[str] = "COHORTS_E2E_1"
Expand All @@ -119,7 +123,7 @@ class test_data_file_paths:

class report_headers:
CAREPLUS: Final[str] = (
"NHS Number,Surname,Forename,Date of Birth,Address Line 1,Person Giving Consent,Ethnicity,Date Attended,Time Attended,Venue Type,Venue Code,Staff Type,Staff Code,Attended,Reason Not Attended,Suspension End Date,Vaccine 1,Dose 1,Reason Not Given 1,Site 1,Manufacturer 1,Batch No 1,Vaccine 2,Dose 2,Reason Not Given 2,Site 2,Manufacturer 2,Batch No 2,Vaccine 3,Dose 3,Reason Not Given 3,Site 3,Manufacturer 3,Batch No 3,Vaccine 4,Dose 4,Reason Not Given 4,Site 4,Manufacturer 4,Batch No 4,Vaccine 5,Dose 5,Reason Not Given 5,Site 5,Manufacturer 5,Batch No 5"
"NHS Number,Surname,Forename,Date of Birth,Address Line 1,Person Giving Consent,Ethnicity,Date Attended,Time Attended,Venue Type,Venue Code,Staff Type,Staff Code,Attended,Reason Not Attended,Suspension End Date,Vaccine 1,Vaccine Code 1,Dose 1,Reason Not Given 1,Site 1,Manufacturer 1,Batch No 1,Vaccine 2,Vaccine Code 2,Dose 2,Reason Not Given 2,Site 2,Manufacturer 2,Batch No 2,Vaccine 3,Vaccine Code 3,Dose 3,Reason Not Given 3,Site 3,Manufacturer 3,Batch No 3,Vaccine 4,Vaccine Code 4,Dose 4,Reason Not Given 4,Site 4,Manufacturer 4,Batch No 4,Vaccine 5,Vaccine Code 5,Dose 5,Reason Not Given 5,Site 5,Manufacturer 5,Batch No 5"
)
CSV: Final[str] = (
"ORGANISATION_CODE,SCHOOL_URN,SCHOOL_NAME,CARE_SETTING,CLINIC_NAME,PERSON_FORENAME,PERSON_SURNAME,PERSON_DATE_OF_BIRTH,PERSON_DATE_OF_DEATH,YEAR_GROUP,PERSON_GENDER_CODE,PERSON_ADDRESS_LINE_1,PERSON_POSTCODE,NHS_NUMBER,NHS_NUMBER_STATUS_CODE,GP_ORGANISATION_CODE,GP_NAME,CONSENT_STATUS,CONSENT_DETAILS,HEALTH_QUESTION_ANSWERS,TRIAGE_STATUS,TRIAGED_BY,TRIAGE_DATE,TRIAGE_NOTES,GILLICK_STATUS,GILLICK_ASSESSMENT_DATE,GILLICK_ASSESSED_BY,GILLICK_ASSESSMENT_NOTES,GILLICK_NOTIFY_PARENTS,VACCINATED,DATE_OF_VACCINATION,TIME_OF_VACCINATION,PROGRAMME_NAME,VACCINE_GIVEN,PERFORMING_PROFESSIONAL_EMAIL,PERFORMING_PROFESSIONAL_FORENAME,PERFORMING_PROFESSIONAL_SURNAME,BATCH_NUMBER,BATCH_EXPIRY_DATE,ANATOMICAL_SITE,ROUTE_OF_VACCINATION,DOSE_SEQUENCE,REASON_NOT_VACCINATED,LOCAL_PATIENT_ID,SNOMED_PROCEDURE_CODE,REASON_FOR_INCLUSION,RECORD_CREATED,RECORD_UPDATED"
Expand Down
15 changes: 10 additions & 5 deletions libs/playwright_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def capture_screenshot(self, identifier: str, action: str) -> None:
)
self.ce.page.screenshot(path=_ss_path, type=screenshot_file_types.JPEG, full_page=True)

def verify(self, locator: str, property: str, expected_value: str, **kwargs) -> None:
def verify(self, locator: str, property: element_properties, expected_value: str, **kwargs) -> None:
"""
Verify a property of a web element.

Expand All @@ -61,7 +61,7 @@ def verify(self, locator: str, property: str, expected_value: str, **kwargs) ->
actual_value = self.get_element_property(
locator=locator, property=property, by_test_id=by_test_id, chain_locator=chain_locator
)
match property.lower():
match property:
case element_properties.TEXT:
if expected_value != "":
self._verify_text(
Expand All @@ -72,7 +72,7 @@ def verify(self, locator: str, property: str, expected_value: str, **kwargs) ->
case element_properties.CHECKBOX_CHECKED:
self._verify_checkbox(locator=locator, expected_value=expected_value, actual_value=actual_value)

def get_element_property(self, locator: str, property: str, **kwargs) -> str:
def get_element_property(self, locator: str, property: element_properties, **kwargs) -> str:
"""
Get a property of a web element.

Expand Down Expand Up @@ -105,7 +105,7 @@ def get_element_property(self, locator: str, property: str, **kwargs) -> str:
case element_properties.PAGE_URL:
return self.ce.page.url

def act(self, locator, action, value=None, **kwargs) -> None:
def act(self, locator: str | None, action: framework_actions, value: str | None = None, **kwargs) -> None:
"""
Perform an action on a web element.

Expand All @@ -115,11 +115,16 @@ def act(self, locator, action, value=None, **kwargs) -> None:
value (str, optional): Value to use for the action.
**kwargs: Additional options (e.g., exact match, index).
"""
# Error check
if locator is None:
locator = ""
if value is None:
value = ""
# Unpack keyword arguments
exact: bool = kwargs.get("exact", False)
index: int = kwargs.get("index", 0)
# Act
match action.lower():
match action:
case framework_actions.CLICK_LINK:
self._click_link(locator=locator, exact=exact, index=index)
case framework_actions.CLICK_BUTTON:
Expand Down
9 changes: 4 additions & 5 deletions libs/testdata_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def create_file_from_template(self, template_path: str, file_name_prefix: str) -
_ln = _ln.replace("<<SCHOOL_2_NAME>>", test_data_values.SCHOOL_2_NAME)
_ln = _ln.replace("<<SCHOOL_1_URN>>", test_data_values.SCHOOL_1_URN)
_ln = _ln.replace("<<ORG_CODE>>", test_data_values.ORG_CODE)
# _ln = _ln.replace("<<NHS_NO>>", f"9{self.get_new_nhs_no(valid=True)[:9]}")
_ln = _ln.replace("<<NHS_NO>>", self.get_new_nhs_no(valid=True))
_ln = _ln.replace("<<INVALID_NHS_NO>>", self.get_new_nhs_no(valid=False))
_ln = _ln.replace("<<FNAME>>", f"F{_dt}{_ctr}")
Expand Down Expand Up @@ -76,7 +75,7 @@ def get_new_nhs_no(self, valid=True) -> str:
"""
return nhs_number.generate(valid=valid, for_region=nhs_number.REGION_ENGLAND, quantity=1)[0]

def get_expected_errors(self, file_path: str) -> list[str]:
def get_expected_errors(self, file_path: str):
"""
Get expected errors from a file.

Expand Down Expand Up @@ -157,13 +156,13 @@ def create_child_list_from_file(self, file_path: str, file_type: str):
match file_type:
case mavis_file_types.CHILD_LIST | mavis_file_types.COHORT | mavis_file_types.CLASS_LIST:
_child_list = _file_df[["CHILD_FIRST_NAME", "CHILD_LAST_NAME"]]
return _child_list["CHILD_LAST_NAME"] + " " + _child_list["CHILD_FIRST_NAME"].values.tolist()
return _child_list["CHILD_LAST_NAME"] + ", " + _child_list["CHILD_FIRST_NAME"].values.tolist()
case mavis_file_types.VACCS_MAVIS:
_child_list = _file_df[["PERSON_FORENAME", "PERSON_SURNAME"]]
return _child_list["PERSON_SURNAME"] + " " + _child_list["PERSON_FIRSTNAME"].values.tolist()
return _child_list["PERSON_SURNAME"] + ", " + _child_list["PERSON_FIRSTNAME"].values.tolist()
case mavis_file_types.VACCS_SYSTMONE:
_child_list = _file_df[["First name", "Surname"]]
return _child_list["Surname"] + " " + _child_list["First name"].values.tolist()
return _child_list["Surname"] + ", " + _child_list["First name"].values.tolist()
case _:
return None

Expand Down
4 changes: 2 additions & 2 deletions libs/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_dob_from_year(year_group: str) -> str:

# Generate a random date between start_date and end_date
random_date = start_date + timedelta(days=random.randint(0, (end_date - start_date).days))
return random_date.strftime("%Y%m%d")
return random_date.strftime("%Y-%m-%d")


def get_project_root() -> str:
Expand Down Expand Up @@ -190,7 +190,7 @@ def get_base64_decoded_string(encoded_string: str) -> str:
return base64.b64decode(base64_bytes).decode(file_encoding.ASCII)


def run_shell_command(command: str) -> str:
def run_shell_command(command: str):
"""
Execute a shell command.

Expand Down
2 changes: 1 addition & 1 deletion pages/pg_children.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def verify_filter(self):
self.po.act(locator=None, action=framework_actions.WAIT, value=wait_time.MIN)
self.po.verify(locator=self.LBL_MAIN, property=element_properties.TEXT, expected_value=self.LBL_CHILD_RECORD)

def verify_child_has_been_uploaded(self, child_list: list[str]) -> None:
def verify_child_has_been_uploaded(self, child_list) -> None:
if len(child_list) >= 1:
self.dashboard_page.go_to_dashboard()
self.dashboard_page.click_children()
Expand Down
Loading
Loading