diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b8a4598ca..564061536c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -226,6 +226,7 @@ jobs: run selenium - name: Upload Artifact uses: actions/upload-artifact@v4 + if: always() continue-on-error: true with: name: report @@ -233,6 +234,7 @@ jobs: retention-days: 5 - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 + if: always() continue-on-error: true with: files: ./backend/coverage.xml diff --git a/backend/selenium_tests/conftest.py b/backend/selenium_tests/conftest.py index f9b390e17c..ac2900d029 100644 --- a/backend/selenium_tests/conftest.py +++ b/backend/selenium_tests/conftest.py @@ -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 @@ -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( diff --git a/backend/selenium_tests/girevance/grievance_tickets/test_grievance_tickets.py b/backend/selenium_tests/girevance/grievance_tickets/test_grievance_tickets.py index fa4442db23..8bd94ef4aa 100644 --- a/backend/selenium_tests/girevance/grievance_tickets/test_grievance_tickets.py +++ b/backend/selenium_tests/girevance/grievance_tickets/test_grievance_tickets.py @@ -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) @@ -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 diff --git a/backend/selenium_tests/helpers/helper.py b/backend/selenium_tests/helpers/helper.py index 4245ed6c1d..1e368da1d9 100644 --- a/backend/selenium_tests/helpers/helper.py +++ b/backend/selenium_tests/helpers/helper.py @@ -11,7 +11,7 @@ class Common: - DEFAULT_TIMEOUT = 100 + DEFAULT_TIMEOUT = 10 def __init__(self, driver: Chrome): self.driver = driver @@ -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 diff --git a/backend/selenium_tests/page_object/grievance/new_ticket.py b/backend/selenium_tests/page_object/grievance/new_ticket.py index 8d57dfb4b0..45b8633d8a 100644 --- a/backend/selenium_tests/page_object/grievance/new_ticket.py +++ b/backend/selenium_tests/page_object/grievance/new_ticket.py @@ -1,3 +1,5 @@ +from time import sleep + from page_object.base_components import BaseComponents from selenium.webdriver.remote.webelement import WebElement @@ -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"]' @@ -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" @@ -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) @@ -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 diff --git a/deployment/docker-compose.selenium.yml b/deployment/docker-compose.selenium.yml index 3940dd0634..7d17e14278 100644 --- a/deployment/docker-compose.selenium.yml +++ b/deployment/docker-compose.selenium.yml @@ -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: