Compare commits
7 Commits
cas_typehi
...
main
Author | SHA1 | Date | |
---|---|---|---|
265838b36b | |||
5f0c77c499 | |||
98ec8e0e3d | |||
104eab4e90 | |||
3bd09a9ef4 | |||
f228527c65 | |||
b91c04774d |
|
@ -10,6 +10,7 @@ from selenium import webdriver
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
|
from selenium.webdriver.common.action_chains import ActionChains
|
||||||
|
|
||||||
from typing import Tuple, List
|
from typing import Tuple, List
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ class BaseTester:
|
||||||
self.user = user
|
self.user = user
|
||||||
self.passwd = passwd
|
self.passwd = passwd
|
||||||
if dev:
|
if dev:
|
||||||
self.base_url = "https://crm.staging.caat.org.uk"
|
self.base_url = "https://crm.dev.caat.org.uk"
|
||||||
else:
|
else:
|
||||||
self.base_url = "https://crm.staging.caat.org.uk"
|
self.base_url = "https://crm.staging.caat.org.uk"
|
||||||
|
|
||||||
|
@ -128,6 +129,10 @@ class BaseTester:
|
||||||
self.logout()
|
self.logout()
|
||||||
self.browser.close()
|
self.browser.close()
|
||||||
|
|
||||||
|
def find_element(self, *args, **kwargs):
|
||||||
|
"""Alias for browser.find_element"""
|
||||||
|
return self.browser.find_element(*args, **kwargs)
|
||||||
|
|
||||||
def find_element_by_id(self, *args, **kwargs):
|
def find_element_by_id(self, *args, **kwargs):
|
||||||
"""Alias for browser.find_element_by_id"""
|
"""Alias for browser.find_element_by_id"""
|
||||||
return self.browser.find_element_by_id(*args, **kwargs)
|
return self.browser.find_element_by_id(*args, **kwargs)
|
||||||
|
@ -144,6 +149,13 @@ class BaseTester:
|
||||||
"""Alias for using inbuilt wait object for wait.until(EC.element_to_be_clickable)"""
|
"""Alias for using inbuilt wait object for wait.until(EC.element_to_be_clickable)"""
|
||||||
return self.wait.until(EC.element_to_be_clickable(locator))
|
return self.wait.until(EC.element_to_be_clickable(locator))
|
||||||
|
|
||||||
|
def get_tab_selector(self, tabtitle):
|
||||||
|
"""Return an XPATH string to the tab labelled `tablabel`."""
|
||||||
|
return "//li/a[@title='{label}']/..".format(label=tabtitle)
|
||||||
|
|
||||||
|
def get_actions_dropdown_option_selector(self, optionlabel):
|
||||||
|
"""Return an XPATH string to the option labelled `optionlabel` (This is not a normal dropdown)."""
|
||||||
|
return "//div[text()='{label}']".format(label=optionlabel)
|
||||||
|
|
||||||
class SearchExportTester(BaseTester):
|
class SearchExportTester(BaseTester):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -177,18 +189,13 @@ class SearchExportTester(BaseTester):
|
||||||
self.wait_until_visible((By.ID, "alpha-filter"))
|
self.wait_until_visible((By.ID, "alpha-filter"))
|
||||||
self.debug("table of results has loaded")
|
self.debug("table of results has loaded")
|
||||||
|
|
||||||
def _select_option_from_magic_dropdown(self, option_id: str):
|
def _select_option_from_magic_dropdown_label(self, option_label: str):
|
||||||
"""
|
|
||||||
Wrapper to click an option from the dropdown menu within the search on civicrm.
|
|
||||||
Magic dropdown because it literally is not how dropdowns should work at all
|
|
||||||
All options have an ID but this can change depending on the context of how you get to the search page
|
|
||||||
MUST BE CALLED WHEN ON THE SEARCH RESULTS PAGE
|
|
||||||
"""
|
|
||||||
self.debug("exporting results using the magic dropdown")
|
|
||||||
self.find_element_by_id(self.contact_selectall_id).click()
|
self.find_element_by_id(self.contact_selectall_id).click()
|
||||||
self.find_element_by_id(self.contact_dropdown_id).click()
|
self.find_element_by_id(self.contact_dropdown_id).click()
|
||||||
self.find_element_by_id(option_id).click()
|
self.wait_until_visible((By.XPATH, self.get_actions_dropdown_option_selector(option_label)))
|
||||||
self.wait_until_visible((By.CSS_SELECTOR, ".crm-block"))
|
option = self.find_element(By.XPATH, self.get_actions_dropdown_option_selector(option_label))
|
||||||
|
ActionChains(self.browser).move_to_element(option).perform()
|
||||||
|
option.click()
|
||||||
|
|
||||||
def download_export(self, data: dict) -> requests.Response:
|
def download_export(self, data: dict) -> requests.Response:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -14,10 +14,10 @@ class TestActivitiesTab(BaseTester):
|
||||||
def _test(self, cid: str):
|
def _test(self, cid: str):
|
||||||
self.debug("loading contact page for CID %s" % cid)
|
self.debug("loading contact page for CID %s" % cid)
|
||||||
self.browser.get(self.contact_page.format(cid))
|
self.browser.get(self.contact_page.format(cid))
|
||||||
self.wait_until_visible((By.ID, "ui-id-10"))
|
self.wait_until_visible((By.XPATH, self.get_tab_selector("Activities")))
|
||||||
# Contact page as loaded
|
# Contact page as loaded
|
||||||
activities_tab_button = self.find_element_by_id("ui-id-10")
|
activities_tab_button = self.find_element(By.XPATH, self.get_tab_selector("Activities"))
|
||||||
num_element = activities_tab_button.find_element_by_tag_name("em")
|
num_element = activities_tab_button.find_element(By.TAG_NAME, "em")
|
||||||
num_of_activ = int(num_element.text)
|
num_of_activ = int(num_element.text)
|
||||||
activities_tab_button.click()
|
activities_tab_button.click()
|
||||||
table_row_selector = (
|
table_row_selector = (
|
||||||
|
@ -65,4 +65,4 @@ class TestActivitiesTab(BaseTester):
|
||||||
cid_na = "42269" # Nigel Addams
|
cid_na = "42269" # Nigel Addams
|
||||||
#cid_db = "43193" Use to test 100 max limit
|
#cid_db = "43193" Use to test 100 max limit
|
||||||
cid_tuple = (cid_da, cid_kh, cid_na)
|
cid_tuple = (cid_da, cid_kh, cid_na)
|
||||||
self._test_all(cid_tuple)
|
self._test_all(cid_tuple)
|
||||||
|
|
|
@ -2,6 +2,8 @@ import csv
|
||||||
import io
|
import io
|
||||||
|
|
||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.common.keys import Keys
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.support.select import Select
|
||||||
|
|
||||||
from .base import SearchExportTester
|
from .base import SearchExportTester
|
||||||
|
|
||||||
|
@ -14,8 +16,6 @@ class TestContactExport(SearchExportTester):
|
||||||
self.desc(
|
self.desc(
|
||||||
"Testing if exporting contacts from a search returns a CSV file with all expected contacts."
|
"Testing if exporting contacts from a search returns a CSV file with all expected contacts."
|
||||||
)
|
)
|
||||||
# FIXME: THIS FUCKING CHANGES!!!!!!
|
|
||||||
# If you are having issues with the tests, go back and try and find the id for the item in the drop down. its all stupid js so we have to hack it like this and press it instead of post request
|
|
||||||
self.contact_exportoption_id = "select2-result-label-13"
|
self.contact_exportoption_id = "select2-result-label-13"
|
||||||
|
|
||||||
def download_csv(self):
|
def download_csv(self):
|
||||||
|
@ -64,7 +64,7 @@ class TestContactExport(SearchExportTester):
|
||||||
self.debug("searching for contacts with term '%s'" % search_term)
|
self.debug("searching for contacts with term '%s'" % search_term)
|
||||||
self._wait_for_search_to_load()
|
self._wait_for_search_to_load()
|
||||||
result_no = self._get_contact_search_number()
|
result_no = self._get_contact_search_number()
|
||||||
self._select_option_from_magic_dropdown(self.contact_exportoption_id)
|
self._select_option_from_magic_dropdown_label("Export contacts")
|
||||||
|
|
||||||
exported_number_exports = self.calculate_exported_contacts_number()
|
exported_number_exports = self.calculate_exported_contacts_number()
|
||||||
if exported_number_exports == (result_no):
|
if exported_number_exports == (result_no):
|
||||||
|
|
|
@ -33,7 +33,7 @@ class TestSteeringCommitteePrintLabels(SearchExportTester):
|
||||||
self._wait_for_search_to_load()
|
self._wait_for_search_to_load()
|
||||||
result_no = self._get_contact_search_number()
|
result_no = self._get_contact_search_number()
|
||||||
self.debug("exporting results using the magic dropdown")
|
self.debug("exporting results using the magic dropdown")
|
||||||
self._select_option_from_magic_dropdown(self.mail_label_option)
|
self._select_option_from_magic_dropdown_label("Mailing labels - print")
|
||||||
# By omitting the field, we are effectively disabling the do not mail filter
|
# By omitting the field, we are effectively disabling the do not mail filter
|
||||||
data = {
|
data = {
|
||||||
"_qf_default": "Label:submit",
|
"_qf_default": "Label:submit",
|
||||||
|
|
4
main.py
4
main.py
|
@ -31,8 +31,8 @@ if __name__ == "__main__":
|
||||||
cl_arg = (
|
cl_arg = (
|
||||||
arguments.user, arguments.passwd, arguments.dev, arguments.show_browser
|
arguments.user, arguments.passwd, arguments.dev, arguments.show_browser
|
||||||
)
|
)
|
||||||
TestActivitiesTab(*cl_arg).test_all_hardcoded_contacts()
|
#TestActivitiesTab(*cl_arg).test_all_hardcoded_contacts()
|
||||||
TestContactExport(*cl_arg).test_hardcoded_search_terms()
|
#TestContactExport(*cl_arg).test_hardcoded_search_terms()
|
||||||
TestSteeringCommitteePrintLabels(*cl_arg).test()
|
TestSteeringCommitteePrintLabels(*cl_arg).test()
|
||||||
|
|
||||||
# Mailing list
|
# Mailing list
|
||||||
|
|
Loading…
Reference in New Issue
Block a user