Skip to content

Commit

Permalink
Selenium: Payment Verification - happy path (#4008)
Browse files Browse the repository at this point in the history
* Init

* Test

* Added test_smoke_payment_verification_details

* Black

* Black

* Black

* Init

* Added to tests payment record part

* In progress test_happy_path_payment_verification

* add data-cy for breadcrumbs

* In progress test_happy_path_payment_verification

* Added test_happy_path_payment_verification

* update snaphots

* Fix test_happy_path_payment_verification

* Fix test_smoke_payment_verification_details

* Black

* Isort

---------

Co-authored-by: Maciej Szewczyk <[email protected]>
  • Loading branch information
szymon-kellton and Maciej Szewczyk authored Jul 9, 2024
1 parent eadd15f commit b878822
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 25 deletions.
10 changes: 8 additions & 2 deletions backend/selenium_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from page_object.payment_module.new_payment_plan import NewPaymentPlan
from page_object.payment_module.payment_module import PaymentModule
from page_object.payment_module.payment_module_details import PaymentModuleDetails
from page_object.payment_verification.payment_record import PaymentRecord
from page_object.payment_verification.payment_verification import PaymentVerification
from page_object.payment_verification.payment_verification_details import (
PaymentVerificationDetails,
Expand Down Expand Up @@ -278,15 +279,20 @@ def pagePaymentModule(request: FixtureRequest, browser: Chrome) -> PaymentModule


@pytest.fixture
def pagePaymentVerification(request: FixtureRequest, browser: Chrome) -> PaymentVerification:
yield PaymentVerification(browser)
def pagePaymentRecord(request: FixtureRequest, browser: Chrome) -> PaymentRecord:
yield PaymentRecord(browser)


@pytest.fixture
def pagePaymentVerificationDetails(request: FixtureRequest, browser: Chrome) -> PaymentVerificationDetails:
yield PaymentVerificationDetails(browser)


@pytest.fixture
def pagePaymentVerification(request: FixtureRequest, browser: Chrome) -> PaymentVerification:
yield PaymentVerification(browser)


@pytest.fixture
def pageTargetingDetails(request: FixtureRequest, browser: Chrome) -> TargetingDetails:
yield TargetingDetails(browser)
Expand Down
8 changes: 8 additions & 0 deletions backend/selenium_tests/page_object/base_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class BaseComponents(Common):
globalProgramFilterSearchButton = 'button[data-cy="search-icon"]'
globalProgramFilterClearButton = 'button[data-cy="clear-icon"]'
rows = 'tr[role="checkbox"]'
breadcrumbsChevronIcon = 'svg[data-cy="breadcrumbs-chevron-icon"]'
arrowBack = 'div[data-cy="arrow_back"]'

# Text
globalProgramFilterText = "All Programmes"
Expand Down Expand Up @@ -170,6 +172,12 @@ def getGlobalProgramFilterSearchButton(self) -> WebElement:
def getGlobalProgramFilterSearchInput(self) -> WebElement:
return self.wait_for(self.globalProgramFilterSearchInput)

def getBreadcrumbsChevronIcon(self) -> WebElement:
return self.wait_for(self.breadcrumbsChevronIcon)

def getArrowBack(self) -> WebElement:
return self.wait_for(self.arrowBack)

def getNavProgramLog(self) -> WebElement:
return self.wait_for(self.navProgramLog)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from page_object.base_components import BaseComponents
from selenium.webdriver.remote.webelement import WebElement


class PaymentRecord(BaseComponents):
pageHeaderContainer = 'div[data-cy="page-header-container"]'
pageHeaderTitle = 'h5[data-cy="page-header-title"]'
buttonEdPlan = 'button[data-cy="button-ed-plan"]'
labelStatus = 'div[data-cy="label-STATUS"]'
statusContainer = 'div[data-cy="status-container"]'
labelHousehold = 'div[data-cy="label-Household"]'
labelTargetPopulation = 'div[data-cy="label-TARGET POPULATION"]'
labelDistributionModality = 'div[data-cy="label-DISTRIBUTION MODALITY"]'
labelAmountReceived = 'div[data-cy="label-AMOUNT RECEIVED"]'
labelHouseholdId = 'div[data-cy="label-HOUSEHOLD ID"]'
labelHeadOfHousehold = 'div[data-cy="label-HEAD OF HOUSEHOLD"]'
labelTotalPersonCovered = 'div[data-cy="label-TOTAL PERSON COVERED"]'
labelPhoneNumber = 'div[data-cy="label-PHONE NUMBER"]'
labelAltPhoneNumber = 'div[data-cy="label-ALT. PHONE NUMBER"]'
labelEntitlementQuantity = 'div[data-cy="label-ENTITLEMENT QUANTITY"]'
labelDeliveredQuantity = 'div[data-cy="label-DELIVERED QUANTITY"]'
labelCurrency = 'div[data-cy="label-CURRENCY"]'
labelDeliveryType = 'div[data-cy="label-DELIVERY TYPE"]'
labelDeliveryDate = 'div[data-cy="label-DELIVERY DATE"]'
labelEntitlementCardId = 'div[data-cy="label-ENTITLEMENT CARD ID"]'
labelTransactionReferenceId = 'div[data-cy="label-TRANSACTION REFERENCE ID"]'
labelEntitlementCardIssueDate = 'div[data-cy="label-ENTITLEMENT CARD ISSUE DATE"]'
labelFsp = 'div[data-cy="label-FSP"]'
buttonSubmit = 'button[data-cy="button-submit"]'
inputReceivedamount = 'input[data-cy="input-receivedAmount"]'

def getInputReceivedamount(self) -> WebElement:
return self.wait_for(self.inputReceivedamount)

def getPageHeaderContainer(self) -> WebElement:
return self.wait_for(self.pageHeaderContainer)

def getPageHeaderTitle(self) -> WebElement:
return self.wait_for(self.pageHeaderTitle)

def getButtonEdPlan(self) -> WebElement:
# Workaround because elements overlapped even though Selenium saw that they were available:
self.driver.execute_script(
"""
container = document.querySelector("div[data-cy='main-content']")
container.scrollBy(0,-200)
"""
)
return self.wait_for(self.buttonEdPlan)

def getLabelStatus(self) -> [WebElement]:
return self.get_elements(self.labelStatus)

def getStatusContainer(self) -> WebElement:
return self.wait_for(self.statusContainer)

def getLabelHousehold(self) -> WebElement:
return self.wait_for(self.labelHousehold)

def getLabelTargetPopulation(self) -> WebElement:
return self.wait_for(self.labelTargetPopulation)

def getLabelDistributionModality(self) -> WebElement:
return self.wait_for(self.labelDistributionModality)

def getLabelAmountReceived(self) -> WebElement:
return self.wait_for(self.labelAmountReceived)

def getLabelHouseholdId(self) -> WebElement:
return self.wait_for(self.labelHouseholdId)

def getLabelHeadOfHousehold(self) -> WebElement:
return self.wait_for(self.labelHeadOfHousehold)

def getLabelTotalPersonCovered(self) -> WebElement:
return self.wait_for(self.labelTotalPersonCovered)

def getLabelPhoneNumber(self) -> WebElement:
return self.wait_for(self.labelPhoneNumber)

def getLabelAltPhoneNumber(self) -> WebElement:
return self.wait_for(self.labelAltPhoneNumber)

def getLabelEntitlementQuantity(self) -> WebElement:
return self.wait_for(self.labelEntitlementQuantity)

def getLabelDeliveredQuantity(self) -> WebElement:
return self.wait_for(self.labelDeliveredQuantity)

def getLabelCurrency(self) -> WebElement:
return self.wait_for(self.labelCurrency)

def getLabelDeliveryType(self) -> WebElement:
return self.wait_for(self.labelDeliveryType)

def getLabelDeliveryDate(self) -> WebElement:
return self.wait_for(self.labelDeliveryDate)

def getLabelEntitlementCardId(self) -> WebElement:
return self.wait_for(self.labelEntitlementCardId)

def getLabelTransactionReferenceId(self) -> WebElement:
return self.wait_for(self.labelTransactionReferenceId)

def getLabelEntitlementCardIssueDate(self) -> WebElement:
return self.wait_for(self.labelEntitlementCardIssueDate)

def getLabelFsp(self) -> WebElement:
return self.wait_for(self.labelFsp)

def getButtonSubmit(self) -> WebElement:
return self.wait_for(self.buttonSubmit)
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class PaymentVerificationDetails(BaseComponents):
labelStatusDiv = 'div[data-cy="label-STATUS"]'
labelActivationDateDiv = 'div[data-cy="label-ACTIVATION DATE"]'
labelCompletionDateDiv = 'div[data-cy="label-COMPLETION DATE"]'
buttonSubmit = 'button[data-cy="button-submit"]'
buttonFinish = 'button[data-cy="button-ed-plan"]'
rows = 'tr[role="checkbox"]'

def getPageHeaderContainer(self) -> WebElement:
return self.wait_for(self.pageHeaderContainer)
Expand Down Expand Up @@ -148,3 +151,13 @@ def getLabelCompletionDateDiv(self) -> WebElement:

def getLabelStatusDiv(self) -> WebElement:
return self.wait_for(self.labelStatusDiv)

def getButtonSubmit(self) -> WebElement:
return self.wait_for(self.buttonSubmit)

def getButtonFinish(self) -> WebElement:
return self.wait_for(self.buttonFinish)

def getRows(self) -> [WebElement]:
self.wait_for(self.rows)
return self.get_elements(self.rows)
118 changes: 101 additions & 17 deletions backend/selenium_tests/payment_verification/test_payment_verification.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from datetime import datetime
from time import sleep

import pytest
from dateutil.relativedelta import relativedelta
from page_object.payment_verification.payment_record import PaymentRecord
from page_object.payment_verification.payment_verification import PaymentVerification
from page_object.payment_verification.payment_verification_details import (
PaymentVerificationDetails,
)
from selenium.webdriver.common.by import By

from hct_mis_api.apps.account.models import User
from hct_mis_api.apps.core.fixtures import DataCollectingTypeFactory
Expand All @@ -18,6 +21,8 @@
PaymentVerificationFactory,
PaymentVerificationPlanFactory,
)
from hct_mis_api.apps.payment.models import GenericPayment
from hct_mis_api.apps.payment.models import PaymentRecord as PR
from hct_mis_api.apps.payment.models import PaymentVerification as PV
from hct_mis_api.apps.payment.models import PaymentVerificationPlan
from hct_mis_api.apps.program.fixtures import ProgramFactory
Expand Down Expand Up @@ -71,15 +76,17 @@ def add_payment_verification() -> PV:
name="TEST",
program=program,
business_area=BusinessArea.objects.first(),
start_date=datetime.now() - relativedelta(months=1),
end_date=datetime.now() + relativedelta(months=1),
)

targeting_criteria = TargetingCriteriaFactory()

target_population = TargetPopulationFactory(
created_by=User.objects.first(),
targeting_criteria=targeting_criteria,
business_area=BusinessArea.objects.first(),
)

payment_record = PaymentRecordFactory(
parent=cash_plan,
household=household,
Expand All @@ -88,16 +95,23 @@ def add_payment_verification() -> PV:
entitlement_quantity="21.36",
delivered_quantity="21.36",
currency="PLN",
status=GenericPayment.STATUS_DISTRIBUTION_SUCCESS,
)
payment_verification_plan = PaymentVerificationPlanFactory(
generic_fk_obj=cash_plan, verification_channel=PaymentVerificationPlan.VERIFICATION_CHANNEL_MANUAL
generic_fk_obj=cash_plan,
verification_channel=PaymentVerificationPlan.VERIFICATION_CHANNEL_MANUAL,
)

return PaymentVerificationFactory(
pv_summary = cash_plan.get_payment_verification_summary
pv_summary.activation_date = datetime.now() - relativedelta(months=1)
pv_summary.save()

pv = PaymentVerificationFactory(
generic_fk_obj=payment_record,
payment_verification_plan=payment_verification_plan,
status=PV.STATUS_PENDING,
)
return pv


@pytest.mark.usefixtures("login")
Expand Down Expand Up @@ -140,11 +154,12 @@ def test_smoke_payment_verification_details(
assert "0%" in pagePaymentVerificationDetails.getLabelErroneous().text
assert "PENDING" in pagePaymentVerificationDetails.getLabelStatus().text
assert "PENDING" in pagePaymentVerificationDetails.getVerificationPlansSummaryStatus().text
activation_date = (datetime.now() - relativedelta(months=1)).strftime("%-d %b %Y")
assert (
"ACTIVATION DATE -"
f"ACTIVATION DATE {activation_date}"
in pagePaymentVerificationDetails.getLabelizedFieldContainerSummaryActivationDate().text.replace("\n", " ")
)
assert "-" in pagePaymentVerificationDetails.getLabelActivationDate().text
assert activation_date in pagePaymentVerificationDetails.getLabelActivationDate().text
assert (
"COMPLETION DATE -"
in pagePaymentVerificationDetails.getLabelizedFieldContainerSummaryCompletionDate().text.replace("\n", " ")
Expand All @@ -161,27 +176,96 @@ def test_smoke_payment_verification_details(
assert "PENDING" in pagePaymentVerificationDetails.getLabelStatus().text
assert "PENDING" in pagePaymentVerificationDetails.getVerificationPlanStatus().text
assert "MANUAL" in pagePaymentVerificationDetails.getLabelVerificationChannel().text
assert "-" in pagePaymentVerificationDetails.getLabelActivationDate().text
assert (
str((datetime.now() - relativedelta(months=1)).strftime("%-d %b %Y"))
in pagePaymentVerificationDetails.getLabelActivationDate().text
)
assert "-" in pagePaymentVerificationDetails.getLabelCompletionDate().text

@pytest.mark.skip(reason="Do during the task: 198121")
def test_smoke_payment_verification_happy_path(
def test_happy_path_payment_verification(
self,
active_program: Program,
add_payment_verification: PV,
pagePaymentVerification: PaymentVerification,
pagePaymentVerificationDetails: PaymentVerificationDetails,
pagePaymentRecord: PaymentRecord,
) -> None:
pagePaymentVerification.selectGlobalProgramFilter("Active Program").click()
pagePaymentVerification.getNavPaymentVerification().click()
pagePaymentVerification.getCashPlanTableRow().click()
assert "0" in pagePaymentVerificationDetails.getLabelPaymentRecords().text
assert "23 Feb 2025" in pagePaymentVerificationDetails.getLabelStartDate().text
assert "26 May 2025" in pagePaymentVerificationDetails.getLabelEndDate().text
assert "1" in pagePaymentVerificationDetails.getLabelPaymentRecords().text
assert (datetime.now() - relativedelta(months=1)).strftime(
"%-d %b %Y"
) in pagePaymentVerificationDetails.getLabelStartDate().text
assert (datetime.now() + relativedelta(months=1)).strftime(
"%-d %b %Y"
) in pagePaymentVerificationDetails.getLabelEndDate().text
assert "Bank reconciliation" in pagePaymentVerificationDetails.getTableLabel().text
assert "Full list" in pagePaymentVerificationDetails.getLabelSampling().text
assert "55" in pagePaymentVerificationDetails.getLabelResponded().text
assert "8" in pagePaymentVerificationDetails.getLabelReceivedWithIssues().text
assert "29" in pagePaymentVerificationDetails.getLabelSampleSize().text
assert "37" in pagePaymentVerificationDetails.getLabelReceived().text
assert "3" in pagePaymentVerificationDetails.getLabelNotReceived().text
payment_verification = add_payment_verification.payment_verification_plan
assert (
payment_verification.sampling.lower().replace("_", " ")
in pagePaymentVerificationDetails.getLabelSampling().text.lower()
)
assert str(payment_verification.responded_count) in pagePaymentVerificationDetails.getLabelResponded().text
assert (
str(payment_verification.received_with_problems_count)
in pagePaymentVerificationDetails.getLabelReceivedWithIssues().text
)
assert str(payment_verification.sample_size) in pagePaymentVerificationDetails.getLabelSampleSize().text
assert str(payment_verification.received_count) in pagePaymentVerificationDetails.getLabelReceived().text
assert str(payment_verification.not_received_count) in pagePaymentVerificationDetails.getLabelNotReceived().text
pagePaymentVerificationDetails.getButtonDeletePlan().click()
pagePaymentVerificationDetails.getButtonSubmit().click()
try:
pagePaymentVerificationDetails.getButtonNewPlan().click()
except BaseException:
sleep(3)
pagePaymentVerificationDetails.getButtonNewPlan().click()
pagePaymentVerificationDetails.getButtonSubmit().click()

pagePaymentVerificationDetails.getButtonActivatePlan().click()
pagePaymentVerificationDetails.getButtonSubmit().click()

pagePaymentVerificationDetails.getRows()[0].find_elements(By.TAG_NAME, "a")[0].click()
payment_record = PR.objects.first()
assert "Payment Record" in pagePaymentRecord.getPageHeaderTitle().text
assert "VERIFY" in pagePaymentRecord.getButtonEdPlan().text
assert "DELIVERED FULLY" in pagePaymentRecord.getLabelStatus()[0].text
assert "DELIVERED FULLY" in pagePaymentRecord.getStatusContainer().text
assert payment_record.household.unicef_id in pagePaymentRecord.getLabelHousehold().text
assert payment_record.target_population.name in pagePaymentRecord.getLabelTargetPopulation().text
assert payment_record.distribution_modality in pagePaymentRecord.getLabelDistributionModality().text
assert payment_record.verification.status in pagePaymentRecord.getLabelStatus()[1].text
assert "PLN 0.00" in pagePaymentRecord.getLabelAmountReceived().text
assert payment_record.household.unicef_id in pagePaymentRecord.getLabelHouseholdId().text
assert "21.36" in pagePaymentRecord.getLabelEntitlementQuantity().text
assert "21.36" in pagePaymentRecord.getLabelDeliveredQuantity().text
assert "PLN" in pagePaymentRecord.getLabelCurrency().text
assert "-" in pagePaymentRecord.getLabelDeliveryType().text
assert payment_record.service_provider.full_name in pagePaymentRecord.getLabelFsp().text

pagePaymentRecord.getButtonEdPlan().click()

pagePaymentRecord.getInputReceivedamount().click()
pagePaymentRecord.getInputReceivedamount().send_keys("100")
pagePaymentRecord.getButtonSubmit().click()

for _ in range(5):
if "RECEIVED WITH ISSUES" in pagePaymentRecord.getLabelStatus()[1].text:
break
sleep(1)
assert "RECEIVED WITH ISSUES" in pagePaymentRecord.getLabelStatus()[1].text
pagePaymentRecord.getArrowBack().click()

pagePaymentVerificationDetails.getButtonFinish().click()
pagePaymentVerificationDetails.getButtonSubmit().click()

pagePaymentVerificationDetails.screenshot("1")
assert "Payment Plan" in pagePaymentVerificationDetails.getPageHeaderTitle().text
assert "FINISHED" in pagePaymentVerificationDetails.getLabelStatus().text
assert "FINISHED" in pagePaymentVerificationDetails.getVerificationPlanStatus().text
assert "100%" in pagePaymentVerificationDetails.getLabelSuccessful().text

pagePaymentRecord.getArrowBack().click()

assert "FINISHED" in pagePaymentVerification.getCashPlanTableRow().text
Loading

0 comments on commit b878822

Please sign in to comment.