from selenium.webdriver.common.by import By from selenium.webdriver.support.select import Select from .base import BaseTester class TestActivitiesTab(BaseTester): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.title("Activities Tab") self.desc("Testing if a contacts activities tab displays all activies") self.contact_page = self.base_url + "/civicrm/contact/view/?reset=1&cid={}" def _test(self, cid: str): self.debug("loading contact page for CID %s" % cid) self.browser.get(self.contact_page.format(cid)) self.wait_until_visible((By.ID, "ui-id-10")) # Contact page as loaded activities_tab_button = self.find_element_by_id("ui-id-10") num_element = activities_tab_button.find_element_by_tag_name("em") num_of_activ = int(num_element.text) activities_tab_button.click() table_row_selector = ( By.CSS_SELECTOR, "#DataTables_Table_0 > tbody tr" ) self.debug( "clicked activities button and waiting for activities page to load" ) self.wait_until_visible(table_row_selector) # Activities page as now loaded table_length_dropdown = Select( self.browser.find_element_by_xpath( "//select[@name='DataTables_Table_0_length']" ) ) table_length_dropdown.select_by_visible_text("100") self.wait_until_clickable(table_row_selector) num_of_rows = len( self.browser.find_elements_by_css_selector("tr.crm-entity") ) if num_of_activ == num_of_rows: self.passed( "expected number of activities found in activity table for CID %s. Expected: %d, Actual %d" % (cid, num_of_activ, num_of_rows) ) elif num_of_activ > 100 and num_of_rows == 100: self.issue( "Number of activities for CID %s is above 100. This is the max amount the table can display. The table is displaying 100 entries. Pagination is not supported by the script." % cid ) else: self.failed( "Number of activities is lower than expected for CID %s. Most likely didn't load properly Expected: %d, Actual %d" % (cid, num_of_activ, num_of_rows) ) def test_all_hardcoded_contacts(self): """Loops self.test with all hardcoded contact ID's Using MP's as MP's are public knowledge and often have activities within the crm system names provided in comments here for debugging purposes """ # There where originally MP's but this seems to have changes to just random people. Still works fine but it is weird cid_da = "42219" # Debbie Abrahams cid_kh = "82163" # Kate Hollern cid_na = "42269" # Nigel Addams #cid_db = "43193" Use to test 100 max limit cid_tuple = (cid_da, cid_kh, cid_na) self._test_all(cid_tuple)