Skip to content

Commit

Permalink
Dashboard verification
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaymudholkar1 committed Oct 24, 2024
1 parent 7414dec commit 1e095e8
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 111 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/MAVIS_TEST.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ jobs:
run: |
echo "Starting tests on Chromium"
pytest --browser_or_device chromium
echo "Starting tests on Chrome"
pytest --browser_or_device chrome
# echo "Starting tests on Chrome"
# pytest --browser_or_device chrome
# echo "Starting tests on Firefox"
# pytest --browser_or_device firefox
echo "Starting tests on iPhone 12"
pytest --browser_or_device iphone_12
echo "Starting tests on iPhone 11"
pytest --browser_or_device iphone_11
echo "Starting tests on Pixel 5"
pytest --browser_or_device pixel_5
# echo "Starting tests on iPhone 12"
# pytest --browser_or_device iphone_12
# echo "Starting tests on iPhone 11"
# pytest --browser_or_device iphone_11
# echo "Starting tests on Pixel 5"
# pytest --browser_or_device pixel_5
- name: Upload report
uses: actions/upload-artifact@v4
with:
Expand Down
48 changes: 30 additions & 18 deletions libs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class actions:
CLICK_BUTTON = "click_button"
CLICK_LABEL = "click_label"
FILL = "fill"
TYPE = "type"
RADIO_BUTTON_SELECT = "radio_select"
SELECT_FILE = "select_file"
SELECT_FROM_LIST = "select_from_list"
Expand Down Expand Up @@ -53,6 +54,7 @@ class wait_time:


class escape_characters:
SEPARATOR = "||" # Used only in code
SPACE = " "
NEW_LINE = "\n"
CARRIAGE_RETURN = "\r"
Expand All @@ -76,25 +78,35 @@ class escape_characters:
SINGLE_QUOTE_CLOSE,
TAB,
]
FILE_NAME = [COLON]
FILE_NAME = [SEPARATOR, COLON]


class test_data_file_paths:
PARENTAL_CONSENT = "test_data/ParentalConsent.xlsx"
VACCS_HPV_POSITIVE = "test_data/hpv/i_positive.csv||test_data/hpv/o_positive.csv"
VACCS_HPV_NEGATIVE = "test_data/hpv/i_negative.csv||test_data/hpv/o_negative.csv"
VACCS_HPV_DUP_1 = "test_data/hpv/i_dup_1.csv||test_data/hpv/o_dup_1.csv"
VACCS_HPV_DUP_2 = "test_data/hpv/i_dup_2.csv||test_data/hpv/o_dup_2.csv"
VACCS_HPV_INVALID_STRUCTURE = "test_data/hpv/i_invalid_structure.csv||test_data/hpv/o_invalid_structure.csv"
VACCS_HPV_EMPTY_FILE = "test_data/hpv/i_empty.csv||test_data/hpv/o_empty.csv"
VACCS_HPV_HEADER_ONLY = "test_data/hpv/i_header_only.csv||test_data/hpv/o_header_only.csv"
COHORTS_POSITIVE = "test_data/cohorts/i_positive.csv||test_data/cohorts/o_positive.csv"
COHORTS_NEGATIVE = "test_data/cohorts/i_negative.csv||test_data/cohorts/o_negative.csv"
COHORTS_INVALID_STRUCTURE = "test_data/cohorts/i_invalid_structure.csv||test_data/cohorts/o_invalid_structure.csv"
COHORTS_EMPTY_FILE = "test_data/cohorts/i_empty.csv||test_data/cohorts/o_empty.csv"
COHORTS_HEADER_ONLY = "test_data/cohorts/i_header_only.csv||test_data/cohorts/o_header_only.csv"
CHILD_POSITIVE = "test_data/child/i_positive.csv||test_data/child/o_positive.csv"
CHILD_NEGATIVE = "test_data/child/i_negative.csv||test_data/child/o_negative.csv"
CHILD_INVALID_STRUCTURE = "test_data/child/i_invalid_structure.csv||test_data/child/o_invalid_structure.csv"
CHILD_EMPTY_FILE = "test_data/child/i_empty.csv||test_data/child/o_empty.csv"
CHILD_HEADER_ONLY = "test_data/child/i_header_only.csv||test_data/child/o_header_only.csv"
VACCS_HPV_POSITIVE = f"test_data/hpv/i_positive.csv{escape_characters.SEPARATOR}test_data/hpv/o_positive.csv"
VACCS_HPV_NEGATIVE = f"test_data/hpv/i_negative.csv{escape_characters.SEPARATOR}test_data/hpv/o_negative.csv"
VACCS_HPV_DUP_1 = f"test_data/hpv/i_dup_1.csv{escape_characters.SEPARATOR}test_data/hpv/o_dup_1.csv"
VACCS_HPV_DUP_2 = f"test_data/hpv/i_dup_2.csv{escape_characters.SEPARATOR}test_data/hpv/o_dup_2.csv"
VACCS_HPV_INVALID_STRUCTURE = (
f"test_data/hpv/i_invalid_structure.csv{escape_characters.SEPARATOR}test_data/hpv/o_invalid_structure.csv"
)
VACCS_HPV_EMPTY_FILE = f"test_data/hpv/i_empty.csv{escape_characters.SEPARATOR}test_data/hpv/o_empty.csv"
VACCS_HPV_HEADER_ONLY = (
f"test_data/hpv/i_header_only.csv{escape_characters.SEPARATOR}test_data/hpv/o_header_only.csv"
)
COHORTS_POSITIVE = f"test_data/cohorts/i_positive.csv{escape_characters.SEPARATOR}test_data/cohorts/o_positive.csv"
COHORTS_NEGATIVE = f"test_data/cohorts/i_negative.csv{escape_characters.SEPARATOR}test_data/cohorts/o_negative.csv"
COHORTS_INVALID_STRUCTURE = f"test_data/cohorts/i_invalid_structure.csv{escape_characters.SEPARATOR}test_data/cohorts/o_invalid_structure.csv"
COHORTS_EMPTY_FILE = f"test_data/cohorts/i_empty.csv{escape_characters.SEPARATOR}test_data/cohorts/o_empty.csv"
COHORTS_HEADER_ONLY = (
f"test_data/cohorts/i_header_only.csv{escape_characters.SEPARATOR}test_data/cohorts/o_header_only.csv"
)
CHILD_POSITIVE = f"test_data/child/i_positive.csv{escape_characters.SEPARATOR}test_data/child/o_positive.csv"
CHILD_NEGATIVE = f"test_data/child/i_negative.csv{escape_characters.SEPARATOR}test_data/child/o_negative.csv"
CHILD_INVALID_STRUCTURE = (
f"test_data/child/i_invalid_structure.csv{escape_characters.SEPARATOR}test_data/child/o_invalid_structure.csv"
)
CHILD_EMPTY_FILE = f"test_data/child/i_empty.csv{escape_characters.SEPARATOR}test_data/child/o_empty.csv"
CHILD_HEADER_ONLY = (
f"test_data/child/i_header_only.csv{escape_characters.SEPARATOR}test_data/child/o_header_only.csv"
)
84 changes: 67 additions & 17 deletions libs/playwright_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,56 +50,106 @@ def get_object_property(self, locator: str, property: str, by_test_id: bool = Fa
elem.scroll_into_view_if_needed()
return "".join(elem.all_text_contents()).strip()
case object_properties.VISIBILITY:
elem = self.ce.page.get_by_role(locator).nth(0)
if escape_characters.SEPARATOR in locator:
_location = locator.split(escape_characters.SEPARATOR)[0]
_locator = locator.split(escape_characters.SEPARATOR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(0)
else:
elem = self.ce.page.get_by_role(locator).nth(0)
return elem.is_visible()

def perform_action(self, locator, action, value=None) -> None:
self.capture_screenshot(identifier=locator, action=f"before-{action}")
match action.lower():
case actions.CLICK_LINK:
elem = self.ce.page.get_by_role(playwright_roles.LINK, name=locator).nth(0)
if escape_characters.SEPARATOR in locator:
_location = locator.split(escape_characters.SEPARATOR)[0]
_locator = locator.split(escape_characters.SEPARATOR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(0)
else:
elem = self.ce.page.get_by_role(playwright_roles.LINK, name=locator).nth(0)
elem.scroll_into_view_if_needed()
elem.click()
case actions.CLICK_BUTTON:
elem = self.ce.page.get_by_role(playwright_roles.BUTTON, name=locator).nth(0)
if escape_characters.SEPARATOR in locator:
_location = locator.split(escape_characters.SEPARATOR)[0]
_locator = locator.split(escape_characters.SEPARATOR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(0)
else:
elem = self.ce.page.get_by_role(playwright_roles.BUTTON, name=locator).nth(0)
elem.scroll_into_view_if_needed()
elem.click()
case actions.CLICK_LABEL:
elem = self.ce.page.get_by_label(locator, exact=True).nth(0)
if escape_characters.SEPARATOR in locator:
_location = locator.split(escape_characters.SEPARATOR)[0]
_locator = locator.split(escape_characters.SEPARATOR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(0)
else:
elem = self.ce.page.get_by_label(locator, exact=True).nth(0)
elem.scroll_into_view_if_needed()
elem.click()
case actions.FILL:
elem = self.ce.page.get_by_label(locator, exact=True).nth(0)
case actions.FILL | actions.TYPE:
if escape_characters.SEPARATOR in locator:
_location = locator.split(escape_characters.SEPARATOR)[0]
_locator = locator.split(escape_characters.SEPARATOR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(0)
else:
elem = self.ce.page.get_by_label(locator, exact=True).nth(0)
elem.scroll_into_view_if_needed()
elem.click()
if value != data_values.EMPTY:
elem.fill(value)
self.capture_screenshot(identifier=locator, action=f"after-{action}")
case actions.RADIO_BUTTON_SELECT:
elem = self.ce.page.get_by_text(locator, exact=True).nth(0)
if escape_characters.SEPARATOR in locator:
_location = locator.split(escape_characters.SEPARATOR)[0]
_locator = locator.split(escape_characters.SEPARATOR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(0)
else:
elem = self.ce.page.get_by_text(locator, exact=True).nth(0)
elem.scroll_into_view_if_needed()
elem.click()
self.capture_screenshot(identifier=locator, action=f"after-{action}")
case actions.SELECT_FILE:
elem = self.ce.page.get_by_label(locator, exact=True).nth(0)
if escape_characters.SEPARATOR in locator:
_location = locator.split(escape_characters.SEPARATOR)[0]
_locator = locator.split(escape_characters.SEPARATOR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(0)
else:
elem = self.ce.page.get_by_label(locator, exact=True).nth(0)
elem.scroll_into_view_if_needed()
elem.set_input_files(value)
case actions.SELECT_FROM_LIST:
self.perform_action(locator=locator, action=actions.FILL, value=value)
elem = self.ce.page.get_by_role(playwright_roles.OPTION, name=value)
if escape_characters.SEPARATOR in locator:
_location = locator.split(escape_characters.SEPARATOR)[0]
_locator = locator.split(escape_characters.SEPARATOR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(0)
else:
elem = self.ce.page.get_by_role(playwright_roles.OPTION, name=value)
elem.click()
case actions.CHECKBOX_CHECK:
elem = self.ce.page.get_by_label(locator).nth(0)
if escape_characters.SEPARATOR in locator:
_location = locator.split(escape_characters.SEPARATOR)[0]
_locator = locator.split(escape_characters.SEPARATOR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(0)
else:
elem = self.ce.page.get_by_label(locator).nth(0)
elem.scroll_into_view_if_needed()
elem.check()
case actions.CLICK_LINK_INDEX_FOR_ROW:
elem = (
self.ce.page.get_by_role(
playwright_roles.ROW,
name=locator,
if escape_characters.SEPARATOR in locator:
_location = locator.split(escape_characters.SEPARATOR)[0]
_locator = locator.split(escape_characters.SEPARATOR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(0)
else:
elem = (
self.ce.page.get_by_role(
playwright_roles.ROW,
name=locator,
)
.get_by_role(playwright_roles.LINK)
.nth(value)
)
.get_by_role(playwright_roles.LINK)
.nth(value)
)
elem.scroll_into_view_if_needed()
elem.click()
2 changes: 1 addition & 1 deletion libs/testdata_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def clean_df(self, df: pd.DataFrame) -> pd.DataFrame:
return _df

def split_file_paths(self, file_paths: str) -> tuple[str, str]:
return file_paths.split("||")[0], file_paths.split("||")[1]
return file_paths.split(escape_characters.SEPARATOR)[0], file_paths.split(escape_characters.SEPARATOR)[1]
44 changes: 44 additions & 0 deletions pages/pg_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from libs import playwright_ops
from libs.constants import actions, escape_characters, object_properties


class pg_dashboard:
po = playwright_ops.playwright_operations()

LNK_PROGRAMMES = f"heading{escape_characters.SEPARATOR}Programmes"
LNK_VACCINES = f"heading{escape_characters.SEPARATOR}Vaccines"
LNK_SESSIONS = f"heading{escape_characters.SEPARATOR}Sessions"
LNK_CHILDREN = f"heading{escape_characters.SEPARATOR}Children"
LNK_NOTICES = f"heading{escape_characters.SEPARATOR}Important Notices"
LNK_ORGANISATION = f"heading{escape_characters.SEPARATOR}Your organisation"

def click_programmes(self):
self.po.perform_action(locator=self.LNK_PROGRAMMES, action=actions.CLICK_LINK)

def click_vaccines(self):
self.po.perform_action(locator=self.LNK_VACCINES, action=actions.CLICK_LINK)

def click_sessions(self):
self.po.perform_action(locator=self.LNK_SESSIONS, action=actions.CLICK_LINK)

def click_children(self):
self.po.perform_action(locator=self.LNK_CHILDREN, action=actions.CLICK_LINK)

def click_important_notices(self):
self.po.perform_action(locator=self.LNK_NOTICES, action=actions.CLICK_LINK)

def click_your_organisation(self):
self.po.perform_action(locator=self.LNK_ORGANISATION, action=actions.CLICK_LINK)

def verify_all_expected_links(self):
self.po.verify(locator=self.LNK_PROGRAMMES, property=object_properties.VISIBILITY, value=True, exact=True)
self.po.verify(locator=self.LNK_VACCINES, property=object_properties.VISIBILITY, value=True, exact=True)
self.po.verify(locator=self.LNK_SESSIONS, property=object_properties.VISIBILITY, value=True, exact=True)
self.po.verify(locator=self.LNK_CHILDREN, property=object_properties.VISIBILITY, value=True, exact=True)
self.po.verify(locator=self.LNK_NOTICES, property=object_properties.VISIBILITY, value=True, exact=True)
self.po.verify(
locator=self.LNK_ORGANISATION,
property=object_properties.VISIBILITY,
value=True,
exact=True,
)
15 changes: 0 additions & 15 deletions pages/pg_home.py

This file was deleted.

2 changes: 1 addition & 1 deletion pages/pg_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def click_login(self):
def verify_login_successful(self):
self.po.verify(locator=self.LBL_BANNER, property=object_properties.TEXT, value=self.LBL_USER)

def perform_login(self):
def perform_valid_login(self):
self.click_start()
self.enter_username(username=self.ce.login_username)
self.enter_password(password=self.ce.login_password)
Expand Down
12 changes: 10 additions & 2 deletions tests/test_1_login.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pytest

from pages import pg_login
from pages import pg_dashboard, pg_login


class Test_Regression_Login:
login_page = pg_login.pg_login()
home_page = pg_dashboard.pg_dashboard()

test_parameters = [
("invalid_user", "invalid_password", "Invalid Email or password."),
Expand All @@ -13,8 +14,15 @@ class Test_Regression_Login:
]

@pytest.mark.login
@pytest.mark.regression
@pytest.mark.mobile
@pytest.mark.order(101)
@pytest.mark.parametrize("user,pwd,expected_message", test_parameters)
def test_reg_invalid_login(self, create_browser_page, user, pwd, expected_message):
self.login_page.perform_invalid_login(user=user, pwd=pwd, expected_message=expected_message)

@pytest.mark.login
@pytest.mark.mobile
@pytest.mark.order(102)
def test_reg_home_page_links(self, create_browser_page):
self.login_page.perform_valid_login()
self.home_page.verify_all_expected_links()
22 changes: 8 additions & 14 deletions tests/test_2_vaccs_upload.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,54 @@
import pytest

from libs.constants import test_data_file_paths
from pages import pg_home, pg_login, pg_programmes
from pages import pg_dashboard, pg_login, pg_programmes


class Test_Regression_Vaccinations_Upload:
login_page = pg_login.pg_login()
home_page = pg_home.pg_home()
home_page = pg_dashboard.pg_dashboard()
programmes_page = pg_programmes.pg_programmes()

@pytest.mark.vaccinations
@pytest.mark.regression
@pytest.mark.order(201)
def test_reg_hpv_positive_file_upload(self, create_browser_page):
self.login_page.perform_login()
self.login_page.perform_valid_login()
self.home_page.click_programmes()
self.programmes_page.upload_hpv_vaccination_records(file_paths=test_data_file_paths.VACCS_HPV_POSITIVE)

@pytest.mark.vaccinations
@pytest.mark.regression
@pytest.mark.order(202)
def test_reg_hpv_negative_file_upload(self, create_browser_page):
self.login_page.perform_login()
self.login_page.perform_valid_login()
self.home_page.click_programmes()
self.programmes_page.upload_hpv_vaccination_records(file_paths=test_data_file_paths.VACCS_HPV_NEGATIVE)

@pytest.mark.vaccinations
@pytest.mark.regression
@pytest.mark.order(203)
def test_reg_hpv_duplicate_record_upload(self, create_browser_page):
self.login_page.perform_login()
self.login_page.perform_valid_login()
self.home_page.click_programmes()
self.programmes_page.upload_hpv_vaccination_records(file_paths=test_data_file_paths.VACCS_HPV_DUP_1)
self.home_page.click_programmes()
self.programmes_page.upload_hpv_vaccination_records(file_paths=test_data_file_paths.VACCS_HPV_DUP_2)

@pytest.mark.vaccinations
@pytest.mark.regression
@pytest.mark.order(204)
def test_reg_hpv_file_structure(self, create_browser_page):
self.login_page.perform_login()
self.login_page.perform_valid_login()
self.home_page.click_programmes()
self.programmes_page.upload_invalid_files(file_paths=test_data_file_paths.VACCS_HPV_INVALID_STRUCTURE)

@pytest.mark.vaccinations
@pytest.mark.regression
@pytest.mark.order(205)
def test_reg_hpv_no_record(self, create_browser_page):
self.login_page.perform_login()
self.login_page.perform_valid_login()
self.home_page.click_programmes()
self.programmes_page.upload_invalid_files(file_paths=test_data_file_paths.VACCS_HPV_HEADER_ONLY)

@pytest.mark.vaccinations
@pytest.mark.regression
@pytest.mark.order(206)
def test_reg_hpv_empty_file(self, create_browser_page):
self.login_page.perform_login()
self.login_page.perform_valid_login()
self.home_page.click_programmes()
self.programmes_page.upload_invalid_files(file_paths=test_data_file_paths.VACCS_HPV_EMPTY_FILE)
Loading

0 comments on commit 1e095e8

Please sign in to comment.