Skip to content

Commit

Permalink
vaccs batch
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaymudholkar1 committed Oct 22, 2024
1 parent f86a6f0 commit 34994eb
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 26 deletions.
2 changes: 2 additions & 0 deletions libs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class actions:
SELECT_FILE = "select_file"
SELECT_FROM_LIST = "select_from_list"
CHECKBOX_CHECK = "checkbox_check"
CLICK_LINK_INDEX_FOR_ROW = "click_link_index_for_row"


class screenshot_types:
Expand Down Expand Up @@ -42,6 +43,7 @@ class playwright_roles:
LINK = "link"
BUTTON = "button"
OPTION = "option"
ROW = "row"


class wait_time:
Expand Down
27 changes: 18 additions & 9 deletions libs/playwright_ops.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import os

from libs import CurrentExecution, testdata_ops
from libs import CurrentExecution
from libs.constants import (
actions,
data_values,
object_properties,
playwright_roles,
screenshot_types,
)
from libs.wrappers import *


class playwright_operations:
ce = CurrentExecution()
tdo = testdata_ops.testdata_operations()

def capture_screenshot(self, identifier: str, action: str) -> None:
if self.ce.capture_screenshot_flag:
self.ce.screenshot_sequence += 1
_ss_path = self.tdo.clean_file_name(
_ss_path = clean_file_name(
os.path.join(
self.ce.session_screenshots_dir,
f"{self.ce.screenshot_sequence}-{action}-{identifier}.{screenshot_types.JPEG}",
f"{self.ce.screenshot_sequence}-{action}-{identifier}-{self.ce.current_browser_name}.{screenshot_types.JPEG}",
)
)
self.ce.page.set_viewport_size({"width": 1500, "height": 1500})
# self.ce.page.set_viewport_size({"width": 1500, "height": 1500})
self.ce.page.screenshot(path=_ss_path, type=screenshot_types.JPEG)

def verify(self, locator: str, property: str, value: str, exact: bool = False, by_test_id: bool = False) -> None:
Expand All @@ -32,11 +32,9 @@ def verify(self, locator: str, property: str, value: str, exact: bool = False, b
self.capture_screenshot(identifier=locator, action="verify_text")
text = self.get_object_property(locator=locator, property=property, by_test_id=by_test_id)
if exact:
assert value == text, f"Exact match failed. Expected; '{value}' but actual '{text}'."
assert value == text, f"Exact match failed. Expected: '{value}' but actual: '{text}'."
else:
assert self.tdo.clean_text(text=value) in self.tdo.clean_text(
text=text
), f"Text '{value}' not found in '{text}'."
assert clean_text(text=value) in clean_text(text=text), f"Text '{value}' not found in '{text}'."
case object_properties.VISIBILITY:
self.capture_screenshot(identifier=locator, action="verify_visibility")
current_state = self.get_object_property(locator=locator, property=property, by_test_id=by_test_id)
Expand Down Expand Up @@ -94,3 +92,14 @@ def perform_action(self, locator, action, value=None) -> None:
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,
)
.get_by_role(playwright_roles.LINK)
.nth(value)
)
elem.scroll_into_view_if_needed()
elem.click()
10 changes: 0 additions & 10 deletions libs/testdata_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ def read_spreadsheet(self, file_path: str) -> pd.DataFrame:
_df = self.fo.read_excel_to_df(file_path=file_path)
return self.clean_df(df=_df)

def clean_text(self, text: str) -> str:
for _chr in escape_characters.UI_FORMATTING:
text = text.replace(_chr, "")
return text

def clean_file_name(self, file_name: str) -> str:
for _chr in escape_characters.FILE_NAME:
file_name = file_name.replace(_chr, "")
return file_name

def clean_df(self, df: pd.DataFrame) -> pd.DataFrame:
pd.set_option("future.no_silent_downcasting", True)
_df = df.fillna(value="0", inplace=False)
Expand Down
16 changes: 15 additions & 1 deletion libs/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import time
from datetime import datetime

from libs.constants import escape_characters


def convert_time_units_to_seconds(time_unit: str) -> int:
"""
Expand Down Expand Up @@ -38,5 +40,17 @@ def get_link_formatted_date_time():
return f"{_dt}{_ampm}"


def get_new_datetime(self) -> str:
def get_new_datetime() -> str:
return datetime.now().strftime("%Y%m%d%H%M%S")


def clean_text(text: str) -> str:
for _chr in escape_characters.UI_FORMATTING:
text = text.replace(_chr, "")
return text


def clean_file_name(file_name: str) -> str:
for _chr in escape_characters.FILE_NAME:
file_name = file_name.replace(_chr, "")
return file_name
6 changes: 5 additions & 1 deletion pages/pg_home.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from libs import playwright_ops
from libs.constants import object_properties, actions
from libs.constants import actions


class pg_home:
po = playwright_ops.playwright_operations()

LNK_PROGRAMMES = "Programmes"
LNK_VACCINES = "Vaccines"

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)
7 changes: 3 additions & 4 deletions pages/pg_login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from libs import playwright_ops
from libs.constants import object_properties, actions
from libs import CurrentExecution
from libs import CurrentExecution, playwright_ops
from libs.constants import actions, object_properties


class pg_login:
Expand Down Expand Up @@ -42,4 +41,4 @@ def perform_invalid_login(self, user: str, pwd: str, expected_message: str) -> s
self.enter_username(username=user)
self.enter_password(password=pwd)
self.click_login()
self.po.verify(locator=self.LBL_PARAGRAPH, property=object_properties.TEXT, value=expected_message)
self.po.verify(locator=self.LBL_PARAGRAPH, property=object_properties.TEXT, value=expected_message, exact=True)
62 changes: 62 additions & 0 deletions pages/pg_vaccines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from libs import playwright_ops
from libs.constants import actions, object_properties
from libs.wrappers import *


class pg_vaccines:
po = playwright_ops.playwright_operations()

LBL_VACCINE_NAME = "Gardasil 9 (HPV)"
LBL_VACCINE_MANUFACTURER = "Merck Sharp & Dohme"
LBL_MAIN = "main"
LBL_PARAGRAPH = "paragraph"
LBL_BATCH_ARCHIVED = "Batch archived."
LNK_ADD_NEW_BATCH = "Add a batch"
TXT_BATCH_NAME = "Batch"
TXT_EXPIRY_DAY = "Day"
TXT_EXPIRY_MONTH = "Month"
TXT_EXPIRY_YEAR = "Year"
BTN_ADD_BATCH = "Add batch"
BTN_SAVE_CHANGES = "Save changes"
BTN_CONFIRM_ARCHIVE = "Yes, archive this batch"

def verify_current_vaccine(self):
self.po.verify(
locator=self.LBL_MAIN, property=object_properties.TEXT, value=self.LBL_VACCINE_NAME, exact=False
)
self.po.verify(
locator=self.LBL_MAIN, property=object_properties.TEXT, value=self.LBL_VACCINE_MANUFACTURER, exact=False
)

def enter_batch_name(self):
self.batch_name = f"Auto{get_new_datetime()}"
self.po.perform_action(locator=self.TXT_BATCH_NAME, action=actions.FILL, value=self.batch_name)

def enter_batch_expiry(self):
self.po.perform_action(locator=self.TXT_EXPIRY_DAY, action=actions.FILL, value="31")
self.po.perform_action(locator=self.TXT_EXPIRY_MONTH, action=actions.FILL, value="12")
self.po.perform_action(locator=self.TXT_EXPIRY_YEAR, action=actions.FILL, value="2030")

def add_batch(self):
self.po.perform_action(locator=self.LNK_ADD_NEW_BATCH, action=actions.CLICK_LINK)
self.enter_batch_name()
self.enter_batch_expiry()
self.po.perform_action(locator=self.BTN_ADD_BATCH, action=actions.CLICK_BUTTON)
_success_message = f"Batch {self.batch_name} added"
self.po.verify(locator=self.LBL_PARAGRAPH, property=object_properties.TEXT, value=_success_message)

def change_batch(self):
self.po.perform_action(
locator=self.batch_name, action=actions.CLICK_LINK_INDEX_FOR_ROW, value=0
) # CHANGE link
self.po.perform_action(locator=self.TXT_EXPIRY_YEAR, action=actions.FILL, value="2031")
self.po.perform_action(locator=self.BTN_SAVE_CHANGES, action=actions.CLICK_BUTTON)
_success_message = f"Batch {self.batch_name} updated"
self.po.verify(locator=self.LBL_PARAGRAPH, property=object_properties.TEXT, value=_success_message)

def archive_batch(self):
self.po.perform_action(
locator=self.batch_name, action=actions.CLICK_LINK_INDEX_FOR_ROW, value=1
) # ARCHIVE link
self.po.perform_action(locator=self.BTN_CONFIRM_ARCHIVE, action=actions.CLICK_BUTTON)
self.po.verify(locator=self.LBL_PARAGRAPH, property=object_properties.TEXT, value=self.LBL_BATCH_ARCHIVED)
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[pytest]

addopts = -vs -rf --alluredir=./reports/ --html-report=./reports/
addopts = -vs -rf --alluredir=./reports/ --html-report=./reports/ -n auto

log_file = logs/pytest.log
log_cli = true
Expand All @@ -19,3 +19,4 @@ markers =
consent
cohorts
childlist
vaccsbatch
Empty file added test-results/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions tests/test_5_child_list_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Test_Regression_Child_List_Upload:
@pytest.mark.childlist
@pytest.mark.regression
@pytest.mark.order(501)
@pytest.mark.skip(reason="Covered by cohort uploads")
def test_reg_child_list_file_upload_positive(self, create_browser_page):
self.login_page.perform_login()
self.home_page.click_programmes()
Expand All @@ -20,6 +21,7 @@ def test_reg_child_list_file_upload_positive(self, create_browser_page):
@pytest.mark.childlist
@pytest.mark.regression
@pytest.mark.order(502)
@pytest.mark.skip(reason="Covered by cohort uploads")
def test_reg_child_list_file_upload_negative(self, create_browser_page):
self.login_page.perform_login()
self.home_page.click_programmes()
Expand All @@ -28,6 +30,7 @@ def test_reg_child_list_file_upload_negative(self, create_browser_page):
@pytest.mark.childlist
@pytest.mark.regression
@pytest.mark.order(503)
@pytest.mark.skip(reason="Covered by cohort uploads")
def test_reg_cohorts_file_structure(self, create_browser_page):
self.login_page.perform_login()
self.home_page.click_programmes()
Expand All @@ -36,6 +39,7 @@ def test_reg_cohorts_file_structure(self, create_browser_page):
@pytest.mark.childlist
@pytest.mark.regression
@pytest.mark.order(504)
@pytest.mark.skip(reason="Covered by cohort uploads")
def test_reg_cohorts_no_record(self, create_browser_page):
self.login_page.perform_login()
self.home_page.click_programmes()
Expand All @@ -44,6 +48,7 @@ def test_reg_cohorts_no_record(self, create_browser_page):
@pytest.mark.childlist
@pytest.mark.regression
@pytest.mark.order(505)
@pytest.mark.skip(reason="Covered by cohort uploads")
def test_reg_cohorts_empty_file(self, create_browser_page):
self.login_page.perform_login()
self.home_page.click_programmes()
Expand Down
46 changes: 46 additions & 0 deletions tests/test_6_vaccs_batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest

from pages import pg_home, pg_login, pg_vaccines


class Test_Regression_Cohorts:
login_page = pg_login.pg_login()
home_page = pg_home.pg_home()
vaccines_page = pg_vaccines.pg_vaccines()

@pytest.mark.vaccsbatch
@pytest.mark.regression
@pytest.mark.order(601)
def test_reg_batch_add_batch(self, create_browser_page):
self.login_page.perform_login()
self.home_page.click_vaccines()
self.vaccines_page.add_batch()
self.vaccines_page.change_batch()
self.vaccines_page.archive_batch()

@pytest.mark.vaccsbatch
@pytest.mark.regression
@pytest.mark.order(602)
def test_reg_batch_change_batch(self, create_browser_page):
self.login_page.perform_login()
self.home_page.click_vaccines()
self.vaccines_page.add_batch()
self.vaccines_page.change_batch()

@pytest.mark.vaccsbatch
@pytest.mark.regression
@pytest.mark.order(603)
def test_reg_batch_archive_batch(self, create_browser_page):
self.login_page.perform_login()
self.home_page.click_vaccines()
self.vaccines_page.add_batch()
self.vaccines_page.archive_batch()

@pytest.mark.vaccsbatch
@pytest.mark.regression
@pytest.mark.order(604)
def test_reg_batch_add_change_archive_batch(self, create_browser_page):
self.login_page.perform_login()
self.home_page.click_vaccines()
self.vaccines_page.add_batch()
self.vaccines_page.archive_batch()

0 comments on commit 34994eb

Please sign in to comment.