class CoursesPage(object): def __init__(self, driver): self.driver = driver self.driver_waits = DriverWaits(self.driver) def get_courses(self): courses = { 'no_of_courses': 0, 'courses': [], } course_elements = self.driver.find_elements( *CoursesPageLocators.COURSE_BLOCK) courses['no_of_courses'] = len(course_elements) for course_element in course_elements: course_title = course_element.find_element( *CoursesPageLocators.COURSE_TITLE).text course_price = course_element.find_element( *CoursesPageLocators.COURSE_PRICE).text course_id = course_element.get_attribute('data-course-id') course_details = { 'title': course_title, 'price': course_price, 'course_id': course_id, } courses['courses'].append(course_details) return courses def search_course_by_keyword(self, query_string=''): search_box = self.driver.find_element(*CoursesPageLocators.SEARCH_BOX) search_box.clear() search_box.send_keys(query_string) search_box.send_keys(Keys.RETURN) time.sleep(2) def search_and_get_courses_by_keyword(self, query_string=''): self.search_course_by_keyword(query_string=query_string) return self.get_courses() def go_to_course_details_page(self, course_id): course_elements = self.driver.find_elements( *CoursesPageLocators.COURSE_BLOCK) course_found = False for element in course_elements: if element.get_attribute('data-course-id') == str(course_id): course_found = True element.click() self.driver_waits.wait_till_element_is_visible( CourseDetailsPageLocators.MAIN_BLOCK) break assert course_found, 'No course found by id: {}'.format(str(course_id))
class CourseDetailsPage(object): def __init__(self, driver): self.driver = driver self.driver_waits = DriverWaits(self.driver) def go_for_enroll(self): self.driver.find_element( *CourseDetailsPageLocators.ENROLL_BUTTON_TOP).click() self.driver_waits.wait_till_element_is_visible( CheckoutPageLocators.MAIN_BLOCK)
class MainNavigation(object): def __init__(self, driver): self.driver = driver self.driver_waits = DriverWaits(self.driver) def go_to_all_courses_page(self): self.driver.find_element(*MainNavLocators.ALL_COURSES_LINK).click() self.driver_waits.wait_till_element_is_visible( CoursesPageLocators.COURSE_DIRECTORY) time.sleep(5) def go_to_home(self): self.driver.find_element(*MainNavLocators.BRAND_LOGO).click() self.driver_waits.wait_till_element_is_visible( HomePageLocators.COURSE_LIST_BLOCK) def logout(self): self.driver.find_element(*MainNavLocators.MY_PROFILE_ICON).click() self.driver_waits.wait_till_element_is_clickable( MainNavLocators.LOGOUT_LINK) time.sleep(1) self.driver.find_element(*MainNavLocators.LOGOUT_LINK).click() self.driver_waits.wait_till_element_is_visible( MainNavLocators.LOGIN_LINK)
class MainNavigation(object): def __init__(self, driver): self.driver = driver self.driver_waits = DriverWaits(self.driver) def logout(self): self.driver.find_element(*MainNavLocators.MY_PROFILE_ICON).click() self.driver_waits.wait_till_element_is_clickable(MainNavLocators.LOGOUT_LINK) time.sleep(1) self.driver.find_element(*MainNavLocators.LOGOUT_LINK).click() self.driver_waits.wait_till_element_is_visible(MainNavLocators.LOGIN_LINK)
class HomePage(object): def __init__(self, driver): self.driver = driver self.driver_wait = DriverWaits(self.driver) def search_by_keyword(self, query_string): # import pdb; pdb.set_trace() search_box = self.driver.find_element(*HomePageLocators.SEARCH_BOX) search_box.send_keys(query_string) search_button = self.driver.find_element( *HomePageLocators.SEARCH_BUTTON) search_button.click() self.driver_wait.wait_till_element_visible( SearchResultPageLocators.FIND_HEADER)
class LoginPage(object): def __init__(self, driver): self.driver = driver self.driver_waits = DriverWaits(self.driver) def login(self, credentials=settings.LOGIN_CREDENTIALS): self.driver.find_element(*MainNavLocators.LOGIN_LINK).click() self.driver_waits.wait_till_element_is_visible( LoginPageLocators.LOGIN_BUTTON) email_input = self.driver.find_element(*LoginPageLocators.EMAIL_INPUT) email_input.clear() email_input.send_keys(credentials['email']) password_input = self.driver.find_element( *LoginPageLocators.PASSWORD_INPUT) password_input.clear() password_input.send_keys(credentials['password']) self.driver_waits.wait_till_element_is_clickable( LoginPageLocators.LOGIN_BUTTON) self.driver.find_element(*LoginPageLocators.LOGIN_BUTTON).click() self.driver_waits.wait_till_element_is_visible( MainNavLocators.MY_PROFILE_ICON)
class CoursesPage(object): def __init__(self, driver): self.driver = driver self.driver_waits = DriverWaits(self.driver) def go_to_all_courses_page(self): self.driver.find_element(*MainNavLocators.ALL_COURSES_LINK).click() self.driver_waits.wait_till_element_is_visible( CoursesPageLocators.COURSE_DIRECTORY) def get_courses(self): courses = { 'no_of_courses': 0, 'courses': [], } course_elements = self.driver.find_elements( *CoursesPageLocators.COURSE_BLOCK) courses['no_of_courses'] = len(course_elements) for course_element in course_elements: course_title = course_element.find_element( *CoursesPageLocators.COURSE_TITLE).text course_price = course_element.find_element( *CoursesPageLocators.COURSE_PRICE).text course_details = {'title': course_title, 'price': course_price} courses['courses'].append(course_details) return courses def search_course_by_keyword(self, query_string=''): search_box = self.driver.find_element(*CoursesPageLocators.SEARCH_BOX) search_box.clear() search_box.send_keys(query_string) search_box.send_keys(Keys.RETURN) time.sleep(2)
def setUpClass(cls): cls.driver = getattr(webdriver, cls.browser)() cls.driver.maximize_window() cls.driver_waits = DriverWaits(cls.driver) cls.driver.get(cls.base_url) cls.driver_waits.wait_till_url_is_updated(settings.BASE_URL) current_url = cls.driver.current_url print(current_url) assert current_url == settings.REDIRECT_URL, "The site is not redirected to currect url. " \ "redirected to {}".format(current_url) css_selector_for_hero_button = '.hero-button' cls.driver_waits.wait_till_element_is_present( css_selector_for_hero_button)
def __init__(self, driver): self.driver = driver self.driver_wait = DriverWaits(self.driver)