예제 #1
0
            def click(self):
                """Go to the banner link destination.

                Return a 'Destination' so the function will fail if
                a new banner link is added.
                """
                destination = self.destination
                parent = self.page
                while not isinstance(parent, Page):
                    parent = parent.page
                base_url = parent.base_url
                if destination.endswith(Web.SUBJECTS):
                    from pages.web.subjects import Subjects as Destination
                elif destination.endswith(Web.ABOUT):
                    from pages.web.about import AboutUs as Destination
                elif destination.endswith(Web.SE_APP):
                    from pages.web.se_app import StudyEdge as Destination
                elif destination.endswith(Web.GLOBAL_REACH):
                    from pages.web.reach import GlobalReach as Destination
                elif destination.endswith(Web.ONLINE_RESOURCES):
                    from pages.web.online_resources \
                        import OnlineResources as Destination
                else:
                    raise WebException(
                        'Unknown destination: {0}'
                        .format(self.destination.split('/')[-1]))
                Utility.click_option(self.driver, element=self.root)
                return go_to_(Destination(self.driver, base_url=base_url))
예제 #2
0
 def is_displayed(self):
     """Return True if the errata table is displayed."""
     if self.driver.get_window_size().get('width') > Web.PHONE:
         table = self.find_elements(*self._table_locator)
     else:
         table = self.find_elements(*self._mobile_errata_locator)
     if self.loaded and not table:
         raise WebException('Errata table is empty')
     return self.loaded and table[0].is_displayed()
예제 #3
0
 def select(self, user_type, retry=0):
     """Select a user type from the user drop down menu."""
     sleep(0.33)
     for step in range(10):
         user = self.find_element(*self._user_select_locator)
         Utility.click_option(self.driver, element=user)
         sleep(0.5)
         is_open = 'open' in (self.find_element(
             *self._user_select_locator).get_attribute('class'))
         if is_open:
             break
         if step == 9:
             raise WebException('User select menu not open')
     for step in range(10):
         user = self.find_element(
             By.CSS_SELECTOR,
             self._user_role_selector.format(
                 user=Web.USER_CONVERSION[user_type]))
         Utility.click_option(self.driver, element=user)
         sleep(0.5)
         is_closed = 'open' not in (self.find_element(
             By.CSS_SELECTOR,
             self._user_role_selector.format(
                 user=Web.USER_CONVERSION[user_type])).get_attribute(
                     'class'))
         if is_closed:
             break
         if step == 9:
             raise WebException('User select menu still open')
     sleep(0.5)
     selected = (self.find_element(
         *self._user_selected_role_locator).get_attribute('textContent')
                 )
     if selected == Web.NO_USER_TYPE and retry <= 2:
         self.select(user_type, retry=retry + 1)
     elif retry == 3:
         raise WebException('No user type selected after 3 tries')
     elif selected != user_type:
         raise WebException(
             f'"{user_type}" not selected; found "{selected}"')
     return self
예제 #4
0
 def _selection_helper(self, selected, options_locator, _type):
     """Click checkboxes for selected options."""
     if selected:
         group = {}
         for option in self.find_elements(*options_locator):
             group[option.get_attribute('value')] = option
         if not group:
             raise WebException(f'No {_type} options found')
         for option in group:
             if option in selected:
                 group.get(option).click()
     return self.page
예제 #5
0
    def answer(self) -> WebElement:
        """Return the free response answer box.

        :return: the free response answer box, if found
        :rtype: :py:class:`~selenium.webdriver.remote.webelement.WebElement`
        :raises: :py:class:`~utils.web.WebException` if the survey answer is
            multiple choice

        """
        if self.is_multiple_choice:
            raise WebException('Free response box not available for '
                               'multiple choice questions')
        return self.find_element(*self._answer_response_text_box_locator)
예제 #6
0
    def subjects_page(self) -> Subjects:
        """Click the 'Subjects page' link in the larger screen description.

        :return: the book subjects page
        :rtype: :py:class:`~pages.web.subjects.Subjects`
        :raises :py:class:`~utils.web.WebException`: if the link is unavailable
            because the user is viewing the page on a phone resolution

        """
        if self.is_phone:
            raise WebException('link not available when viewing on a phone')
        link = self.find_element(*self._subjects_page_link_locator)
        Utility.click_option(self.driver, element=link)
        return go_to_(Subjects(self.driver, base_url=self.base_url))
예제 #7
0
    def answers(self, answer: str) -> None:
        """Select the answer choice.

        :param str answer: the user's multiple choice answer
        :return: None
        :raises: :py:class:`~utils.web.WebException` if the answer is not
            available for the survey question

        """
        if self.is_multiple_choice:
            for option in self.answers:
                if option.answer.lower() == answer.lower():
                    option.select()
                    return
            raise WebException(f'"{answer}" not available for {self.question}')
예제 #8
0
 def _selection_helper(self, link, tab='book-details'):
     """Select the book reference link."""
     if not self.book_selected:
         raise WebException('No book selected')
     book = self.find_element(*link)
     book_title = (
         book.get_attribute('href').split('/')[-1].split('?')[0])
     Utility.switch_to(self.driver, element=book)
     self.wait.until(lambda _: (sleep(4) or (
         self.find_elements(*self._details_tab_locator) or self.
         find_elements(*self._instructor_resources_tab_locator) or self.
         find_elements(*self._student_resources_tab_locator) or self.
         find_elements(*self._partner_resources_tab_locator))))
     return go_to_(
         Book(self.driver, self.page.base_url, book_name=book_title))
예제 #9
0
    def answers(self) -> List[Survey.Answer]:
        """Access the survey answer options.

        :return: the list of possible answers
        :rtype: list(:py:class:`~regions.web.footer.Survey.Answer`)
        :raises: :py:class:`~utils.web.WebException` if the survey answer is
            a free response

        """
        if self.is_free_response:
            raise WebException('Multiple choice answers not available for '
                               'free response questions')
        return [
            self.Answer(self, option)
            for option in self.find_elements(*self._answer_option_locator)
        ]
예제 #10
0
 def select_random_book(self, _from=Library.OPENSTAX, filter_current=False):
     """Return a random book from the active list."""
     using = {
         Library.ALL_BOOKS: self._active_books,
         Library.AP: self.ap_books,
         Library.AVAILABLE: self.available_books,
         Library.BOOKSHARE: self.bookshare_books,
         Library.BUSINESS: self.business_books,
         Library.COMP_COPY: self.comp_copy,
         Library.CURRENT: self.current_books,
         Library.HAS_I_LOCK: self.locked_instructor,
         Library.HAS_I_UNLOCK: self.unlocked_instructor,
         Library.HAS_S_LOCK: self.locked_student,
         Library.HAS_S_UNLOCK: self.unlocked_student,
         Library.HIGH_SCHOOL: self.high_school,
         Library.HUMANITIES: self.humanities_books,
         Library.ITUNES: self.itunes_books,
         Library.KINDLE: self.kindle_books,
         Library.MATH: self.math_books,
         Library.OPENSTAX: self.openstax_books,
         Library.POLISH: self.polish_books,
         Library.PRINT_COPY: self.print_books,
         Library.SCIENCE: self.science_books,
         Library.SOCIAL: self.social_sciences_books,
         Library.SUPERSEDED: self.old_book_editions,
     }.get(_from)
     if filter_current:
         using = list(
             filter(lambda book: book.title not in Library.OLD_EDITIONS,
                    using))
     total = len(using)
     if total <= 0:
         raise WebException('No books are available for selection')
     book = Utility.random(0, total - 1)
     selected = using[book]
     print('Selected book: {0}'.format(selected.title))
     destination = selected.url_append
     selected.select()
     sleep(1.0)
     from pages.web.book import Book as Details
     return go_to_(Details(self.driver, book_name=destination))
예제 #11
0
    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))
예제 #12
0
    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))