"""The interest form page."""
from time import sleep
from selenium.webdriver.common.by import By
from pages.web.adoption import ERROR, Adoption, AdoptionConfirmation
from utils.utilities import Utility, go_to_
from utils.web import TechProviders, WebException
[docs]class Interest(Adoption):
"""The book interest form."""
URL_TEMPLATE = '/interest'
_adoption_form_link_locator = (By.CSS_SELECTOR, '[href$=adoption]')
[docs] def go_to_adoption(self):
"""Switch to the adoption form."""
return self.go_to_interest(link=self._adoption_form_link_locator)
[docs] 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_(InterestConfirmation(self.driver, self.base_url))
[docs]class InterestConfirmation(AdoptionConfirmation):
"""The interest confirmation page."""
URL_TEMPLATE = '/interest-confirmation'
_confirmation_locator = (By.CSS_SELECTOR, '.confirmation-page')
_back_to_books_locator = (By.CSS_SELECTOR, '[href$=subjects]')
_report_another_locator = _back_to_books_locator
_response_text_locator = (By.CSS_SELECTOR, '.confirmation-page p')
@property
def response(self):
"""Return the response text."""
return self.find_element(*self._response_text_locator).text.strip()
@property
def subjects(self):
"""Return the 'Back to the books' link."""
return self.find_element(*self._back_to_books_locator)
[docs] def back_to_books(self):
"""Return to the subjects page."""
Utility.click_option(self.driver, element=self.subjects)
from pages.web.subjects import Subjects
return go_to_(Subjects(self.driver, self.base_url))