2018-06-26 00:47:21 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""Page model for home page."""
|
|
|
|
|
2018-06-28 15:44:28 +03:00
|
|
|
import typing
|
2018-06-26 00:47:21 +03:00
|
|
|
|
2018-06-28 15:44:28 +03:00
|
|
|
from pypom import Page
|
2018-06-26 00:47:21 +03:00
|
|
|
from selenium.webdriver.common.by import By
|
2018-06-26 21:55:19 +03:00
|
|
|
from selenium.webdriver.support import expected_conditions as expected
|
2018-06-26 00:47:21 +03:00
|
|
|
|
2018-06-28 15:44:28 +03:00
|
|
|
from pages.queries import QueryPage
|
|
|
|
|
2018-06-28 16:08:32 +03:00
|
|
|
Locator = typing.Tuple[typing.Any, str]
|
2018-06-28 15:44:28 +03:00
|
|
|
|
2018-06-26 00:47:21 +03:00
|
|
|
|
|
|
|
class HomePage(Page):
|
|
|
|
"""Page object model for home page."""
|
|
|
|
|
2018-06-28 16:08:32 +03:00
|
|
|
_profile_username_dropdown_locator: Locator = (
|
2018-06-27 19:27:37 +03:00
|
|
|
By.CSS_SELECTOR,
|
|
|
|
".dropdown--profile__username",
|
|
|
|
)
|
2018-07-12 18:03:28 +03:00
|
|
|
_navbar_search_input_locator: Locator = (By.CLASS_NAME, "navbar__search__input")
|
|
|
|
_search_input_btn_locator: Locator = (By.CLASS_NAME, "input-group-btn .btn")
|
2018-06-27 19:27:37 +03:00
|
|
|
|
|
|
|
@property
|
2018-06-28 15:52:27 +03:00
|
|
|
def loaded(self) -> typing.Any:
|
2018-06-26 00:47:21 +03:00
|
|
|
self.wait.until(
|
|
|
|
lambda _: self.is_element_displayed(
|
2018-06-27 19:27:37 +03:00
|
|
|
*self._profile_username_dropdown_locator
|
2018-06-26 00:47:21 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
return self
|
|
|
|
|
2018-06-26 21:55:19 +03:00
|
|
|
@property
|
2018-06-28 15:44:28 +03:00
|
|
|
def title(self) -> typing.Any:
|
2018-06-26 21:55:19 +03:00
|
|
|
"""Return the page title."""
|
|
|
|
return self.wait.until(lambda s: self.selenium.title)
|
|
|
|
|
|
|
|
@property
|
2018-06-28 15:44:28 +03:00
|
|
|
def profile_dropdown(self) -> typing.Any:
|
2018-06-26 21:55:19 +03:00
|
|
|
"""Return the profile dropdown element."""
|
|
|
|
element = self.wait.until(
|
|
|
|
expected.visibility_of_element_located(
|
2018-06-27 19:27:37 +03:00
|
|
|
self._profile_username_dropdown_locator
|
2018-06-26 21:55:19 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
return element.text
|
|
|
|
|
2018-06-28 15:44:28 +03:00
|
|
|
def log_out(self) -> None:
|
2018-07-12 18:03:28 +03:00
|
|
|
element = self.selenium.find_element(*self._profile_username_dropdown_locator)
|
2018-06-26 00:47:21 +03:00
|
|
|
element.click()
|
|
|
|
logout = element.find_elements_by_tag_name("li")
|
|
|
|
logout[-1].click()
|
|
|
|
|
2018-06-28 15:44:28 +03:00
|
|
|
def search(self, term: str) -> typing.Any:
|
2018-07-12 18:03:28 +03:00
|
|
|
element = self.selenium.find_element(*self._navbar_search_input_locator)
|
2018-06-26 00:47:21 +03:00
|
|
|
element.click()
|
|
|
|
element.send_keys(term)
|
2018-06-27 19:27:37 +03:00
|
|
|
button = self.selenium.find_element(*self._search_input_btn_locator)
|
2018-06-26 00:47:21 +03:00
|
|
|
button.click()
|
|
|
|
|
|
|
|
return QueryPage(self.selenium).wait_for_page_to_load()
|