Skip to content

Commit

Permalink
Selenium: Targeting smoke tests (#3822)
Browse files Browse the repository at this point in the history
* Init

* Added test_smoke_targeting_details_page

* Added creation page smoke tests

* Edited ci.yml

* Black

* Fixes after conflicts

* Update ci.yml

* Upgrade helper.py

* mypy fix
  • Loading branch information
szymon-kellton authored May 14, 2024
1 parent 8f88ef0 commit 1c00a3e
Show file tree
Hide file tree
Showing 9 changed files with 569 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,4 @@ jobs:
echo "Failed to trigger deploy for pipeline $pipeline"
exit 1
fi
done
done
8 changes: 7 additions & 1 deletion backend/selenium_tests/helpers/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def __init__(self, driver: Chrome):
def _wait(self, timeout: int = DEFAULT_TIMEOUT) -> WebDriverWait:
return WebDriverWait(self.driver, timeout)

@staticmethod
def _wait_using_element(element: WebElement, timeout: int = DEFAULT_TIMEOUT) -> WebDriverWait:
# find and wait only in other element area (instead of whole driver)
return WebDriverWait(element, timeout)

def get(self, locator: str, element_type: str = By.CSS_SELECTOR) -> WebElement:
return self.driver.find_element(element_type, locator)

Expand Down Expand Up @@ -56,8 +61,9 @@ def select_listbox_element(
items = select_element.find_elements("tag name", tag_name)
for item in items:
if name in item.text:
self._wait().until(EC.element_to_be_clickable((By.XPATH, f"//*[contains(text(), '{name}')]")))
return item
return select_element
raise AssertionError(f"Element: {name} is not in the list.")

def check_page_after_click(self, button: WebElement, url_fragment: str) -> None:
programme_creation_url = self.driver.current_url
Expand Down
87 changes: 87 additions & 0 deletions backend/selenium_tests/page_object/targeting/create_new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from page_object.base_components import BaseComponents
from selenium.webdriver.remote.webelement import WebElement


class CreateNew(BaseComponents):
pageHeaderContainer = 'div[data-cy="page-header-container"]'
pageHeaderTitle = 'h5[data-cy="page-header-title"]'
buttonTargetPopulationCreate = 'button[data-cy="button-target-population-create"]'
inputDivName = 'div[data-cy="input-name"]'
inputIncludedHouseholdIds = 'div[data-cy="input-included-household-ids"]'
inputHouseholdids = 'input[data-cy="input-householdIds"]'
inputIncludedIndividualIds = 'div[data-cy="input-included-individual-ids"]'
inputIndividualids = 'input[data-cy="input-individualIds"]'
inputFlagexcludeifactiveadjudicationticket = 'span[data-cy="input-flagExcludeIfActiveAdjudicationTicket"]'
inputName = 'input[data-cy="input-name"]'

pageHeaderContainer = 'div[data-cy="page-header-container"]'
pageHeaderTitle = 'h5[data-cy="page-header-title"]'
buttonTargetPopulationCreate = 'button[data-cy="button-target-population-create"]'
divTargetPopulationAddCriteria = 'div[data-cy="button-target-population-add-criteria"]'
inputFlagexcludeifactiveadjudicationticket = 'span[data-cy="input-flagExcludeIfActiveAdjudicationTicket"]'
titleExcludedEntries = 'h6[data-cy="title-excluded-entries"]'
buttonShowHideExclusions = 'button[data-cy="button-show-hide-exclusions"]'
inputExcludedIds = 'div[data-cy="input-excluded-ids"]'
inputExcludedids = 'input[data-cy="input-excludedIds"]'
inputExclusionReason = 'div[data-cy="input-exclusion-reason"]'
titleAddFilter = 'h6[data-cy="title-add-filter"]'
autocompleteTargetCriteria = 'div[data-cy="autocomplete-target-criteria"]'
fieldChooserFilters = 'div[data-cy="field-chooser-filters[0]"]'
autocompleteTargetCriteriaOption = 'input[data-cy="autocomplete-target-criteria-option-0"]'
buttonHouseholdRule = 'button[data-cy="button-household-rule"]'
buttonIndividualRule = 'button[data-cy="button-individual-rule"]'
buttonTargetPopulationAddCriteria = 'button[data-cy="button-target-population-add-criteria"]'

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

def getButtonTargetPopulationCreate(self) -> WebElement:
return self.wait_for(self.buttonTargetPopulationCreate)

def getInputName(self) -> WebElement:
return self.wait_for(self.inputName)

def getInputIncludedHouseholdIds(self) -> WebElement:
return self.wait_for(self.inputIncludedHouseholdIds)

def getInputHouseholdids(self) -> WebElement:
return self.wait_for(self.inputHouseholdids)

def getInputIncludedIndividualIds(self) -> WebElement:
return self.wait_for(self.inputIncludedIndividualIds)

def getInputIndividualids(self) -> WebElement:
return self.wait_for(self.inputIndividualids)

def getInputFlagexcludeifactiveadjudicationticket(self) -> WebElement:
return self.wait_for(self.inputFlagexcludeifactiveadjudicationticket)

def getButtonTargetPopulationAddCriteria(self) -> WebElement:
return self.wait_for(self.buttonTargetPopulationAddCriteria)

def getDivTargetPopulationAddCriteria(self) -> WebElement:
return self.wait_for(self.divTargetPopulationAddCriteria)

def getTitleExcludedEntries(self) -> WebElement:
return self.wait_for(self.titleExcludedEntries)

def getButtonShowHideExclusions(self) -> WebElement:
return self.wait_for(self.buttonShowHideExclusions)

def getInputExcludedIds(self) -> WebElement:
return self.wait_for(self.inputExcludedIds)

def getInputExcludedids(self) -> WebElement:
return self.wait_for(self.inputExcludedids)

def getInputExclusionReason(self) -> WebElement:
return self.wait_for(self.inputExclusionReason)

def getButtonHouseholdRule(self) -> WebElement:
return self.wait_for(self.buttonHouseholdRule)

def getButtonIndividualRule(self) -> WebElement:
return self.wait_for(self.buttonIndividualRule)

def getAutocompleteTargetCriteriaOption(self) -> WebElement:
return self.wait_for(self.autocompleteTargetCriteriaOption)
130 changes: 130 additions & 0 deletions backend/selenium_tests/page_object/targeting/t_details_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
from page_object.base_components import BaseComponents
from selenium.webdriver.remote.webelement import WebElement


class DetailsTargeting(BaseComponents):
pageHeaderContainer = 'div[data-cy="page-header-container"]'
pageHeaderTitle = 'h5[data-cy="page-header-title"]'
buttonTargetPopulationDuplicate = 'button[data-cy="button-target-population-duplicate"]'
buttonDelete = 'button[data-cy="button-delete"]'
buttonEdit = 'a[data-cy="button-edit"]'
buttonRebuild = 'button[data-cy="button-rebuild"]'
buttonTargetPopulationLock = 'button[data-cy="button-target-population-lock"]'
detailsTitle = 'div[data-cy="details-title"]'
detailsGrid = 'div[data-cy="details-grid"]'
labelStatus = 'div[data-cy="label-Status"]'
targetPopulationStatus = 'div[data-cy="target-population-status"]'
labelizedFieldContainerCreatedBy = 'div[data-cy="labelized-field-container-created-by"]'
labelCreatedBy = 'div[data-cy="label-created by"]'
labelizedFieldContainerCloseDate = 'div[data-cy="labelized-field-container-close-date"]'
labelProgrammePopulationCloseDate = 'div[data-cy="label-Programme population close date"]'
labelizedFieldContainerProgramName = 'div[data-cy="labelized-field-container-program-name"]'
labelProgramme = 'div[data-cy="label-Programme"]'
labelizedFieldContainerSendBy = 'div[data-cy="labelized-field-container-send-by"]'
labelSendBy = 'div[data-cy="label-Send by"]'
labelizedFieldContainerSendDate = 'div[data-cy="labelized-field-container-send-date"]'
labelSendDate = 'div[data-cy="label-Send date"]'
criteriaContainer = 'div[data-cy="criteria-container"]'
checkboxExcludeIfActiveAdjudicationTicket = 'span[data-cy="checkbox-exclude-if-active-adjudication-ticket"]'
labelFemaleChildren = 'div[data-cy="label-Female Children"]'
labelFemaleAdults = 'div[data-cy="label-Female Adults"]'
labelMaleChildren = 'div[data-cy="label-Male Children"]'
labelMaleAdults = 'div[data-cy="label-Male Adults"]'
labelTotalNumberOfHouseholds = 'div[data-cy="label-Total Number of Households"]'
labelTargetedIndividuals = 'div[data-cy="label-Targeted Individuals"]'
tableTitle = 'h6[data-cy="table-title"]'
tableLabel = 'span[data-cy="table-label"]'
tablePagination = 'div[data-cy="table-pagination"]'

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

def getButtonTargetPopulationDuplicate(self) -> WebElement:
return self.wait_for(self.buttonTargetPopulationDuplicate)

def getButtonDelete(self) -> WebElement:
return self.wait_for(self.buttonDelete)

def getButtonEdit(self) -> WebElement:
return self.wait_for(self.buttonEdit)

def getButtonRebuild(self) -> WebElement:
return self.wait_for(self.buttonRebuild)

def getButtonTargetPopulationLock(self) -> WebElement:
return self.wait_for(self.buttonTargetPopulationLock)

def getDetailsTitle(self) -> WebElement:
return self.wait_for(self.detailsTitle)

def getDetailsGrid(self) -> WebElement:
return self.wait_for(self.detailsGrid)

def getLabelStatus(self) -> WebElement:
return self.wait_for(self.labelStatus)

def getTargetPopulationStatus(self) -> WebElement:
return self.wait_for(self.targetPopulationStatus)

def getLabelizedFieldContainerCreatedBy(self) -> WebElement:
return self.wait_for(self.labelizedFieldContainerCreatedBy)

def getLabelCreatedBy(self) -> WebElement:
return self.wait_for(self.labelCreatedBy)

def getLabelizedFieldContainerCloseDate(self) -> WebElement:
return self.wait_for(self.labelizedFieldContainerCloseDate)

def getLabelProgrammePopulationCloseDate(self) -> WebElement:
return self.wait_for(self.labelProgrammePopulationCloseDate)

def getLabelizedFieldContainerProgramName(self) -> WebElement:
return self.wait_for(self.labelizedFieldContainerProgramName)

def getLabelProgramme(self) -> WebElement:
return self.wait_for(self.labelProgramme)

def getLabelizedFieldContainerSendBy(self) -> WebElement:
return self.wait_for(self.labelizedFieldContainerSendBy)

def getLabelSendBy(self) -> WebElement:
return self.wait_for(self.labelSendBy)

def getLabelizedFieldContainerSendDate(self) -> WebElement:
return self.wait_for(self.labelizedFieldContainerSendDate)

def getLabelSendDate(self) -> WebElement:
return self.wait_for(self.labelSendDate)

def getCriteriaContainer(self) -> WebElement:
return self.wait_for(self.criteriaContainer)

def getCheckboxExcludeIfActiveAdjudicationTicket(self) -> WebElement:
return self.wait_for(self.checkboxExcludeIfActiveAdjudicationTicket)

def getLabelFemaleChildren(self) -> WebElement:
return self.wait_for(self.labelFemaleChildren)

def getLabelFemaleAdults(self) -> WebElement:
return self.wait_for(self.labelFemaleAdults)

def getLabelMaleChildren(self) -> WebElement:
return self.wait_for(self.labelMaleChildren)

def getLabelMaleAdults(self) -> WebElement:
return self.wait_for(self.labelMaleAdults)

def getLabelTotalNumberOfHouseholds(self) -> WebElement:
return self.wait_for(self.labelTotalNumberOfHouseholds)

def getLabelTargetedIndividuals(self) -> WebElement:
return self.wait_for(self.labelTargetedIndividuals)

def getTableTitle(self) -> WebElement:
return self.wait_for(self.tableTitle)

def getTableLabel(self) -> WebElement:
return self.get_elements(self.tableLabel)

def getTablePagination(self) -> WebElement:
return self.wait_for(self.tablePagination)
66 changes: 22 additions & 44 deletions backend/selenium_tests/page_object/targeting/targeting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from time import sleep

from page_object.base_components import BaseComponents
from selenium.webdriver.remote.webelement import WebElement

Expand All @@ -18,6 +20,8 @@ class Targeting(BaseComponents):
tabColumnLabel = 'span[data-cy="table-label"]'
statusOptions = 'li[role="option"]'
rows = 'tr[role="checkbox"]'
createUserFilters = 'div[data-cy="menu-item-filters-text"]'
createUseIDs = 'div[data-cy="menu-item-ids-text"]'

# Texts

Expand Down Expand Up @@ -70,23 +74,8 @@ def getButtonCreateNewByFilters(self) -> WebElement:
def getTabTitle(self) -> WebElement:
return self.wait_for(self.tabTitle)

def getTabColumnName(self) -> WebElement:
return self.wait_for(self.tabColumnLabel).eq(0)

def getTabColumnStatus(self) -> WebElement:
return self.wait_for(self.tabColumnLabel).eq(1)

def getTabColumnNOHouseholds(self) -> WebElement:
return self.wait_for(self.tabColumnLabel).eq(2)

def getTabColumnDateCreated(self) -> WebElement:
return self.wait_for(self.tabColumnLabel).eq(3)

def getTabColumnLastEdited(self) -> WebElement:
return self.wait_for(self.tabColumnLabel).eq(4)

def getTabColumnCreatedBy(self) -> WebElement:
return self.wait_for(self.tabColumnLabel).eq(5)
def getTabColumnLabel(self) -> list[WebElement]:
return self.get_elements(self.tabColumnLabel)

def getStatusOption(self) -> WebElement:
return self.wait_for(self.statusOptions)
Expand All @@ -97,30 +86,19 @@ def getApply(self) -> WebElement:
def getClear(self) -> WebElement:
return self.wait_for(self.buttonClear)

def getTargetPopulationsRows(self) -> WebElement:
return self.wait_for(self.rows)

def checkElementsOnPage(self) -> None:
self.getTitlePage().should("be.visible").contains(self.textTitlePage)
# self.getButtonFiltersExpand().click()
self.getSearchFilter().should("be.visible")
self.getStatusFilter().should("be.visible")
self.getMinNumberOfHouseholdsFilter().should("be.visible")
self.getMaxNumberOfHouseholdsFilter().should("be.visible")
self.getButtonCreateNew().should("be.visible").contains(self.textCreateNew)
self.getTabTitle().should("be.visible").contains(self.textTabTitle)
self.getTabColumnName().should("be.visible").contains(self.textTabName)
self.getTabColumnStatus().should("be.visible").contains(self.textTabStatus)
self.getTabColumnNOHouseholds()
self.getTabColumnDateCreated()
self.getTabColumnLastEdited()
self.getTabColumnCreatedBy()

def selectStatus(self, status: str) -> None:
self.getStatusFilter().click()
self.getStatusOption().contains(status).click()
self.pressEscapeFromElement(self.getStatusOption().contains(status))
self.getApply().click()

def chooseTargetPopulationRow(self, row: int) -> WebElement:
return self.getTargetPopulationsRows().eq(row)
def getTargetPopulationsRows(self) -> list[WebElement]:
return self.get_elements(self.rows)

def chooseTargetPopulations(self, number: int) -> WebElement:
try:
self.wait_for(self.rows)
return self.get_elements(self.rows)[number]
except IndexError:
sleep(1)
return self.get_elements(self.rows)[number]

def getCreateUseFilters(self) -> WebElement:
return self.wait_for(self.createUserFilters)

def getCreateUseIDs(self) -> WebElement:
return self.wait_for(self.createUseIDs)
Loading

0 comments on commit 1c00a3e

Please sign in to comment.