Skip to content

Commit

Permalink
converted constant to env setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Tllew committed Jan 7, 2025
1 parent 2d22863 commit 11fc8c7
Showing 18 changed files with 51 additions and 58 deletions.
1 change: 1 addition & 0 deletions conf/caseworker.py
Original file line number Diff line number Diff line change
@@ -134,3 +134,4 @@
# using it here as some browsers still don't support CSP_REPORT_TO which replaces it

CSP_REPORT_URI = env.tuple("CASEWORKER_CSP_REPORT_URI", default=("",))
E2E_WAIT_MULTIPLIER = env.int("E2E_WAIT_MULTIPLIER", default=1)
1 change: 1 addition & 0 deletions conf/exporter.py
Original file line number Diff line number Diff line change
@@ -129,3 +129,4 @@
# using it here as some browsers still don't support CSP_REPORT_TO which replaces it

CSP_REPORT_URI = env.tuple("EXPORTER_CSP_REPORT_URI", default=("",))
E2E_WAIT_MULTIPLIER = env.int("E2E_WAIT_MULTIPLIER", default=1)
5 changes: 0 additions & 5 deletions tests_common/constants.py

This file was deleted.

13 changes: 6 additions & 7 deletions tests_common/functions.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from tests_common.constants import WebDriverDelay


def click_submit(driver: WebDriver):
@@ -71,7 +70,7 @@ def select_multi_select_options(driver: WebDriver, element_selector: str, option
element = driver.find_element(by=By.CSS_SELECTOR, value=element_selector)
element.send_keys(option)
element.send_keys(Keys.ENTER)
WebDriverWait(driver, WebDriverDelay.THIRTY).until(
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located(
(By.XPATH, f"//span[@class='selected-options__option-text' and contains(text(), '{option}')]")
),
@@ -84,17 +83,17 @@ def click_apply_filters(driver: WebDriver):

def open_case_filters(driver: WebDriver):
if not driver.find_element(by=By.CLASS_NAME, value="case-filters").is_displayed():
WebDriverWait(driver, WebDriverDelay.THIRTY).until(
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, "show-filters-link"))
).click()
WebDriverWait(driver, WebDriverDelay.THIRTY).until(
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.element_to_be_clickable((By.ID, "accordion-case-filters"))
).click()


def try_open_filters(driver: WebDriver):
if not driver.find_element(by=By.CLASS_NAME, value="lite-filter-bar").is_displayed():
WebDriverWait(driver, WebDriverDelay.THIRTY).until(
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, "show-filters-link"))
).click()

@@ -116,7 +115,7 @@ def click_next_page(driver: WebDriver):
def select_report_summary_subject_and_fill(driver, subject):
suggestion_input_autocomplete = driver.find_element(by=By.ID, value="_report_summary_subject")
suggestion_input_autocomplete.send_keys(subject)
WebDriverWait(driver, WebDriverDelay.THIRTY).until(
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.text_to_be_present_in_element(
(By.CSS_SELECTOR, ".lite-autocomplete__menu--visible #_report_summary_subject__option--0"),
subject,
@@ -129,7 +128,7 @@ def select_report_summary_subject_and_fill(driver, subject):
def select_report_summary_prefix_and_fill(driver, prefix):
suggestion_input_autocomplete = driver.find_element(by=By.ID, value="_report_summary_prefix")
suggestion_input_autocomplete.send_keys(prefix)
WebDriverWait(driver, WebDriverDelay.THIRTY).until(
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.text_to_be_present_in_element(
(By.CSS_SELECTOR, ".lite-autocomplete__menu--visible #_report_summary_prefix__option--0"),
prefix,
18 changes: 8 additions & 10 deletions ui_tests/caseworker/conftest.py
Original file line number Diff line number Diff line change
@@ -4,10 +4,8 @@
from pytest_bdd import given, when, then, parsers
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from core.constants import CaseStatusEnum
from tests_common.constants import WebDriverDelay
from ui_tests.caseworker.pages.advice import FinalAdvicePage, RecommendationsAndDecisionPage, TeamAdvicePage
from ui_tests.caseworker.pages.case_page import CasePage, CaseTabs
from ui_tests.caseworker.pages.teams_pages import TeamsPages
@@ -285,7 +283,7 @@ def prepare_case(api_test_client, nlr): # noqa
def submit_form(driver): # noqa
old_page = driver.find_element(by=By.TAG_NAME, value="html")
Shared(driver).click_submit()
WebDriverWait(driver, WebDriverDelay.FORTYFIVE).until(expected_conditions.staleness_of(old_page))
WebDriverWait(driver, 45 * settings.E2E_WAIT_MULTIPLIER).until(expected_conditions.staleness_of(old_page))


@when(parsers.parse('I click the text "{text}"'))
@@ -296,7 +294,7 @@ def click_text(driver, text): # noqa

@when(parsers.parse('I click "{button_text}"'))
def click_button_with_text(driver, button_text): # noqa
WebDriverWait(driver, WebDriverDelay.TWENTY).until(
WebDriverWait(driver, 20 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located(
(
By.XPATH,
@@ -397,28 +395,28 @@ def case_list_page(driver, internal_url): # noqa

@when("I go to my profile page") # noqa
def get_profile_page(driver): # noqa
WebDriverWait(driver, WebDriverDelay.THIRTY).until(
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, "link-profile"))
).click()


@when(parsers.parse('I change my team to "{team}" and default queue to "{queue}"')) # noqa
def go_to_team_edit_page(driver, team, queue): # noqa
# we should already be on the profile page
WebDriverWait(driver, WebDriverDelay.THIRTY).until(
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, "link-edit-team"))
).click()
teams_page = TeamsPages(driver)
teams_page.select_team_from_dropdown(team)
teams_page.select_default_queue_from_dropdown(queue)
functions.click_submit(driver)
# Ensure we return to the profile page
WebDriverWait(driver, WebDriverDelay.THIRTY).until(
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, "link-edit-team"))
)
# Check that the team/queue change was applied successfully
assert driver.find_element(by=By.ID, value="user-team-name").text == team
WebDriverWait(driver, WebDriverDelay.THIRTY)
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER)
assert driver.find_element(by=By.ID, value="user-default-queue").text == queue


@@ -440,7 +438,7 @@ def system_queue_shown_in_dropdown(driver, queue_name): # noqa
@when(parsers.parse('I switch to "{queue_name}" queue')) # noqa
def switch_to_queue(driver, queue_name): # noqa
driver.find_element(by=By.ID, value="link-queue").click()
WebDriverWait(driver, WebDriverDelay.THIRTY).until(
WebDriverWait(driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, "filter-queues"))
)
driver.find_element(by=By.ID, value="filter-queues").send_keys(queue_name)
@@ -688,7 +686,7 @@ def click_edit_case_flags_link(driver, flag_name):

old_page = driver.find_element(by=By.TAG_NAME, value="html")
functions.click_submit(driver)
WebDriverWait(driver, WebDriverDelay.FORTYFIVE).until(expected_conditions.staleness_of(old_page))
WebDriverWait(driver, 45 * settings.E2E_WAIT_MULTIPLIER).until(expected_conditions.staleness_of(old_page))


@given(parsers.parse('the status is set to "{status}"')) # noqa
4 changes: 2 additions & 2 deletions ui_tests/caseworker/pages/BasePage.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
from selenium.webdriver.support.wait import WebDriverWait

from tests_common import functions
from tests_common.constants import WebDriverDelay
from django.conf import settings


class BasePage:
@@ -13,7 +13,7 @@ def __init__(self, driver: WebDriver):

# Wait for the cases list to load before interacting with the page
if functions.element_with_id_exists(self.driver, "link-queue"):
WebDriverWait(driver, WebDriverDelay.SIXTY).until(
WebDriverWait(driver, 60 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.visibility_of_element_located((By.ID, "all-cases-tab"))
)

4 changes: 2 additions & 2 deletions ui_tests/caseworker/pages/add_denial_records_page.py
Original file line number Diff line number Diff line change
@@ -7,15 +7,15 @@
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from tests_common.constants import WebDriverDelay
from django.conf import settings
from ui_tests.caseworker.pages.BasePage import BasePage


class AddDenialRecordsPage(BasePage):
CSV_FILE_LOCATION = "/tmp/downloads/example-denials.csv"

def download_example_csv_file(self):
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.LINK_TEXT, "Download an example .csv file"))
).click()

14 changes: 7 additions & 7 deletions ui_tests/caseworker/pages/application_page.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
from selenium.webdriver.support.ui import Select

from tests_common import functions
from tests_common.constants import WebDriverDelay
from django.conf import settings
from ui_tests.caseworker.pages.BasePage import BasePage
from tests_common.tools.helpers import scroll_to_element_by_id
from tests_common.tools.helpers import scroll_to_element_below_header_by_id
@@ -68,7 +68,7 @@ def get_case_copy_of_field_href(self):
return self.driver.find_element(by=By.ID, value=self.CASE_COPY_OF_ID).get_attribute("href")

def click_visible_to_exporter_checkbox(self):
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, self.IS_VISIBLE_TO_EXPORTER_CHECKBOX_ID))
).click()

@@ -83,15 +83,15 @@ def get_text_of_case_note_field(self):
return self.driver.find_element(by=By.ID, value=self.INPUT_CASE_NOTE_ID).text

def click_post_note_btn(self):
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located(
(By.CSS_SELECTOR, f"#{self.BUTTON_POST_NOTE_ID}:not([disabled])")
)
)
functions.click_submit(self.driver)

def click_cancel_btn(self):
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, self.LINK_CANCEL_NOTE_ID))
).click()

@@ -151,7 +151,7 @@ def select_a_good(self):
self.driver.execute_script("arguments[0].click();", element)

def click_move_case_button(self):
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, self.MOVE_CASE_BUTTON))
).click()

@@ -242,7 +242,7 @@ def click_assign_user_button(self):
self.driver.find_element(by=By.ID, value=self.ASSIGN_USER_ID).click()

def click_im_done_button(self):
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, self.BUTTON_IM_DONE_ID))
).click()

@@ -306,7 +306,7 @@ def get_matches(self, match_type):
"""Return a list of names that have denial matches based on
the supplied match_type - one of "PARTIAL MATCH" or "EXACT MATCH".
"""
table = WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
table = WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.XPATH, "//table[@id='table-denial-matches']"))
)

6 changes: 3 additions & 3 deletions ui_tests/caseworker/pages/case_list_page.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select

from tests_common.constants import WebDriverDelay
from django.conf import settings
from ui_tests.caseworker.pages.BasePage import BasePage
from ui_tests.caseworker.pages.shared import Shared
from tests_common import functions
@@ -155,7 +155,7 @@ def click_on_queue_title(self):
self.driver.find_element(by=By.ID, value=self.LINK_CHANGE_QUEUE_ID).click()

def search_for_queue(self, queue_name):
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, self.QUEUE_SEARCH_BOX))
)
self.driver.find_element(by=By.ID, value=self.QUEUE_SEARCH_BOX).send_keys(queue_name)
@@ -217,6 +217,6 @@ def click_checkbox_to_show_team_ecju_query_and_hidden_cases(self):
return self.driver.find_element(by=By.ID, value=self.SHOW_TEAM_ECJU_AND_HIDDEN_CASES).click()

def click_export_enforcement_xml(self):
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, self.EXPORT_ENFORCEMENT_XML_BUTTON_ID))
).click()
4 changes: 2 additions & 2 deletions ui_tests/caseworker/pages/case_page.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from tests_common.constants import WebDriverDelay
from django.conf import settings
from ui_tests.caseworker.pages.shared import Shared
from ui_tests.caseworker.pages.BasePage import BasePage
from tests_common import selectors
@@ -129,7 +129,7 @@ def is_flag_applied(self, flag_name):

self.driver.find_element(by=By.ID, value="candy-flags").click()

WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, POPUP_FLAGS_ID))
)

4 changes: 2 additions & 2 deletions ui_tests/caseworker/pages/header_page.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tests_common.constants import WebDriverDelay
from django.conf import settings
from ui_tests.caseworker.pages.BasePage import BasePage
from tests_common.tools.wait import wait_until_page_is_loaded

@@ -22,7 +22,7 @@ def click_lite_menu(self):
self.driver.find_element(by=By.ID, value=self.MENU_BUTTON).click()

def click_organisations(self):
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.CSS_SELECTOR, self.ORGANISATIONS_LINK))
).click()

6 changes: 3 additions & 3 deletions ui_tests/caseworker/pages/product_assessment.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
from selenium.webdriver.support.wait import WebDriverWait

from tests_common import functions
from tests_common.constants import WebDriverDelay
from django.conf import settings
from ui_tests.caseworker.pages.BasePage import BasePage


@@ -24,7 +24,7 @@ def assess_report_summary_prefix(self, ars_prefix):
ars_prefix_element = self.driver.find_element(by=By.ID, value="report_summary_prefix_container")
ars_prefix_input = ars_prefix_element.find_element(by=By.ID, value="_report_summary_prefix")
ars_prefix_input.send_keys(ars_prefix)
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, "_report_summary_prefix__listbox"))
)

@@ -40,7 +40,7 @@ def assess_report_summary_subject(self, ars_subject):
ars_subject_element = self.driver.find_element(by=By.ID, value="report_summary_subject_container")
ars_subject_input = ars_subject_element.find_element(by=By.ID, value="_report_summary_subject")
ars_subject_input.send_keys(ars_subject)
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.ID, "_report_summary_subject__listbox"))
)

6 changes: 3 additions & 3 deletions ui_tests/caseworker/pages/shared.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
from selenium.webdriver.support.wait import WebDriverWait

from tests_common import functions
from tests_common.constants import WebDriverDelay
from django.conf import settings
from ui_tests.caseworker.pages.BasePage import BasePage
from tests_common.tools.helpers import scroll_to_element_by_id

@@ -123,14 +123,14 @@ def click_first_link_in_row(self):

def expand_govuk_details(self):
self.driver.find_element(by=By.CLASS_NAME, value=self.GOVUK_DETAILS).click()
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located(
(By.XPATH, f"//*[contains(@class, '{self.GOVUK_DETAILS}') and ancestor::details/@open]")
)
)

def try_open_filters(self):
WebDriverWait(self.driver, WebDriverDelay.THIRTY).until(
WebDriverWait(self.driver, 30 * settings.E2E_WAIT_MULTIPLIER).until(
expected_conditions.presence_of_element_located((By.CLASS_NAME, "lite-filter-bar"))
)

4 changes: 2 additions & 2 deletions ui_tests/caseworker/step_defs/test_documents.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from tests_common.constants import WebDriverDelay
from django.conf import settings
from ui_tests.caseworker.pages.application_page import ApplicationPage
from ui_tests.caseworker.pages.attach_document_page import AttachDocumentPage
from ui_tests.caseworker.pages.documents_page import DocumentsPage
@@ -29,7 +29,7 @@ def upload_a_file(driver, filename, description, tmp_path):

old_page = driver.find_element(by=By.TAG_NAME, value="html")
attach_document_page.click_submit_btn()
WebDriverWait(driver, WebDriverDelay.FORTYFIVE).until(expected_conditions.staleness_of(old_page))
WebDriverWait(driver, 45 * settings.E2E_WAIT_MULTIPLIER).until(expected_conditions.staleness_of(old_page))


@then(parsers.parse('I see a file with filename "{filename}" is uploaded'))
Loading

0 comments on commit 11fc8c7

Please sign in to comment.