Files
notifications-admin/tests/end_to_end/test_create_new_template.py

195 lines
6.6 KiB
Python
Raw Normal View History

2025-06-09 09:34:13 -07:00
import datetime
2024-03-27 10:21:01 -07:00
import os
import re
import uuid
from playwright.sync_api import expect
2024-10-07 11:02:04 -07:00
2024-10-07 10:45:02 -07:00
from tests.end_to_end.conftest import check_axe_report
2024-03-27 10:21:01 -07:00
E2E_TEST_URI = os.getenv("NOTIFY_E2E_TEST_URI")
2025-06-09 12:08:10 -07:00
def create_new_template(page):
2024-03-27 10:21:01 -07:00
2024-03-27 10:35:09 -07:00
current_service_link = page.get_by_text("Current service")
expect(current_service_link).to_be_visible()
current_service_link.click()
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
2024-10-07 10:45:02 -07:00
check_axe_report(page)
2024-03-27 12:15:44 -07:00
send_messages_button = page.get_by_role("link", name="Send messages")
2024-04-09 10:41:54 -07:00
expect(send_messages_button).to_be_visible()
2024-03-27 10:52:22 -07:00
send_messages_button.click()
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
2024-10-07 10:45:02 -07:00
check_axe_report(page)
Removed all govuk css (#2814) * Removed all govuk css * Updated reference files * Removing govuk js * Fixed casing for modules, removed unused page * Got more reference images * Updated template page * Removed govuk padding util * Updated hint to uswds hint * More govuk cleanup * Commiting backstopjs ref files * Fixed all unit tests that broke due to brittleness around govuk styling * Added new ref images * Final removal of govuk * Officially removed all govuk references * Updated reference file * Updated link to button * UI modernization * Cleanup * removed govuk escaping tests since they are no longer needed * Fix CodeQL security issue in escapeElementName function - Escape backslashes first before other special characters - Prevents potential double-escaping vulnerability - Addresses CodeQL alert about improper string escaping * Found more govuk removal. Fixed unit tests * Add missing pipeline check to pre-commit * updated test * Updated e2e test * More update to e2e test * Fixed another e2e test * Simple PR comments addressed * More updates * Updated backstop ref files * Refactored folder selection for non-admins * Updated redundant line * Updated tests to include correct mocks * Added more ref files * Addressing carlos comments * Addressing Carlo comments, cleanup of window initing * More cleanup and addressing carlo comments * Fixing a11 scan * Fixed a few issues with javascript * Fixed for pr * Fixing e2e tests * Tweaking e2e test * Added more ref files and cleaned up urls.js * Fixed bug with creating new template * Removed brittle test - addressed code ql comment * e2e race condition fix * More e2e test fixes * Updated e2e tests to not wait for text sent * Updated test to not wait for button click response * Made tear down more resilent if staging is down * reverted e2e test to what was working before main merge * Updated backstopRef images * Updated gulp to include job-polling differently
2025-10-06 09:38:54 -04:00
create_template_button = page.get_by_text("New template")
2024-03-27 10:21:01 -07:00
expect(create_template_button).to_be_visible()
create_template_button.click()
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
2024-10-07 10:45:02 -07:00
check_axe_report(page)
2024-03-27 10:21:01 -07:00
start_with_a_blank_template_radio = page.get_by_text("Start with a blank template")
expect(start_with_a_blank_template_radio).to_be_visible()
start_with_a_blank_template_radio.click()
continue_button = page.get_by_role("button", name="Continue")
expect(continue_button).to_be_visible()
continue_button.click()
page.wait_for_load_state("domcontentloaded")
2024-10-07 10:45:02 -07:00
check_axe_report(page)
Removed all govuk css (#2814) * Removed all govuk css * Updated reference files * Removing govuk js * Fixed casing for modules, removed unused page * Got more reference images * Updated template page * Removed govuk padding util * Updated hint to uswds hint * More govuk cleanup * Commiting backstopjs ref files * Fixed all unit tests that broke due to brittleness around govuk styling * Added new ref images * Final removal of govuk * Officially removed all govuk references * Updated reference file * Updated link to button * UI modernization * Cleanup * removed govuk escaping tests since they are no longer needed * Fix CodeQL security issue in escapeElementName function - Escape backslashes first before other special characters - Prevents potential double-escaping vulnerability - Addresses CodeQL alert about improper string escaping * Found more govuk removal. Fixed unit tests * Add missing pipeline check to pre-commit * updated test * Updated e2e test * More update to e2e test * Fixed another e2e test * Simple PR comments addressed * More updates * Updated backstop ref files * Refactored folder selection for non-admins * Updated redundant line * Updated tests to include correct mocks * Added more ref files * Addressing carlos comments * Addressing Carlo comments, cleanup of window initing * More cleanup and addressing carlo comments * Fixing a11 scan * Fixed a few issues with javascript * Fixed for pr * Fixing e2e tests * Tweaking e2e test * Added more ref files and cleaned up urls.js * Fixed bug with creating new template * Removed brittle test - addressed code ql comment * e2e race condition fix * More e2e test fixes * Updated e2e tests to not wait for text sent * Updated test to not wait for button click response * Made tear down more resilent if staging is down * reverted e2e test to what was working before main merge * Updated backstopRef images * Updated gulp to include job-polling differently
2025-10-06 09:38:54 -04:00
template_name_input = page.locator('input[type="text"]:visible').first
2024-03-27 10:21:01 -07:00
expect(template_name_input).to_be_visible()
template_name = str(uuid.uuid4())
template_name_input.fill(template_name)
message_input = page.get_by_role("textbox", name="Message")
expect(message_input).to_be_visible()
2024-03-27 12:32:29 -07:00
message = "Test message for e2e test"
2024-03-27 10:21:01 -07:00
message_input.fill(message)
save_button = page.get_by_text("Save")
expect(save_button).to_be_visible()
save_button.click()
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
2024-10-07 10:45:02 -07:00
check_axe_report(page)
2024-03-27 10:21:01 -07:00
use_this_template_button = page.get_by_text("Use this template")
expect(use_this_template_button).to_be_visible()
use_this_template_button.click()
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
use_my_phone_number_link = page.get_by_text("Use my phone number")
expect(use_my_phone_number_link).to_be_visible()
use_my_phone_number_link.click()
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
preview_button = page.get_by_text("Preview")
2025-06-09 12:18:38 -07:00
expect(preview_button).to_be_visible()
preview_button.click()
2024-03-27 10:21:01 -07:00
# Check to make sure that we've arrived at the next page.
2025-06-09 12:18:38 -07:00
page.wait_for_load_state("domcontentloaded")
check_axe_report(page)
2024-10-07 10:45:02 -07:00
2024-03-27 12:40:45 -07:00
# We are not going to send the message for this test, we just want to confirm
# that the template has been created and we are now seeing the message from the
# template in the preview.
2025-06-09 12:15:54 -07:00
# assert "Test message for e2e test" in page.content()
2024-03-27 10:21:01 -07:00
2025-06-09 10:07:04 -07:00
def test_create_new_template(end_to_end_context):
2025-06-09 09:34:13 -07:00
page = end_to_end_context.new_page()
page.goto(f"{E2E_TEST_URI}/sign-in")
# Wait for the next page to fully load.
page.wait_for_load_state("domcontentloaded")
check_axe_report(page)
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
current_date_time = datetime.datetime.now()
new_service_name = "E2E Federal Test Service {now} - {browser_type}".format(
now=current_date_time.strftime("%m/%d/%Y %H:%M:%S"),
browser_type=page.context.browser.browser_type.name,
)
page.goto(f"{E2E_TEST_URI}/accounts")
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
check_axe_report(page)
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Check to make sure that we've arrived at the next page.
# Check the page title exists and matches what we expect.
expect(page).to_have_title(re.compile("Choose service"))
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Check for the sign in heading.
sign_in_heading = page.get_by_role("heading", name="Choose service")
expect(sign_in_heading).to_be_visible()
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Retrieve some prominent elements on the page for testing.
2025-11-05 09:24:31 -05:00
add_service_button = page.get_by_role("button", name=re.compile("Add service"))
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
expect(add_service_button).to_be_visible()
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
existing_service_link = page.get_by_role("link", name=new_service_name)
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Check to see if the service was already created - if so, we should fail.
# TODO: Figure out how to make this truly isolated, and/or work in a
# delete service workflow.
expect(existing_service_link).to_have_count(0)
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Click on add a new service.
add_service_button.click()
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
check_axe_report(page)
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Check for the sign in heading.
about_heading = page.get_by_role("heading", name="About your service")
expect(about_heading).to_be_visible()
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Retrieve some prominent elements on the page for testing.
service_name_input = page.locator('xpath=//input[@name="name"]')
add_service_button = page.get_by_role("button", name=re.compile("Add service"))
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
expect(service_name_input).to_be_visible()
expect(add_service_button).to_be_visible()
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Fill in the form.
service_name_input.fill(new_service_name)
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Click on add service.
add_service_button.click()
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
check_axe_report(page)
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
# TODO this fails on staging due to duplicate results on 'get_by_text'
# Check for the service name title and heading.
# service_heading = page.get_by_text(new_service_name, exact=True)
# expect(service_heading).to_be_visible()
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
expect(page).to_have_title(re.compile(new_service_name))
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
create_new_template(page)
2025-06-05 10:01:57 -07:00
2025-06-09 09:34:13 -07:00
_teardown(page)
2024-03-27 10:21:01 -07:00
def _teardown(page):
page.click("text='Settings'")
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
2024-10-07 10:45:02 -07:00
check_axe_report(page)
2024-03-27 10:21:01 -07:00
page.click("text='Delete this service'")
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
2024-10-07 10:45:02 -07:00
check_axe_report(page)
2024-03-27 10:21:01 -07:00
page.click("text='Yes, delete'")
# Check to make sure that we've arrived at the next page.
page.wait_for_load_state("domcontentloaded")
2024-10-07 10:45:02 -07:00
check_axe_report(page)
2024-03-27 10:21:01 -07:00
# Check to make sure that we've arrived at the next page.
# Check the page title exists and matches what we expect.
expect(page).to_have_title(re.compile("Choose service"))