From 5f0c77c499535cfee78b155d837a3f6cbc1e2e0b Mon Sep 17 00:00:00 2001 From: Cassowary Rusnov Date: Thu, 3 Feb 2022 21:21:20 -0800 Subject: [PATCH] Fix export contacts test. Squashed commit of the following: commit 81d88bd69775edbbe7018038df60f266357171da Author: Cassowary Rusnov Date: Thu Feb 3 21:20:51 2022 -0800 mob next [ci-skip] [ci skip] [skip ci] commit f3639dbaccfd0f28d8ffb285993b688e94136fad Author: naomi Date: Fri Feb 4 07:04:16 2022 +0200 mob next [ci-skip] [ci skip] [skip ci] Co-authored-by: naomi --- civicrm_tester/base.py | 17 +++++++---------- civicrm_tester/test_contact_export.py | 6 +++--- main.py | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/civicrm_tester/base.py b/civicrm_tester/base.py index 5d3d525..928b34f 100644 --- a/civicrm_tester/base.py +++ b/civicrm_tester/base.py @@ -152,6 +152,9 @@ class BaseTester: """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): def __init__(self, *args, **kwargs): @@ -185,18 +188,12 @@ class SearchExportTester(BaseTester): self.wait_until_visible((By.ID, "alpha-filter")) self.debug("table of results has loaded") - def _select_option_from_magic_dropdown(self, option_id: 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") + def _select_option_from_magic_dropdown_label(self, option_label: str): 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(option_id).click() - self.wait_until_visible((By.CSS_SELECTOR, ".crm-block")) + self.wait_until_visible((By.XPATH, self.get_actions_dropdown_option_selector(option_label))) + contact_export_option = self.find_element(By.XPATH, self.get_actions_dropdown_option_selector(option_label)) + contact_export_option.click() def download_export(self, data: dict) -> requests.Response: """ diff --git a/civicrm_tester/test_contact_export.py b/civicrm_tester/test_contact_export.py index 89c7ec1..e7f68a5 100644 --- a/civicrm_tester/test_contact_export.py +++ b/civicrm_tester/test_contact_export.py @@ -2,6 +2,8 @@ import csv import io 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 @@ -14,8 +16,6 @@ class TestContactExport(SearchExportTester): self.desc( "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" def download_csv(self): @@ -64,7 +64,7 @@ class TestContactExport(SearchExportTester): self.debug("searching for contacts with term '%s'" % search_term) self._wait_for_search_to_load() 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() if exported_number_exports == (result_no): diff --git a/main.py b/main.py index c1c0a43..d1738e3 100644 --- a/main.py +++ b/main.py @@ -31,9 +31,9 @@ if __name__ == "__main__": cl_arg = ( 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() - TestSteeringCommitteePrintLabels(*cl_arg).test() + #TestSteeringCommitteePrintLabels(*cl_arg).test() # Mailing list # Load mailing list test and enter test data