Skip to content

Commit

Permalink
Selenium - Grievance tickets: happy path (#3837)
Browse files Browse the repository at this point in the history
* Init

* Tests grievance_tickets.py

* ci.yaml always Upload Artifact

---------

Co-authored-by: Maciej Szewczyk <[email protected]>
  • Loading branch information
szymon-kellton and Maciej Szewczyk authored May 13, 2024
1 parent 67d8ccc commit 416c153
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,15 @@ jobs:
run selenium
- name: Upload Artifact
uses: actions/upload-artifact@v4
if: always()
continue-on-error: true
with:
name: report
path: ./backend/report/
retention-days: 5
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: always()
continue-on-error: true
with:
files: ./backend/coverage.xml
Expand Down
6 changes: 6 additions & 0 deletions backend/selenium_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from page_object.grievance.feedback import Feedback
from page_object.grievance.grievance_tickets import GrievanceTickets
from page_object.grievance.new_feedback import NewFeedback
from page_object.grievance.new_ticket import NewTicket
from page_object.programme_details.programme_details import ProgrammeDetails
from page_object.programme_management.programme_management import ProgrammeManagement
from page_object.programme_population.households import Households
Expand Down Expand Up @@ -266,6 +267,11 @@ def pageGrievanceDetailsPage(request: FixtureRequest, browser: Chrome) -> Grieva
yield GrievanceDetailsPage(browser)


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


@pytest.fixture
def business_area() -> BusinessArea:
business_area, _ = BusinessArea.objects.get_or_create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
from page_object.grievance.details_grievance_page import GrievanceDetailsPage
from page_object.grievance.grievance_tickets import GrievanceTickets
from page_object.grievance.new_ticket import NewTicket
from pytest_django import DjangoDbBlocker

pytestmark = pytest.mark.django_db(transaction=True)
Expand Down Expand Up @@ -148,12 +149,65 @@ def test_check_grievance_tickets_details_page(

@pytest.mark.usefixtures("login")
class TestGrievanceTicketsHappyPath:

@pytest.mark.parametrize(
"test_data",
[
pytest.param({"category": "Sensitive Grievance", "type": "Miscellaneous"}, id="Sensitive Grievance"),
pytest.param({"category": "Grievance Complaint", "type": "Other Complaint"}, id="Grievance Complaint"),
],
)
@pytest.mark.skip(reason="ToDo")
def test_grievance_tickets_create_new_ticket(
self,
pageGrievanceTickets: GrievanceTickets,
pageGrievanceNewTicket: NewTicket,
pageGrievanceDetailsPage: GrievanceDetailsPage,
test_data: dict,
) -> None:
pageGrievanceTickets.getNavGrievance().click()
assert "Grievance Tickets" in pageGrievanceTickets.getGrievanceTitle().text
pageGrievanceTickets.getButtonNewTicket().click()
pageGrievanceNewTicket.getSelectCategory().click()
pageGrievanceNewTicket.select_option_by_name(test_data["category"])
pageGrievanceNewTicket.getIssueType().click()
pageGrievanceNewTicket.select_option_by_name(test_data["type"])
pageGrievanceNewTicket.getButtonNext().click()
pageGrievanceNewTicket.getHouseholdTab()
assert pageGrievanceNewTicket.waitForNoResults()
pageGrievanceNewTicket.getButtonNext().click()
pageGrievanceNewTicket.getReceivedConsent().click()
pageGrievanceNewTicket.getButtonNext().click()
pageGrievanceNewTicket.getDescription().send_keys("Happy path test 1234!")
pageGrievanceNewTicket.getButtonNext().click()
assert "Happy path test 1234!" in pageGrievanceDetailsPage.getTicketDescription().text
assert test_data["category"] in pageGrievanceDetailsPage.getTicketCategory().text
assert test_data["type"] in pageGrievanceDetailsPage.getLabelIssueType().text
assert "New" in pageGrievanceDetailsPage.getTicketStatus().text
assert "Not set" in pageGrievanceDetailsPage.getTicketPriority().text
assert "Not set" in pageGrievanceDetailsPage.getTicketUrgency().text

def test_grievance_tickets_create_new_ticket_referral(
self,
pageGrievanceTickets: GrievanceTickets,
pageGrievanceNewTicket: NewTicket,
pageGrievanceDetailsPage: GrievanceDetailsPage,
) -> None:
pageGrievanceTickets.getNavGrievance().click()
assert "Grievance Tickets" in pageGrievanceTickets.getGrievanceTitle().text
pageGrievanceTickets.getButtonNewTicket().click()
pageGrievanceTickets.screenshot("HappyPath")
pageGrievanceNewTicket.getSelectCategory().click()
pageGrievanceNewTicket.select_option_by_name("Referral")
pageGrievanceNewTicket.getButtonNext().click()
pageGrievanceNewTicket.getHouseholdTab()
assert pageGrievanceNewTicket.waitForNoResults()
pageGrievanceNewTicket.getButtonNext().click()
pageGrievanceNewTicket.getReceivedConsent().click()
pageGrievanceNewTicket.getButtonNext().click()
pageGrievanceNewTicket.getDescription().send_keys("Happy path test 1234!")
pageGrievanceNewTicket.getButtonNext().click()
assert "Happy path test 1234!" in pageGrievanceDetailsPage.getTicketDescription().text
assert "Referral" in pageGrievanceDetailsPage.getTicketCategory().text
assert "New" in pageGrievanceDetailsPage.getTicketStatus().text
assert "Not set" in pageGrievanceDetailsPage.getTicketPriority().text
assert "Not set" in pageGrievanceDetailsPage.getTicketUrgency().text
11 changes: 10 additions & 1 deletion backend/selenium_tests/helpers/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class Common:
DEFAULT_TIMEOUT = 100
DEFAULT_TIMEOUT = 10

def __init__(self, driver: Chrome):
self.driver = driver
Expand Down Expand Up @@ -107,3 +107,12 @@ def screenshot(
) -> None:
sleep(delay_sec)
self.driver.get_screenshot_as_file(os.path.join(f"{file_path}", f"{file_name}.{file_type}"))

def get_value_of_attributes(self, attribute: str = "data-cy") -> None:
sleep(1)
ids = self.driver.find_elements(By.XPATH, f"//*[@{attribute}]")
for ii in ids:
try:
print(f"{ii.text}: {ii.get_attribute(attribute)}") # type: ignore
except BaseException:
print(f"No text: {ii.get_attribute(attribute)}") # type: ignore
32 changes: 18 additions & 14 deletions backend/selenium_tests/page_object/grievance/new_ticket.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 @@ -12,6 +14,7 @@ class NewTicket(BaseComponents):
lookUpTabs = 'button[role="tab"]'
householdTableRow = 'tr[data-cy="household-table-row"]'
individualTableRow = 'tr[data-cy="individual-table-row"]'
tableRow = '[data-cy="table-row"]'
receivedConsent = 'span[data-cy="input-consent"]'
individualID = 'div[data-cy="label-INDIVIDUAL ID"]'
householdID = 'div[data-cy="label-HOUSEHOLD ID"]'
Expand Down Expand Up @@ -61,6 +64,7 @@ class NewTicket(BaseComponents):
individualFieldName = 'div[data-cy="select-individualDataUpdateFields[0].fieldName"]'
inputValue = 'input[data-cy="input-householdDataUpdateFields[0].fieldValue"]'
partner = 'div[data-cy="select-partner"]'
tablePagination = '[data-cy="table-pagination"]'

# Texts
textLookUpHousehold = "LOOK UP HOUSEHOLD"
Expand Down Expand Up @@ -116,16 +120,16 @@ def getOption(self) -> WebElement:
return self.wait_for(self.statusOptions)

def getHouseholdTab(self) -> WebElement:
return self.wait_for(self.lookUpTabs).contains(self.textLookUpHousehold)
return self.wait_for(self.lookUpTabs)

def getIndividualTab(self) -> WebElement:
return self.wait_for(self.lookUpTabs).contains(self.textLookUpIndividual)
return self.wait_for(self.lookUpTabs)

def getHouseholdTableRows(self, number: int) -> WebElement:
return self.wait_for(self.householdTableRow).eq(number)
return self.wait_for(self.householdTableRow)[number]

def getIndividualTableRows(self, number: int) -> WebElement:
return self.wait_for(self.individualTableRow).eq(number)
return self.wait_for(self.individualTableRow)[number]

def getReceivedConsent(self) -> WebElement:
return self.wait_for(self.receivedConsent)
Expand Down Expand Up @@ -274,15 +278,15 @@ def getIndividualFieldName(self) -> WebElement:
def getPartner(self) -> WebElement:
return self.wait_for(self.partner)

def checkElementsOnPage(self) -> None:
self.getTitle().contains(self.textTitle)
self.getButtonNext().contains(self.textNext)
self.getSelectCategory().should("be.visible")
def getTablePagination(self) -> WebElement:
return self.wait_for(self.tablePagination)

def chooseCategory(self, category: str) -> None:
self.getSelectCategory().click()
self.getOption().contains(category).click()
def getTableRow(self) -> WebElement:
return self.wait_for(self.tableRow)

def chooseIssueType(self, issue: str) -> None:
self.getIssueType().should("be.visible").click()
self.getOption().contains(issue).click()
def waitForNoResults(self) -> bool:
for _ in range(10):
if "No results" in self.getTableRow().text:
return True
sleep(1)
return False
2 changes: 1 addition & 1 deletion deployment/docker-compose.selenium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
command: |
bash -c "
waitforit -host=db -port=5432 -timeout=30
pytest -svvv selenium_tests --cov-report xml:./coverage.xml --html=./report/report.html --randomly-seed=42
pytest -svvv selenium_tests --cov-report xml:./coverage.xml --html-report=./report/report.html --randomly-seed=42
"
depends_on:
db:
Expand Down

0 comments on commit 416c153

Please sign in to comment.