def is_displayed(self): """Return True if the portrait is loaded and in the frame.""" Utility.scroll_to(self.driver, element=self.portrait, shift=-20) card = self.find_element(*self._card_locator) return (Utility.is_image_visible(self.driver, image=self.portrait) and Utility.in_viewport( self.driver, element=card, display_marks=True))
def loaded(self): """Override the loaded property.""" try: main = self.find_element(*self._main_locator) images = self.find_elements(*self._image_locator) return (Utility.has_children(main) and Utility.is_image_visible(self.driver, image=images)) except WebDriverException: return False
def test_the_openstax_ally_logo_is_available(web_base_url, selenium): """An OpenStax Ally is identified by the Ally logo.""" # GIVEN: a user viewing the partners page home = WebHome(selenium, web_base_url).open() partners = home.web_nav.technology.view_partners() # WHEN: # THEN: the OpenStax Ally logo is displayed assert (partners.is_displayed()) assert (partners.logo.is_displayed()) assert (Utility.is_image_visible(selenium, image=partners.logo))
def test_institutional_partner_logos_are_displayed(web_base_url, selenium): """Institutional Partner logos are presented.""" # GIVEN: a user viewing the impact page home = WebHome(selenium, web_base_url).open() impact = home.information.box[Web.OUR_IMPACT].click() # WHEN: they scroll below the banner impact.view_partners() # THEN: institutional partner logos are displayed for partner in impact.partners: assert (Utility.is_image_visible(selenium, image=partner.logo))
def test_a_breakdown_of_the_student_fee_is_shown(web_base_url, selenium): """The student fee is broken down and explained.""" # GIVEN: a user viewing the Tutor marketing page home = WebHome(selenium, web_base_url).open() tutor_marketing = home.web_nav.technology.view_tutor() # WHEN: they scroll to the $10 explanation section tutor_marketing.sidebar.view_where_money_goes() # THEN: the breakdown image is displayed assert (tutor_marketing.where_money_goes.breakdown_image.is_displayed()) assert (Utility.is_image_visible( selenium, image=tutor_marketing.where_money_goes.breakdown_image))
def media_ready(self): """Return True if the current media is ready.""" from selenium.webdriver.support import expected_conditions media = self.wait.until( expected_conditions.presence_of_element_located( self._media_locator)) media_type = media.tag_name.lower() if media_type == 'img': return Utility.is_image_visible(self.driver, media) elif media_type == 'video': return self.driver.execute_script( 'return arguments[0].duration;', media) > 0 raise WebDriverException( 'Unknown media type: {0}'.format(media_type))
def loaded(self): """Return True when the four root elements are found.""" locator = (By.CSS_SELECTOR, '{hero} , {press} , {sidebar} , {news}'.format( hero=self._hero_quote_selector, press=self._press_releases_selector, sidebar=self._sidebar_selector, news=self._news_mentions_selector)) try: merged = self.find_elements(*locator) sections_found = len(merged) == 4 images_visible = Utility.is_image_visible( self.driver, locator=self._image_locator) contact_found = (self.contact.name if not isinstance(self.contact, list) else self.contact[0].name) return (super().loaded and sections_found and images_visible and (contact_found or self.is_phone)) except Exception: return False
def loaded(self): """Return True when the form is displayed.""" return (Utility.is_image_visible(driver=self.driver, locator=self._logo_locator) and self.find_element(*self._form_root_locator).is_displayed())
def loaded(self): """Return True when banner is visible.""" return (super().loaded and Utility.is_image_visible(self.driver, image=self.banner))
def loaded(self): """Override the base loader.""" return (self.find_element(*self._loader_locator) and self.find_element(*self._category_locator) and Utility.is_image_visible(self.driver, locator=self._image_locators))
def submit_interest(self, user_type, first, last, email, phone, school, books, students, additional_resources, heard_on, tech_providers=None, other_provider=None): """Fill out and submit the interest form. Args: user_type (str): the user's role Web.STUDENT, Web.INSTRUCTOR, Web.ADMINISTRATOR, Web.LIBRARIAN, Web.DESIGNER, Web.HOMESCHOOL, Web.ADJUNCT, or Web.OTHER first (str): the user's first name last (str): the user's last name email (str): the user's email address phone (str): the user's telephone number school (str): the user's school affiliation books (list): a list of book short names students (int): the number of students taught in a semester number must be greater than or equal to one additional_resources (list): a list of additional resource options Web.HOMEWORK, Web.COURSEWARE, and/or Web.TOOLS heard_on (list): a list of marketing sources Web.BY_WEB_SEARCH, Web.BY_COLLEAGUE, Web.AT_CONFERENCE, Web.BY_EMAIL, Web.BY_FACEBOOK, Web.BY_TWITTER, Web.BY_WEBINAR, Web.BY_PARTNER tech_providers (list): a list of tech partners user use [Web.TechProviders.<provider>] other_providers (str): a string of unlisted providers to be used when Web.TechProviders.OTHER is in tech_providers """ self.form.select(user_type) self.form.first_name = first self.form.last_name = last self.form.email = email self.form.phone = phone self.form.school = school self.form.next() user_errors = self.form.get_user_errors if user_errors: raise WebException(f'User errors: {user_errors}') self.wait.until(lambda _: Utility.is_image_visible( self.driver, locator=self._image_locator) and self.find_element( *self._book_selection_locator)) Utility.scroll_to(self.driver, self._book_selection_locator) self.form.select_books(books) sleep(0.5) self.form.students = students self.form.heard(heard_on) self.form.next() book_error = self.form.get_book_error if book_error: raise WebException(f'Book error - {book_error}') using_error = self.form.using_error if using_error: raise WebException(f'Using error - {using_error}') self.form.select_tech(tech_providers) if TechProviders.OTHER in tech_providers: self.form.other = other_provider self.form.submit() return go_to_(Partners(self.driver, self.base_url))
def submit_adoption(self, user_type, first, last, email, phone, school, books, tech_providers=None, other_provider=None): """Fill out and submit the adoption form. Args: user_type (str): the user's role Web.STUDENT, Web.INSTRUCTOR, Web.ADMINISTRATOR, Web.LIBRARIAN, Web.DESIGNER, Web.HOMESCHOOL, Web.ADJUNCT, or Web.OTHER first (str): the user's first name last (str): the user's last name email (str): the user's email address phone (str): the user's telephone number school (str): the user's school affiliation books (dict): a dictionaries of dictionaries for adopted books Book short name (str): the shortened book title Adoption status (str): Web.ADOPTED or Web.RECOMMENDED Students (int): number of students being taught per semester { 'AP Biology': { 'status': Web.ADOPTED, 'students': 30 }, <book-short-name>: { 'status': <status>, 'students': <students> } } tech_providers (list): a list of technology partners under use [Web.TechProviders.<provider>] other_provider (str): a string of unlisted providers to be used when Web.TechProviders.OTHER is in tech_providers """ self.form.select(user_type) sleep(1.0) self.form.first_name = first self.form.last_name = last self.form.email = email self.form.phone = phone self.form.school = school self.form.next() sleep(1.0) user_errors = self.form.get_user_errors if user_errors: raise WebException(f'User errors: {user_errors}') self.wait.until(lambda _: Utility.is_image_visible( self.driver, locator=self._image_locator) and self.find_element( *self._book_selection_locator)) Utility.scroll_to(self.driver, self._book_selection_locator, shift=-80) sleep(0.25) self.form.select_books(books) sleep(0.5) self.form.set_using(books) sleep(0.5) self.form.next() sleep(1.0) book_error = self.form.get_book_error if book_error: raise WebException(f'Book error: {book_error}') using_errors = self.form.get_using_errors if using_errors: raise WebException(f'Using error: {using_errors}') self.form.select_tech(tech_providers) if tech_providers and TechProviders.OTHER in tech_providers: self.form.other = other_provider self.form.submit() sleep(1.0) from pages.web.book import Book return go_to_(Book(self.driver, self.base_url))
def has_portrait(self): """Return True if the portrait exists.""" return Utility.is_image_visible(self.driver, image=self.portrait)
def loaded(self): """Return True if the title is set and images are visible.""" return ('OpenStax Tech Scout' in self.title and Utility.is_image_visible(self.driver, locator=self._image_locator))
def loaded(self): """Override the base loader.""" sleep(1.0) visible = Utility.is_image_visible(self.driver, locator=self._image_locators) return visible and self.find_element(*self._new_frontier_locator)