class OSFBasePage(BasePage): """ Note: All pages must have a unique identity or overwrite `verify` """ url = settings.OSF_HOME navbar = ComponentLocator(HomeNavbar) def __init__(self, driver, verify=False): super().__init__(driver, verify) def find_error_heading_element(self): try: error_head = self.driver.find_element(By.CSS_SELECTOR, 'h2#error') except NoSuchElementException: return None else: return error_head def error_handling(self): # If we've got an error message here from osf, grab it error_heading = self.find_error_heading_element() if error_heading: raise HttpError( error_heading.get_attribute('data-http-status-code')) def is_logged_in(self): return self.navbar.is_logged_in() def is_logged_out(self): return self.navbar.is_logged_out()
class ProjectPage(GuidBasePage): identity = Locator(By.ID, 'projectScope') title = Locator(By.ID, 'nodeTitleEditable', settings.LONG_TIMEOUT) title_input = Locator(By.CSS_SELECTOR, '.form-inline input') title_edit_submit_button = Locator(By.CSS_SELECTOR, '.editable-submit') title_edit_cancel_button = Locator(By.CSS_SELECTOR, '.editable-cancel') make_public_link = Locator(By.XPATH, '//a[contains(text(), "Make Public")]') make_private_link = Locator(By.XPATH, '//a[contains(text(), "Make Private")]') confirm_privacy_change_link = Locator(By.XPATH, '//a[text()="Confirm"]') cancel_privacy_change_link = Locator(By.XPATH, '//a[text()="Cancel"]') # Components file_widget = ComponentLocator(FileWidget) log_widget = ComponentLocator(LogWidget)
class DashboardPage(BaseDashboardPage): url = settings.OSF_HOME + '/dashboard/' identity = Locator(By.CSS_SELECTOR, '._institutions-panel_1b28t4', settings.LONG_TIMEOUT) create_project_button = Locator(By.CSS_SELECTOR, '[data-test-create-project-modal-button]', settings.LONG_TIMEOUT) view_meetings_button = Locator(By.XPATH, '//a[text()="View meetings"]') view_preprints_button = Locator(By.XPATH, '//a[text()="View preprints"]') first_popular_project_entry = Locator(By.CSS_SELECTOR, '._NoteworthyProject__item_ko80g1', settings.LONG_TIMEOUT) institutions_carousel_left_arrow = Locator(By.CSS_SELECTOR, '._InstitutionCarousel__control_16pdz4.carousel-control._left_16pdz4') institutions_carousel_right_arrow = Locator(By.CSS_SELECTOR, '._InstitutionCarousel__control_16pdz4.carousel-control._right_16pdz4') # Group Locators institution_carousel_logos = GroupLocator(By.CSS_SELECTOR, '.carousel-inner img') # Components navbar = ComponentLocator(EmberNavbar) create_project_modal = ComponentLocator(components.EmberCreateProjectModal) project_created_modal = ComponentLocator(components.EmberProjectCreatedModal) project_list = ComponentLocator(components.EmberProjectList)
class LegacyDashboardPage(BaseDashboardPage): waffle_override = {'ember_home_page': DashboardPage} identity = Locator(By.CSS_SELECTOR, '#osfHome > div.prereg-banner', settings.LONG_TIMEOUT) create_project_button = Locator(By.CSS_SELECTOR, 'button.btn-success:nth-child(1)', settings.LONG_TIMEOUT) view_meetings_button = Locator(By.XPATH, '//a[text()="View meetings"]') view_preprints_button = Locator(By.XPATH, '//a[text()="View preprints"]') new_and_noteworthy = Locator(By.CSS_SELECTOR, '#osfHome > div.newAndNoteworthy > div > div:nth-child(2) > div > div > div:nth-child(1) > div:nth-child(1) > div > h4', settings.LONG_TIMEOUT) first_popular_project_entry = Locator(By.CLASS_NAME, 'public-projects-item', settings.LONG_TIMEOUT) popular_projects = Locator(By.CSS_SELECTOR, '#osfHome > div.newAndNoteworthy > div > div:nth-child(2) > div > div > div:nth-child(1) > div:nth-child(2) > div > h4', settings.LONG_TIMEOUT) institutions_carousel_left_arrow = Locator(By.CSS_SELECTOR, '.left.carousel-control') institutions_carousel_right_arrow = Locator(By.CSS_SELECTOR, '.right.carousel-control') # Group Locators institution_carousel_logos = GroupLocator(By.CSS_SELECTOR, '.carousel-inner .img-circle') # Components create_project_modal = ComponentLocator(components.CreateProjectModal) project_created_modal = ComponentLocator(components.ProjectCreatedModal) project_list = ComponentLocator(components.ProjectList)
class InstitutionsLandingPage(OSFBasePage): url = settings.OSF_HOME + '/institutions/' # TODO fix insitution typo identity = Locator(By.CSS_SELECTOR, 'div[data-test-insitutions-header]', settings.VERY_LONG_TIMEOUT) search_bar = Locator(By.CSS_SELECTOR, '.ember-text-field') # Group Locators institution_list = GroupLocator(By.CSS_SELECTOR, 'span[data-test-institution-name]') navbar = ComponentLocator(InstitutionsNavbar)
class LandingPage(OSFBasePage): identity = Locator(By.ID, 'home-hero', settings.LONG_TIMEOUT) name_input = Locator(By.NAME, 'fullName') email_one_input = Locator(By.NAME, 'email1') email_two_input = Locator(By.NAME, 'email2') password_input = Locator(By.NAME, 'password') terms_of_service_checkbox = Locator(By.NAME, 'acceptedTermsOfService') sign_up_button = Locator(By.CSS_SELECTOR, '._SignUpForm_3ntsx4 .btn-success') registration_success = Locator(By.CSS_SELECTOR, '.ext-success', settings.LONG_TIMEOUT) # Components navbar = ComponentLocator(EmberNavbar)
class BasePreprintPage(OSFBasePage): """The base page from which all preprint pages inherit. """ base_url = settings.OSF_HOME + '/preprints/' url_addition = '' navbar = ComponentLocator(PreprintsNavbar) def __init__(self, driver, verify=False, provider=None): self.provider = provider if provider: self.provider_id = provider['id'] self.provider_name = provider['attributes']['name'] self.provider_domain = provider['attributes']['domain'] super().__init__(driver, verify) @property def url(self): """Set the URL based on the provider domain. """ if self.provider and self.provider_id != 'osf': if self.provider['attributes']['domain_redirect_enabled']: return urljoin(self.provider_domain, self.url_addition) else: return urljoin(self.base_url, self.provider_id) + '/' + self.url_addition return self.base_url + self.url_addition def verify(self): """Return true if you are on the expected page. Checks both the general page identity and the branding. """ if self.provider and self.provider_id != 'osf': return super().verify( ) and self.provider_name in self.navbar.title.text return super().verify()
class BaseQuickfilesPage(OSFBasePage): navbar = ComponentLocator(EmberNavbar)
class BaseMeetingsPage(OSFBasePage): navbar = ComponentLocator(MeetingsNavbar)
class BaseRegistriesPage(OSFBasePage): # Components navbar = ComponentLocator(RegistriesNavbar)