|
| 1 | +import settings |
| 2 | +from time import sleep |
| 3 | + |
| 4 | +from selenium.webdriver.common.by import By |
| 5 | +from base.locators import Locator, GroupLocator, BaseElement |
| 6 | + |
| 7 | + |
| 8 | +class EmberCreateProjectModal(BaseElement): |
| 9 | + |
| 10 | + modal = Locator(By.CLASS_NAME, 'modal-dialog') |
| 11 | + create_project_button = Locator(By.CSS_SELECTOR, '[data-test-create-project-submit]') |
| 12 | + cancel_button = Locator(By.CSS_SELECTOR, '[data-test-create-project-cancel]') |
| 13 | + title_input = Locator(By.CSS_SELECTOR, '._NewProject__label_fz56y2 input') |
| 14 | + select_all_link = Locator(By.XPATH, '//button[text()="Select all"]') |
| 15 | + remove_all_link = Locator(By.XPATH, '//button[text()="Remove all"]') |
| 16 | + more_arrow = Locator(By.CSS_SELECTOR, 'button[data-analytics-name="Toggle more"]') |
| 17 | + description_input = Locator(By.CLASS_NAME, 'project-desc') |
| 18 | + template_dropdown = Locator(By.CLASS_NAME, 'ember-power-select-placeholder') |
| 19 | + |
| 20 | + def institution_selected(self, institution): |
| 21 | + try: |
| 22 | + logo = self.modal.find_element_by_name(institution) |
| 23 | + return '0.25' not in logo.value_of_css_property('opacity') |
| 24 | + except Exception: |
| 25 | + raise ValueError('Institution logo for {} not present in modal'.format(institution)) |
| 26 | + |
| 27 | + |
| 28 | +class EmberProjectCreatedModal(BaseElement): |
| 29 | + |
| 30 | + go_to_project_href_link = Locator(By.CSS_SELECTOR, '.modal-dialog a', settings.LONG_TIMEOUT) |
| 31 | + keep_working_here_button = Locator(By.CSS_SELECTOR, 'button.btn-default') |
| 32 | + |
| 33 | + |
| 34 | +class EmberProjectList(BaseElement): |
| 35 | + |
| 36 | + search_input = Locator(By.CSS_SELECTOR, '._quick-search-input_1b28t4 > input') |
| 37 | + top_project_link = Locator(By.CLASS_NAME, '_DashboardItem_17nn6d') |
| 38 | + sort_title_asc_button = Locator(By.CSS_SELECTOR, '._quick-search-col_1b28t4 ._SortButton_1ifm79 [title~="ascending"]') |
| 39 | + sort_title_dsc_button = Locator(By.CSS_SELECTOR, '._quick-search-col_1b28t4 ._SortButton_1ifm79 [title~="descending"]') |
| 40 | + sort_date_asc_button = Locator(By.CSS_SELECTOR, '.col-md-3 ._quick-search-col_1b28t4 ._SortButton_1ifm79 [title~="ascending"]') |
| 41 | + sort_date_dsc_button = Locator(By.CSS_SELECTOR, '.col-md-3 ._quick-search-col_1b28t4 ._SortButton_1ifm79 [title~="descending"]') |
| 42 | + loading_dashboard_item = Locator(By.CLASS_NAME, '_loading-dashboard-item_1b28t4', settings.QUICK_TIMEOUT) |
| 43 | + |
| 44 | + # Group Locators |
| 45 | + project_list_projects = GroupLocator(By.CSS_SELECTOR, '._quick-search-table_1b28t4 a') |
| 46 | + |
| 47 | + def get_nth_project_link(self, n=0): |
| 48 | + if self.loading_dashboard_item.here_then_gone(): |
| 49 | + try: |
| 50 | + element = self.project_list_projects[n - 1] |
| 51 | + return element.get_attribute('href') |
| 52 | + except IndexError: |
| 53 | + raise ValueError('Unable to find a project at position {}'.format(n)) |
| 54 | + raise ValueError('Dashboard page is still loading.') |
| 55 | + |
| 56 | + def get_list_length(self): |
| 57 | + if self.loading_dashboard_item.here_then_gone(): |
| 58 | + return len(self.project_list_projects) |
| 59 | + raise ValueError('Dashboard page is still loading.') |
| 60 | + |
| 61 | + |
| 62 | +class CreateProjectModal(BaseElement): |
| 63 | + |
| 64 | + modal = Locator(By.ID, 'addProjectFromHome') |
| 65 | + create_project_button = Locator(By.CSS_SELECTOR, '#addProject button.btn.btn-success') |
| 66 | + cancel_button = Locator(By.CSS_SELECTOR, '#addProjectFromHome > div > div > div.modal-footer > button.btn.btn-default') |
| 67 | + title_input = Locator(By.CSS_SELECTOR, '.form-control') |
| 68 | + select_all_link = Locator(By.XPATH, '//a[text()="Select all"]') |
| 69 | + remove_all_link = Locator(By.XPATH, '//a[text()="Remove all"]') |
| 70 | + more_arrow = Locator(By.CSS_SELECTOR, '#addProjectFromHome > div > div > div.modal-body > div > div.text-muted.pointer') |
| 71 | + description_input = Locator(By.CSS_SELECTOR, '#addProjectFromHome > div > div > div.modal-body > div > div:nth-child(4) > input') |
| 72 | + template_dropdown = Locator(By.ID, 'select2-chosen-2') |
| 73 | + |
| 74 | + def institution_selected(self, institution): |
| 75 | + try: |
| 76 | + logo = self.modal.find_element(By.NAME, institution) |
| 77 | + return '0.25' not in logo.value_of_css_property('opacity') |
| 78 | + except Exception: |
| 79 | + raise ValueError('Institution logo for {} not present in modal'.format(institution)) |
| 80 | + |
| 81 | + |
| 82 | +class ProjectCreatedModal(BaseElement): |
| 83 | + |
| 84 | + go_to_project_href_link = Locator(By.XPATH, '//a[text()="Go to new project"]', settings.LONG_TIMEOUT) |
| 85 | + keep_working_here_button = Locator(By.CSS_SELECTOR, 'button[data-dismiss="modal"]', settings.TIMEOUT) |
| 86 | + |
| 87 | + |
| 88 | +class CreateCollectionModal(BaseElement): |
| 89 | + |
| 90 | + modal = Locator(By.CSS_SELECTOR, '#addColl') |
| 91 | + name_input = Locator(By.CSS_SELECTOR, '#addCollInput') |
| 92 | + add_button = Locator(By.CSS_SELECTOR, '#addColl .btn-success') |
| 93 | + cancel_button = Locator(By.CSS_SELECTOR, '#addColl .btn-default') |
| 94 | + |
| 95 | + |
| 96 | +class DeleteCollectionModal(BaseElement): |
| 97 | + |
| 98 | + modal = Locator(By.CSS_SELECTOR, '#removeColl') |
| 99 | + delete_button = Locator(By.CSS_SELECTOR, '#removeColl .btn-danger') |
| 100 | + cancel_button = Locator(By.CSS_SELECTOR, '#removeColl .btn-default') |
| 101 | + |
| 102 | + |
| 103 | +class ProjectList(BaseElement): |
| 104 | + |
| 105 | + search_input = Locator(By.ID, 'searchQuery', settings.LONG_TIMEOUT) |
| 106 | + top_project_link = Locator(By.CSS_SELECTOR, 'div.quick-search-table > div:nth-child(3) > a:nth-child(1)') |
| 107 | + sort_title_asc_button = Locator(By.CSS_SELECTOR, |
| 108 | + 'div.quick-search-table > div.row.node-col-headers.m-t-md > div.col-sm-3.col-md-6 > div > button:nth-child(1)') |
| 109 | + sort_title_dsc_button = Locator(By.CSS_SELECTOR, |
| 110 | + 'div.quick-search-table > div.row.node-col-headers.m-t-md > div.col-sm-3.col-md-6 > div > button:nth-child(2)') |
| 111 | + sort_date_asc_button = Locator(By.CSS_SELECTOR, |
| 112 | + 'div.quick-search-table > div.row.node-col-headers.m-t-md > div:nth-child(3) > div > span > button:nth-child(1)') |
| 113 | + sort_date_dsc_button = Locator(By.CSS_SELECTOR, |
| 114 | + 'div.quick-search-table > div.row.node-col-headers.m-t-md > div:nth-child(3) > div > span > button:nth-child(2)') |
| 115 | + |
| 116 | + # Group Locators |
| 117 | + project_list_projects = GroupLocator(By.CSS_SELECTOR, 'div.quick-search-table > div:nth-child(3) > a') |
| 118 | + |
| 119 | + def get_nth_project_link(self, n=0): |
| 120 | + base_selector = 'div.quick-search-table > div:nth-child(3) > a:nth-child' |
| 121 | + try: |
| 122 | + selector = '{}({})'.format(base_selector, n) |
| 123 | + element = self.driver.find_element(By.CSS_SELECTOR, selector) |
| 124 | + guid = element.get_attribute('href').strip('/') |
| 125 | + return guid |
| 126 | + except Exception: |
| 127 | + raise ValueError('Unable to find a project at position {}'.format(n)) |
| 128 | + |
| 129 | + def get_list_length(self): |
| 130 | + sleep(0.4) # Need sleep to let quicksearch do its thing |
| 131 | + return len(self.project_list_projects) |
0 commit comments