Skip to content

Commit

Permalink
file upload flow
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaymudholkar1 committed Sep 27, 2024
1 parent 56bde6f commit 2398953
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 9 deletions.
11 changes: 6 additions & 5 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@pytest.fixture(scope="session")
def start_exe_session():
ce.execution_start_time = datetime.now()
ce.session_screenshots_dir = create_session_screenshot_dir()
ce.get_env_values()
ce.session_screenshots_dir = create_session_screenshot_dir()
ce.start_browser()
yield
ce.quit_browser()
Expand All @@ -24,7 +24,8 @@ def browser_page(start_exe_session):


def create_session_screenshot_dir() -> str:
_start_time = str(ce.execution_start_time).replace("-", "").replace(" ", "").replace(":", "").split(".")[0]
_session_name = f"Execution-{_start_time}"
fo.file_operations().create_dir(dir_path=f"screenshots/{_session_name}")
return f"screenshots/{_session_name}"
if ce.capture_screenshot_flag:
_start_time = str(ce.execution_start_time).replace("-", "").replace(" ", "").replace(":", "").split(".")[0]
_session_name = f"Execution-{_start_time}"
fo.file_operations().create_dir(dir_path=f"screenshots/{_session_name}")
return f"screenshots/{_session_name}"
3 changes: 3 additions & 0 deletions libs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class object_properties:
class actions:
CLICK_LINK = "click_link"
CLICK_BUTTON = "click_button"
CLICK_LABEL = "click_label"
FILL = "fill"
RADIO_BUTTON_SELECT = "radio_select"
SELECT_FILE = "select_file"


class screenshot_types:
Expand Down
25 changes: 21 additions & 4 deletions libs/playwright_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,35 @@ def verify(self, page, locator: str, property: str, value: str) -> None:
expect(elem).to_contain_text(value)

def perform_action(self, page, locator, action, value=None) -> None:
self.capture_screenshot(page=page, identifier=locator, action=action)
self.capture_screenshot(page=page, identifier=locator, action=f"before-{action}")
match action.lower():
case actions.CLICK_LINK:
elem = page.get_by_role("link", name=locator)
elem = page.get_by_role("link", name=locator).nth(0)
elem.scroll_into_view_if_needed()
elem.click()
case actions.CLICK_BUTTON:
elem = page.get_by_role("button", name=locator)
elem = page.get_by_role("button", name=locator).nth(0)
elem.scroll_into_view_if_needed()
elem.click()
case actions.CLICK_LABEL:
elem = page.get_by_label(locator, exact=True).nth(0)
elem.scroll_into_view_if_needed()
elem.click()
case actions.FILL:
elem = page.get_by_label(locator, exact=True)
elem = page.get_by_label(locator, exact=True).nth(0)
elem.scroll_into_view_if_needed()
elem.click()
elem.fill(value)
self.capture_screenshot(page=page, identifier=locator, action=f"after-{action}")
case actions.RADIO_BUTTON_SELECT:
elem = page.get_by_text(locator, exact=True).nth(0)
elem.scroll_into_view_if_needed()
elem.click()
self.capture_screenshot(page=page, identifier=locator, action=f"after-{action}")
case actions.SELECT_FILE:
# _values = os.path.split(value)
# _file_path = _values[0]
# _file_name = _values[1]
elem = page.get_by_label(locator, exact=True).nth(0)
elem.scroll_into_view_if_needed()
elem.set_input_files(value)
11 changes: 11 additions & 0 deletions pages/pg_home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from libs import playwright_ops
from libs.constants import object_properties, actions


class pg_home:
po = playwright_ops.playwright_operations()

LNK_PROGRAMMES = "Programmes"

def click_programmes(self, browser_page):
self.po.perform_action(page=browser_page, locator=self.LNK_PROGRAMMES, action=actions.CLICK_LINK)
61 changes: 61 additions & 0 deletions pages/pg_programmes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from libs import playwright_ops
from libs.constants import object_properties, actions


class pg_programmes:
po = playwright_ops.playwright_operations()

LNK_HPV = "HPV"
LNK_IMPORTS = "Imports"
LNK_IMPORT_RECORDS = "Import records"
RDO_CHILD_RECORDS = "Child records"
RDO_VACCINATION_RECORDS = "Vaccination records"
BTN_CONTINUE = "Continue"
LBL_CHOOSE_FILE_CHILD_RECORDS = "HPVImport child records"
LBL_CHOOSE_FILE_VACCINATION_RECORDS = "HPVUpload vaccination records"

def click_HPV(self, browser_page):
self.po.perform_action(page=browser_page, locator=self.LNK_HPV, action=actions.CLICK_LINK)

def click_Imports(self, browser_page):
self.po.perform_action(page=browser_page, locator=self.LNK_IMPORTS, action=actions.CLICK_LINK)

def click_ImportRecords(self, browser_page):
self.po.perform_action(page=browser_page, locator=self.LNK_IMPORT_RECORDS, action=actions.CLICK_LINK)

def select_ChildRecords(self, browser_page):
self.po.perform_action(page=browser_page, locator=self.RDO_CHILD_RECORDS, action=actions.RADIO_BUTTON_SELECT)

def select_VaccinationRecords(self, browser_page):
self.po.perform_action(
page=browser_page, locator=self.RDO_VACCINATION_RECORDS, action=actions.RADIO_BUTTON_SELECT
)

def click_Continue(self, browser_page):
self.po.perform_action(page=browser_page, locator=self.BTN_CONTINUE, action=actions.CLICK_BUTTON)

def click_ChooseFile_ChildRecords(self, browser_page):
self.po.perform_action(
page=browser_page, locator=self.LBL_CHOOSE_FILE_CHILD_RECORDS, action=actions.CLICK_LABEL
)

def choose_file_child_records(self, browser_page, file_path: str):
self.po.perform_action(
page=browser_page,
locator=self.LBL_CHOOSE_FILE_CHILD_RECORDS,
action=actions.SELECT_FILE,
value=file_path,
)

def click_ChooseFile_VaccinationRecords(self, browser_page):
self.po.perform_action(
page=browser_page, locator=self.LBL_CHOOSE_FILE_VACCINATION_RECORDS, action=actions.CLICK_LABEL
)

def choose_file_vaccination_records(self, browser_page, file_path: str):
self.po.perform_action(
page=browser_page,
locator=self.LBL_CHOOSE_FILE_VACCINATION_RECORDS,
action=actions.SELECT_FILE,
value=file_path,
)
14 changes: 14 additions & 0 deletions tests/test_1_reg_file_upload.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import pytest
from pages import pg_login
from pages import pg_home
from pages import pg_programmes


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

@pytest.mark.regression
@pytest.mark.order(101)
def test_reg_file_upload(self, browser_page):
self.login_page.perform_login(browser_page=browser_page)
self.home_page.click_programmes(browser_page=browser_page)
self.programmes_page.click_HPV(browser_page=browser_page)
self.programmes_page.click_Imports(browser_page=browser_page)
self.programmes_page.click_ImportRecords(browser_page=browser_page)
self.programmes_page.select_VaccinationRecords(browser_page=browser_page)
self.programmes_page.click_Continue(browser_page=browser_page)
self.programmes_page.choose_file_vaccination_records(
browser_page=browser_page, file_path="test_data/hpv/file1.csv"
)
self.programmes_page.click_Continue(browser_page=browser_page)

0 comments on commit 2398953

Please sign in to comment.